Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -8,15 +8,11 @@ from backend_agent.api_generator import generate_backend_code_llm
|
|
| 8 |
from backend_agent.live_api import app as fastapi_app, add_dynamic_route, run_server
|
| 9 |
import threading
|
| 10 |
|
| 11 |
-
# Ensure directories exist
|
| 12 |
os.makedirs("frontend_live", exist_ok=True)
|
| 13 |
os.makedirs("backend_live", exist_ok=True)
|
| 14 |
|
| 15 |
# Start FastAPI server in a separate thread
|
| 16 |
-
|
| 17 |
-
run_server()
|
| 18 |
-
|
| 19 |
-
threading.Thread(target=start_backend, daemon=True).start()
|
| 20 |
|
| 21 |
def process_brief_live(project_brief):
|
| 22 |
output_text = ""
|
|
@@ -37,34 +33,28 @@ def process_brief_live(project_brief):
|
|
| 37 |
for task, agent in assignment_result["assignments"].items():
|
| 38 |
output_text += f"- {task} -> {agent}\n"
|
| 39 |
|
| 40 |
-
# Step 3: Generate
|
| 41 |
output_text += "\n### Step 3: Live Code Generation\n"
|
| 42 |
|
| 43 |
for task, agent in assignment_result["assignments"].items():
|
| 44 |
output_text += f"\n#### {task} ({agent})\n"
|
| 45 |
|
| 46 |
if "frontend" in agent.lower():
|
| 47 |
-
# Generate React component using LLM
|
| 48 |
code = generate_react_component_llm(task)
|
| 49 |
-
# Save React component for live preview
|
| 50 |
filename = save_react_component(task, code)
|
| 51 |
output_text += f"**Frontend Component Generated:** {filename}\n"
|
| 52 |
output_text += f"Preview: <iframe src='/{filename}' width='100%' height='300'></iframe>\n"
|
| 53 |
|
| 54 |
elif "backend" in agent.lower():
|
| 55 |
-
# Generate backend code using LLM
|
| 56 |
code = generate_backend_code_llm(task)
|
| 57 |
backend_file = f"backend_live/{task.replace(' ', '_')}.py"
|
| 58 |
with open(backend_file, "w") as f:
|
| 59 |
f.write(code)
|
| 60 |
-
#
|
| 61 |
-
safe_code_for_route = 'pass # LLM code executed in separate route' # Placeholder
|
| 62 |
-
add_dynamic_route(task, safe_code_for_route)
|
| 63 |
output_text += f"**Backend API Created:** http://127.0.0.1:8000/{task.replace(' ','_').lower()}\n"
|
| 64 |
|
| 65 |
return output_text
|
| 66 |
|
| 67 |
-
# Gradio UI
|
| 68 |
with gr.Blocks() as demo:
|
| 69 |
gr.Markdown("## AI Project Coordinator - Live Frontend & Backend")
|
| 70 |
project_brief_input = gr.Textbox(lines=3, placeholder="Enter your project brief here...")
|
|
@@ -74,7 +64,6 @@ with gr.Blocks() as demo:
|
|
| 74 |
placeholder="LLM reasoning and live code output will appear here...",
|
| 75 |
lines=30
|
| 76 |
)
|
| 77 |
-
|
| 78 |
submit_button.click(fn=process_brief_live, inputs=project_brief_input, outputs=console_output)
|
| 79 |
|
| 80 |
if __name__ == "__main__":
|
|
|
|
| 8 |
from backend_agent.live_api import app as fastapi_app, add_dynamic_route, run_server
|
| 9 |
import threading
|
| 10 |
|
|
|
|
| 11 |
os.makedirs("frontend_live", exist_ok=True)
|
| 12 |
os.makedirs("backend_live", exist_ok=True)
|
| 13 |
|
| 14 |
# Start FastAPI server in a separate thread
|
| 15 |
+
threading.Thread(target=run_server, daemon=True).start()
|
|
|
|
|
|
|
|
|
|
| 16 |
|
| 17 |
def process_brief_live(project_brief):
|
| 18 |
output_text = ""
|
|
|
|
| 33 |
for task, agent in assignment_result["assignments"].items():
|
| 34 |
output_text += f"- {task} -> {agent}\n"
|
| 35 |
|
| 36 |
+
# Step 3: Generate Live Frontend & Backend
|
| 37 |
output_text += "\n### Step 3: Live Code Generation\n"
|
| 38 |
|
| 39 |
for task, agent in assignment_result["assignments"].items():
|
| 40 |
output_text += f"\n#### {task} ({agent})\n"
|
| 41 |
|
| 42 |
if "frontend" in agent.lower():
|
|
|
|
| 43 |
code = generate_react_component_llm(task)
|
|
|
|
| 44 |
filename = save_react_component(task, code)
|
| 45 |
output_text += f"**Frontend Component Generated:** {filename}\n"
|
| 46 |
output_text += f"Preview: <iframe src='/{filename}' width='100%' height='300'></iframe>\n"
|
| 47 |
|
| 48 |
elif "backend" in agent.lower():
|
|
|
|
| 49 |
code = generate_backend_code_llm(task)
|
| 50 |
backend_file = f"backend_live/{task.replace(' ', '_')}.py"
|
| 51 |
with open(backend_file, "w") as f:
|
| 52 |
f.write(code)
|
| 53 |
+
add_dynamic_route(task, "pass") # placeholder
|
|
|
|
|
|
|
| 54 |
output_text += f"**Backend API Created:** http://127.0.0.1:8000/{task.replace(' ','_').lower()}\n"
|
| 55 |
|
| 56 |
return output_text
|
| 57 |
|
|
|
|
| 58 |
with gr.Blocks() as demo:
|
| 59 |
gr.Markdown("## AI Project Coordinator - Live Frontend & Backend")
|
| 60 |
project_brief_input = gr.Textbox(lines=3, placeholder="Enter your project brief here...")
|
|
|
|
| 64 |
placeholder="LLM reasoning and live code output will appear here...",
|
| 65 |
lines=30
|
| 66 |
)
|
|
|
|
| 67 |
submit_button.click(fn=process_brief_live, inputs=project_brief_input, outputs=console_output)
|
| 68 |
|
| 69 |
if __name__ == "__main__":
|