Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,33 +1,22 @@
|
|
| 1 |
-
from transformers import pipeline
|
| 2 |
import gradio as gr
|
|
|
|
| 3 |
|
| 4 |
-
# Load
|
| 5 |
-
generator = pipeline("
|
| 6 |
-
|
| 7 |
-
# Function to generate website code from user prompt
|
| 8 |
-
def generate_website_code(prompt):
|
| 9 |
-
full_prompt = f"""You are a senior web developer. Based on the following instructions, generate a full HTML5 website including CSS and JavaScript inside <style> and <script> tags.
|
| 10 |
-
|
| 11 |
-
Instructions:
|
| 12 |
-
{prompt}
|
| 13 |
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
|
|
|
| 17 |
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
if html_start != -1:
|
| 21 |
-
return output[html_start:]
|
| 22 |
-
return output
|
| 23 |
-
|
| 24 |
-
# Gradio UI
|
| 25 |
-
iface = gr.Interface(
|
| 26 |
-
fn=generate_website_code,
|
| 27 |
-
inputs=gr.Textbox(lines=8, label="Describe your website (Prompt)"),
|
| 28 |
-
outputs=gr.Code(label="Generated HTML Website Code"),
|
| 29 |
-
title="AI Website Generator",
|
| 30 |
-
description="Enter a prompt describing your website. Example: 'Create a modern cafe website using beige and brown colors. The brand is BrewNest. Include food items, transitions, and animations.'",
|
| 31 |
-
)
|
| 32 |
|
| 33 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
+
from transformers import pipeline
|
| 3 |
|
| 4 |
+
# Load the text-to-text generation model
|
| 5 |
+
generator = pipeline("text2text-generation", model="google/flan-t5-small")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 6 |
|
| 7 |
+
# Define the function to generate website code
|
| 8 |
+
def generate_website(prompt):
|
| 9 |
+
# Instruction prompt to ensure web-style code output
|
| 10 |
+
full_prompt = f"Generate a modern HTML, CSS, and JavaScript website. {prompt}"
|
| 11 |
|
| 12 |
+
result = generator(full_prompt, max_length=1024, do_sample=True)[0]['generated_text']
|
| 13 |
+
return result
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 14 |
|
| 15 |
+
# Build a simple Gradio UI
|
| 16 |
+
gr.Interface(
|
| 17 |
+
fn=generate_website,
|
| 18 |
+
inputs=gr.Textbox(label="Describe the website you want", placeholder="e.g. A modern cafe website using beige and brown colors..."),
|
| 19 |
+
outputs=gr.Textbox(label="Generated Website Code"),
|
| 20 |
+
title="AI Website Code Generator",
|
| 21 |
+
description="Enter a prompt to generate a full website (HTML/CSS/JS)."
|
| 22 |
+
).launch()
|