Spaces:
Sleeping
Sleeping
File size: 2,330 Bytes
ae75831 d6076e8 ae75831 d6076e8 ae75831 88c712e ae75831 88c712e ea519a9 88c712e ea519a9 ae75831 88c712e ae75831 ea519a9 88c712e ea519a9 373e120 ae75831 ea519a9 ae75831 ea519a9 ae75831 ea519a9 17aa104 ae75831 d6076e8 ae75831 ac30d30 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 |
import gradio as gr
import zipfile
import os
from langchain_core.messages import HumanMessage
from utils.langgraph_pipeline import run_pipeline_and_save
TEMP_DIR = "generated_output"
os.makedirs(TEMP_DIR, exist_ok=True)
def save_files(html: str, log: str):
html_path = os.path.join(TEMP_DIR, "ui.html")
log_path = os.path.join(TEMP_DIR, "agent_log.txt")
zip_path = os.path.join(TEMP_DIR, "output_bundle.zip")
with open(html_path, "w", encoding="utf-8") as f:
f.write(html)
with open(log_path, "w", encoding="utf-8") as f:
f.write(log)
with zipfile.ZipFile(zip_path, "w") as zipf:
zipf.write(html_path, arcname="ui.html")
zipf.write(log_path, arcname="agent_log.txt")
return html_path, log_path, zip_path
def process(user_input):
messages = [HumanMessage(content=user_input)]
final_state = run_pipeline_and_save(messages)
html = final_state["html_output"]
log = "\n\n".join([f"{msg.type.upper()}: {msg.content}" for msg in final_state["messages"]])
html_file, log_file, zip_file = save_files(html, log)
# Escape quotes for safe iframe embedding
escaped_html = html.replace('"', """)
preview = f"<iframe srcdoc='{escaped_html}' width='100%' height='600px' style='border:1px solid #ccc;'></iframe>"
return preview, html, log, html_file, log_file, zip_file
with gr.Blocks() as demo:
gr.Markdown("# π€ Multi-Agent UI Generator")
user_prompt = gr.Textbox(label="Describe your UI", lines=4, value="A yoga retreat homepage with schedule and testimonials.")
run_btn = gr.Button("Run Agents")
gr.Markdown("### π Website Preview")
preview_html = gr.HTML()
gr.Markdown("### π₯οΈ Generated HTML Code")
html_output = gr.Textbox(lines=15, label="Final HTML")
gr.Markdown("### π¬ Agent Dialogue")
log_output = gr.Textbox(lines=15, label="Conversation Log")
gr.Markdown("### π₯ Download Files")
html_download = gr.File(label="Download HTML")
log_download = gr.File(label="Download Agent Log")
zip_download = gr.File(label="Download All (.zip)")
run_btn.click(
fn=process,
inputs=[user_prompt],
outputs=[preview_html, html_output, log_output, html_download, log_download, zip_download]
)
if __name__ == "__main__":
demo.launch() |