Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -7,28 +7,6 @@ from utils.langgraph_pipeline import run_pipeline_and_save
|
|
| 7 |
TEMP_DIR = "generated_output"
|
| 8 |
os.makedirs(TEMP_DIR, exist_ok=True)
|
| 9 |
|
| 10 |
-
# β
Tailwind-based HTML wrapper
|
| 11 |
-
def wrap_with_template(body_content: str) -> str:
|
| 12 |
-
return f"""<!DOCTYPE html>
|
| 13 |
-
<html lang="en">
|
| 14 |
-
<head>
|
| 15 |
-
<meta charset="UTF-8" />
|
| 16 |
-
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
| 17 |
-
<title>Generated UI</title>
|
| 18 |
-
<script src="https://cdn.tailwindcss.com"></script>
|
| 19 |
-
<link href="https://fonts.googleapis.com/css2?family=Inter:wght@400;700&display=swap" rel="stylesheet">
|
| 20 |
-
<style>
|
| 21 |
-
body {{
|
| 22 |
-
font-family: 'Inter', sans-serif;
|
| 23 |
-
}}
|
| 24 |
-
</style>
|
| 25 |
-
</head>
|
| 26 |
-
<body class="bg-gray-50 text-gray-800">
|
| 27 |
-
{body_content}
|
| 28 |
-
</body>
|
| 29 |
-
</html>"""
|
| 30 |
-
|
| 31 |
-
# β
Save output files
|
| 32 |
def save_files(html: str, log: str):
|
| 33 |
html_path = os.path.join(TEMP_DIR, "ui.html")
|
| 34 |
log_path = os.path.join(TEMP_DIR, "agent_log.txt")
|
|
@@ -46,35 +24,24 @@ def save_files(html: str, log: str):
|
|
| 46 |
|
| 47 |
return html_path, log_path, zip_path
|
| 48 |
|
| 49 |
-
# β
Main pipeline trigger
|
| 50 |
def process(user_input):
|
| 51 |
messages = [HumanMessage(content=user_input)]
|
| 52 |
final_state = run_pipeline_and_save(messages)
|
| 53 |
|
| 54 |
-
|
| 55 |
-
raw_html = final_state["html_output"]
|
| 56 |
-
styled_html = wrap_with_template(raw_html)
|
| 57 |
-
|
| 58 |
-
# Agent dialogue
|
| 59 |
log = "\n\n".join([f"{msg.type.upper()}: {msg.content}" for msg in final_state["messages"]])
|
| 60 |
|
| 61 |
-
|
| 62 |
-
html_file, log_file, zip_file = save_files(styled_html, log)
|
| 63 |
|
| 64 |
-
#
|
| 65 |
-
escaped_html =
|
| 66 |
preview = f"<iframe srcdoc='{escaped_html}' width='100%' height='600px' style='border:1px solid #ccc;'></iframe>"
|
| 67 |
|
| 68 |
-
return preview,
|
| 69 |
|
| 70 |
-
# β
Gradio UI
|
| 71 |
with gr.Blocks() as demo:
|
| 72 |
gr.Markdown("# π€ Multi-Agent UI Generator")
|
| 73 |
-
user_prompt = gr.Textbox(
|
| 74 |
-
label="Describe your UI",
|
| 75 |
-
lines=4,
|
| 76 |
-
value="A yoga retreat homepage with a hero section, schedule, and testimonials. Make it beautiful and modern."
|
| 77 |
-
)
|
| 78 |
run_btn = gr.Button("Run Agents")
|
| 79 |
|
| 80 |
gr.Markdown("### π Website Preview")
|
|
@@ -98,4 +65,4 @@ with gr.Blocks() as demo:
|
|
| 98 |
)
|
| 99 |
|
| 100 |
if __name__ == "__main__":
|
| 101 |
-
demo.launch()
|
|
|
|
| 7 |
TEMP_DIR = "generated_output"
|
| 8 |
os.makedirs(TEMP_DIR, exist_ok=True)
|
| 9 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 10 |
def save_files(html: str, log: str):
|
| 11 |
html_path = os.path.join(TEMP_DIR, "ui.html")
|
| 12 |
log_path = os.path.join(TEMP_DIR, "agent_log.txt")
|
|
|
|
| 24 |
|
| 25 |
return html_path, log_path, zip_path
|
| 26 |
|
|
|
|
| 27 |
def process(user_input):
|
| 28 |
messages = [HumanMessage(content=user_input)]
|
| 29 |
final_state = run_pipeline_and_save(messages)
|
| 30 |
|
| 31 |
+
html = final_state["html_output"]
|
|
|
|
|
|
|
|
|
|
|
|
|
| 32 |
log = "\n\n".join([f"{msg.type.upper()}: {msg.content}" for msg in final_state["messages"]])
|
| 33 |
|
| 34 |
+
html_file, log_file, zip_file = save_files(html, log)
|
|
|
|
| 35 |
|
| 36 |
+
# Escape quotes for safe iframe embedding
|
| 37 |
+
escaped_html = html.replace('"', """)
|
| 38 |
preview = f"<iframe srcdoc='{escaped_html}' width='100%' height='600px' style='border:1px solid #ccc;'></iframe>"
|
| 39 |
|
| 40 |
+
return preview, html, log, html_file, log_file, zip_file
|
| 41 |
|
|
|
|
| 42 |
with gr.Blocks() as demo:
|
| 43 |
gr.Markdown("# π€ Multi-Agent UI Generator")
|
| 44 |
+
user_prompt = gr.Textbox(label="Describe your UI", lines=4, value="A yoga retreat homepage with schedule and testimonials.")
|
|
|
|
|
|
|
|
|
|
|
|
|
| 45 |
run_btn = gr.Button("Run Agents")
|
| 46 |
|
| 47 |
gr.Markdown("### π Website Preview")
|
|
|
|
| 65 |
)
|
| 66 |
|
| 67 |
if __name__ == "__main__":
|
| 68 |
+
demo.launch()
|