Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -132,10 +132,20 @@ vibe_crew = Crew(
|
|
| 132 |
def run_crew(prompt):
|
| 133 |
try:
|
| 134 |
if llm is None:
|
| 135 |
-
return
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 136 |
|
| 137 |
if not prompt or prompt.strip() == "":
|
| 138 |
-
return
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 139 |
|
| 140 |
# Clean up previous output
|
| 141 |
if os.path.exists("outputs/index.html"):
|
|
@@ -151,85 +161,139 @@ def run_crew(prompt):
|
|
| 151 |
html_content = file.read()
|
| 152 |
|
| 153 |
if html_content.strip():
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 154 |
return (
|
| 155 |
-
|
| 156 |
-
|
| 157 |
-
"outputs/index.html"
|
|
|
|
| 158 |
)
|
| 159 |
else:
|
| 160 |
return (
|
| 161 |
-
|
| 162 |
-
|
| 163 |
-
|
|
|
|
| 164 |
)
|
| 165 |
else:
|
| 166 |
return (
|
| 167 |
-
|
| 168 |
-
|
| 169 |
-
|
|
|
|
| 170 |
)
|
| 171 |
|
| 172 |
except Exception as e:
|
| 173 |
error_trace = traceback.format_exc()
|
| 174 |
-
error_message = f"β **Error occurred during execution:**\n\n
|
| 175 |
print(error_trace) # Also print to console
|
| 176 |
-
return
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 177 |
|
| 178 |
# --- 7. CREATE THE GRADIO INTERFACE WITH CUSTOM LAYOUT ---
|
| 179 |
-
with gr.Blocks(theme=gr.themes.Soft()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 180 |
gr.Markdown(
|
| 181 |
"""
|
| 182 |
# π¨ Vibe Coder AI
|
| 183 |
-
|
|
|
|
| 184 |
"""
|
| 185 |
)
|
| 186 |
|
| 187 |
with gr.Row():
|
| 188 |
-
|
| 189 |
-
|
| 190 |
-
|
| 191 |
-
|
| 192 |
-
|
| 193 |
-
|
| 194 |
-
|
| 195 |
-
generate_btn = gr.Button("π Generate Website", variant="primary", size="lg")
|
| 196 |
-
|
| 197 |
-
gr.Examples(
|
| 198 |
-
examples=[
|
| 199 |
-
["A personal portfolio for a photographer. The vibe should be minimalist, modern, and clean."],
|
| 200 |
-
["A landing page for a new tech startup focused on AI. Vibe: futuristic, sleek, professional."],
|
| 201 |
-
["A website for a local bakery. Vibe: warm, friendly, and homemade."]
|
| 202 |
-
],
|
| 203 |
-
inputs=prompt_input
|
| 204 |
-
)
|
| 205 |
|
| 206 |
with gr.Row():
|
| 207 |
-
|
| 208 |
|
| 209 |
with gr.Row():
|
| 210 |
-
|
| 211 |
-
|
| 212 |
-
|
| 213 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 214 |
|
| 215 |
with gr.Row():
|
| 216 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 217 |
|
| 218 |
-
|
| 219 |
-
|
| 220 |
-
|
| 221 |
-
|
| 222 |
-
|
| 223 |
-
|
| 224 |
-
|
| 225 |
-
|
| 226 |
-
|
| 227 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 228 |
|
| 229 |
generate_btn.click(
|
| 230 |
-
fn=
|
| 231 |
inputs=[prompt_input],
|
| 232 |
-
outputs=[
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 233 |
)
|
| 234 |
|
| 235 |
if __name__ == "__main__":
|
|
|
|
| 132 |
def run_crew(prompt):
|
| 133 |
try:
|
| 134 |
if llm is None:
|
| 135 |
+
return (
|
| 136 |
+
"β **Error:** Gemini LLM not initialized. Please check your GOOGLE_API_KEY in environment variables.",
|
| 137 |
+
None,
|
| 138 |
+
gr.update(visible=False),
|
| 139 |
+
gr.update(visible=False)
|
| 140 |
+
)
|
| 141 |
|
| 142 |
if not prompt or prompt.strip() == "":
|
| 143 |
+
return (
|
| 144 |
+
"β **Error:** Please enter a prompt describing your desired website vibe.",
|
| 145 |
+
None,
|
| 146 |
+
gr.update(visible=False),
|
| 147 |
+
gr.update(visible=False)
|
| 148 |
+
)
|
| 149 |
|
| 150 |
# Clean up previous output
|
| 151 |
if os.path.exists("outputs/index.html"):
|
|
|
|
| 161 |
html_content = file.read()
|
| 162 |
|
| 163 |
if html_content.strip():
|
| 164 |
+
# Create preview
|
| 165 |
+
preview_html = f'<iframe srcdoc="{html_content.replace(chr(34), """)}" width="100%" height="800px" style="border: 2px solid #e0e0e0; border-radius: 8px;"></iframe>'
|
| 166 |
+
|
| 167 |
+
success_message = "β
**Success!** Your website has been generated and is ready to download."
|
| 168 |
+
|
| 169 |
return (
|
| 170 |
+
success_message,
|
| 171 |
+
preview_html,
|
| 172 |
+
gr.update(value="outputs/index.html", visible=True),
|
| 173 |
+
gr.update(visible=True)
|
| 174 |
)
|
| 175 |
else:
|
| 176 |
return (
|
| 177 |
+
"β οΈ **Warning:** File created but is empty. Please try again.",
|
| 178 |
+
None,
|
| 179 |
+
gr.update(visible=False),
|
| 180 |
+
gr.update(visible=False)
|
| 181 |
)
|
| 182 |
else:
|
| 183 |
return (
|
| 184 |
+
"β **Error:** Output file not found. The developer agent might have failed. Please try again.",
|
| 185 |
+
None,
|
| 186 |
+
gr.update(visible=False),
|
| 187 |
+
gr.update(visible=False)
|
| 188 |
)
|
| 189 |
|
| 190 |
except Exception as e:
|
| 191 |
error_trace = traceback.format_exc()
|
| 192 |
+
error_message = f"β **Error occurred during execution:**\n\n```python\n{str(e)}\n```\n\nPlease try again or check your API keys."
|
| 193 |
print(error_trace) # Also print to console
|
| 194 |
+
return (
|
| 195 |
+
error_message,
|
| 196 |
+
None,
|
| 197 |
+
gr.update(visible=False),
|
| 198 |
+
gr.update(visible=False)
|
| 199 |
+
)
|
| 200 |
|
| 201 |
# --- 7. CREATE THE GRADIO INTERFACE WITH CUSTOM LAYOUT ---
|
| 202 |
+
with gr.Blocks(theme=gr.themes.Soft(), css="""
|
| 203 |
+
.container { max-width: 1400px; margin: auto; }
|
| 204 |
+
.status-box { padding: 20px; border-radius: 8px; margin: 10px 0; }
|
| 205 |
+
.download-section { text-align: center; padding: 20px; }
|
| 206 |
+
""") as iface:
|
| 207 |
+
|
| 208 |
gr.Markdown(
|
| 209 |
"""
|
| 210 |
# π¨ Vibe Coder AI
|
| 211 |
+
### Create beautiful websites with AI - Just describe your vision!
|
| 212 |
+
Enter the 'vibe' for your website, and our multi-agent team will design, write, and code a complete webpage for you.
|
| 213 |
"""
|
| 214 |
)
|
| 215 |
|
| 216 |
with gr.Row():
|
| 217 |
+
prompt_input = gr.Textbox(
|
| 218 |
+
lines=4,
|
| 219 |
+
placeholder="Example: A website for my new coffee shop in Brooklyn. The vibe should be cozy, rustic, and artisanal.",
|
| 220 |
+
label="βοΈ Describe Your Website Vibe",
|
| 221 |
+
elem_classes="container"
|
| 222 |
+
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 223 |
|
| 224 |
with gr.Row():
|
| 225 |
+
generate_btn = gr.Button("π Generate Website", variant="primary", size="lg", scale=1)
|
| 226 |
|
| 227 |
with gr.Row():
|
| 228 |
+
gr.Examples(
|
| 229 |
+
examples=[
|
| 230 |
+
["A personal portfolio for a photographer. The vibe should be minimalist, modern, and clean."],
|
| 231 |
+
["A landing page for a new tech startup focused on AI. Vibe: futuristic, sleek, professional."],
|
| 232 |
+
["A website for a local bakery. Vibe: warm, friendly, and homemade."],
|
| 233 |
+
["A fitness coach website. Vibe: energetic, motivating, and bold."]
|
| 234 |
+
],
|
| 235 |
+
inputs=prompt_input,
|
| 236 |
+
label="π‘ Try these examples"
|
| 237 |
+
)
|
| 238 |
|
| 239 |
with gr.Row():
|
| 240 |
+
status_output = gr.Markdown(
|
| 241 |
+
value="",
|
| 242 |
+
label="Status",
|
| 243 |
+
elem_classes="status-box"
|
| 244 |
+
)
|
| 245 |
|
| 246 |
+
with gr.Row():
|
| 247 |
+
preview_output = gr.HTML(
|
| 248 |
+
label="π₯οΈ Live Preview",
|
| 249 |
+
visible=True
|
| 250 |
+
)
|
| 251 |
+
|
| 252 |
+
with gr.Row():
|
| 253 |
+
with gr.Column(scale=1):
|
| 254 |
+
download_btn = gr.File(
|
| 255 |
+
label="π₯ Download Website (HTML)",
|
| 256 |
+
visible=False,
|
| 257 |
+
elem_classes="download-section"
|
| 258 |
+
)
|
| 259 |
+
with gr.Column(scale=1):
|
| 260 |
+
view_code_btn = gr.Button(
|
| 261 |
+
"ποΈ View Source Code",
|
| 262 |
+
visible=False,
|
| 263 |
+
variant="secondary"
|
| 264 |
+
)
|
| 265 |
+
|
| 266 |
+
# Hidden code display (only shown when user clicks "View Source Code")
|
| 267 |
+
with gr.Row(visible=False) as code_row:
|
| 268 |
+
code_output = gr.Code(
|
| 269 |
+
label="π Generated HTML Source Code",
|
| 270 |
+
language="html",
|
| 271 |
+
lines=15,
|
| 272 |
+
elem_classes="container"
|
| 273 |
+
)
|
| 274 |
+
|
| 275 |
+
def toggle_code_view():
|
| 276 |
+
return gr.update(visible=True)
|
| 277 |
+
|
| 278 |
+
def generate_website(prompt):
|
| 279 |
+
status, preview, download, view_btn = run_crew(prompt)
|
| 280 |
+
return (
|
| 281 |
+
status,
|
| 282 |
+
preview,
|
| 283 |
+
download,
|
| 284 |
+
view_btn
|
| 285 |
+
)
|
| 286 |
|
| 287 |
generate_btn.click(
|
| 288 |
+
fn=generate_website,
|
| 289 |
inputs=[prompt_input],
|
| 290 |
+
outputs=[status_output, preview_output, download_btn, view_code_btn]
|
| 291 |
+
)
|
| 292 |
+
|
| 293 |
+
view_code_btn.click(
|
| 294 |
+
fn=lambda: (gr.update(visible=True), open("outputs/index.html", "r", encoding="utf-8").read() if os.path.exists("outputs/index.html") else ""),
|
| 295 |
+
inputs=None,
|
| 296 |
+
outputs=[code_row, code_output]
|
| 297 |
)
|
| 298 |
|
| 299 |
if __name__ == "__main__":
|