Update app.py
Browse files
app.py
CHANGED
@@ -1,10 +1,9 @@
|
|
1 |
-
# app.py
|
2 |
import gradio as gr
|
3 |
import json
|
4 |
import os
|
5 |
import random
|
6 |
import string
|
7 |
-
from html_generator import generate_website_html
|
8 |
|
9 |
# CSS for styling the interface
|
10 |
css = """
|
@@ -71,17 +70,26 @@ example_prompts = [
|
|
71 |
# Function to handle website generation
|
72 |
def create_website(prompt):
|
73 |
site_id = generate_site_id()
|
74 |
-
|
75 |
try:
|
76 |
# Generate HTML content based on the prompt
|
77 |
-
|
78 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
79 |
# Save the HTML content to a file
|
80 |
os.makedirs('websites', exist_ok=True)
|
81 |
file_path = f"websites/{site_id}.html"
|
82 |
with open(file_path, "w") as f:
|
83 |
f.write(html_content)
|
84 |
-
|
85 |
# In a real Hugging Face Space, you might use a different mechanism to serve the file
|
86 |
# For demo purposes, we'll return the HTML directly
|
87 |
preview_html = f"""
|
@@ -93,9 +101,9 @@ def create_website(prompt):
|
|
93 |
<iframe srcdoc="{html_content.replace('"', '"')}" width="100%" height="600px"></iframe>
|
94 |
</div>
|
95 |
"""
|
96 |
-
|
97 |
return preview_html, html_content
|
98 |
-
|
99 |
except Exception as e:
|
100 |
return f"Error generating website: {str(e)}", ""
|
101 |
|
@@ -108,38 +116,38 @@ with gr.Blocks(css=css) as demo:
|
|
108 |
<p>Generate a complete website from a simple prompt. Describe what you want, and we'll create it.</p>
|
109 |
</div>
|
110 |
""")
|
111 |
-
|
112 |
with gr.Row():
|
113 |
prompt_input = gr.Textbox(
|
114 |
placeholder="Describe the website you want to create...",
|
115 |
label="Your Website Prompt",
|
116 |
elem_classes="prompt-box"
|
117 |
)
|
118 |
-
|
119 |
with gr.Row():
|
120 |
generate_btn = gr.Button("Generate Website", elem_classes="generate-btn")
|
121 |
-
|
122 |
with gr.Row():
|
123 |
gr.HTML("<p>Need inspiration? Try one of these examples:</p>")
|
124 |
-
|
125 |
with gr.Row():
|
126 |
example_buttons = [gr.Button(f"Example {i+1}", elem_classes="example-btn") for i in range(5)]
|
127 |
-
|
128 |
with gr.Accordion("Advanced Options", open=False):
|
129 |
gr.Checkbox(label="Include responsive design", value=True)
|
130 |
gr.Checkbox(label="Generate CSS animations", value=False)
|
131 |
gr.Dropdown(["Light", "Dark", "Colorful"], label="Color Theme", value="Light")
|
132 |
-
|
133 |
output_preview = gr.HTML(elem_classes="output-container")
|
134 |
output_code = gr.Code(language="html", label="HTML Code", visible=False)
|
135 |
-
|
136 |
# Set up button actions
|
137 |
generate_btn.click(create_website, inputs=[prompt_input], outputs=[output_preview, output_code])
|
138 |
-
|
139 |
# Set up example button actions
|
140 |
for i, btn in enumerate(example_buttons):
|
141 |
btn.click(lambda _, i=i: example_prompts[i], outputs=prompt_input)
|
142 |
|
143 |
# Launch the app
|
144 |
if __name__ == "__main__":
|
145 |
-
demo.launch(share=True)
|
|
|
|
|
1 |
import gradio as gr
|
2 |
import json
|
3 |
import os
|
4 |
import random
|
5 |
import string
|
6 |
+
from html_generator import generate_website_html, generate_navbar, generate_hero_section, generate_features_section, generate_pricing_section, generate_testimonials_section, generate_contact_section
|
7 |
|
8 |
# CSS for styling the interface
|
9 |
css = """
|
|
|
70 |
# Function to handle website generation
|
71 |
def create_website(prompt):
|
72 |
site_id = generate_site_id()
|
73 |
+
|
74 |
try:
|
75 |
# Generate HTML content based on the prompt
|
76 |
+
title = "Generated Website"
|
77 |
+
sections = [
|
78 |
+
generate_navbar(title),
|
79 |
+
generate_hero_section("Welcome to Your Website", "This is a demo website generated from your prompt."),
|
80 |
+
generate_features_section(),
|
81 |
+
generate_pricing_section(),
|
82 |
+
generate_testimonials_section(),
|
83 |
+
generate_contact_section()
|
84 |
+
]
|
85 |
+
html_content = generate_website_html(title, sections)
|
86 |
+
|
87 |
# Save the HTML content to a file
|
88 |
os.makedirs('websites', exist_ok=True)
|
89 |
file_path = f"websites/{site_id}.html"
|
90 |
with open(file_path, "w") as f:
|
91 |
f.write(html_content)
|
92 |
+
|
93 |
# In a real Hugging Face Space, you might use a different mechanism to serve the file
|
94 |
# For demo purposes, we'll return the HTML directly
|
95 |
preview_html = f"""
|
|
|
101 |
<iframe srcdoc="{html_content.replace('"', '"')}" width="100%" height="600px"></iframe>
|
102 |
</div>
|
103 |
"""
|
104 |
+
|
105 |
return preview_html, html_content
|
106 |
+
|
107 |
except Exception as e:
|
108 |
return f"Error generating website: {str(e)}", ""
|
109 |
|
|
|
116 |
<p>Generate a complete website from a simple prompt. Describe what you want, and we'll create it.</p>
|
117 |
</div>
|
118 |
""")
|
119 |
+
|
120 |
with gr.Row():
|
121 |
prompt_input = gr.Textbox(
|
122 |
placeholder="Describe the website you want to create...",
|
123 |
label="Your Website Prompt",
|
124 |
elem_classes="prompt-box"
|
125 |
)
|
126 |
+
|
127 |
with gr.Row():
|
128 |
generate_btn = gr.Button("Generate Website", elem_classes="generate-btn")
|
129 |
+
|
130 |
with gr.Row():
|
131 |
gr.HTML("<p>Need inspiration? Try one of these examples:</p>")
|
132 |
+
|
133 |
with gr.Row():
|
134 |
example_buttons = [gr.Button(f"Example {i+1}", elem_classes="example-btn") for i in range(5)]
|
135 |
+
|
136 |
with gr.Accordion("Advanced Options", open=False):
|
137 |
gr.Checkbox(label="Include responsive design", value=True)
|
138 |
gr.Checkbox(label="Generate CSS animations", value=False)
|
139 |
gr.Dropdown(["Light", "Dark", "Colorful"], label="Color Theme", value="Light")
|
140 |
+
|
141 |
output_preview = gr.HTML(elem_classes="output-container")
|
142 |
output_code = gr.Code(language="html", label="HTML Code", visible=False)
|
143 |
+
|
144 |
# Set up button actions
|
145 |
generate_btn.click(create_website, inputs=[prompt_input], outputs=[output_preview, output_code])
|
146 |
+
|
147 |
# Set up example button actions
|
148 |
for i, btn in enumerate(example_buttons):
|
149 |
btn.click(lambda _, i=i: example_prompts[i], outputs=prompt_input)
|
150 |
|
151 |
# Launch the app
|
152 |
if __name__ == "__main__":
|
153 |
+
demo.launch(share=True)
|