Spaces:
Runtime error

agents / app.py
faiz3123's picture
Create app.py
c7caf30 verified
Raw History Blame Contribute Delete
2.91 kB
import gradio as gr
import google.generativeai as genai
# βœ… Public Gemini API key (you provided)
genai.configure(api_key="AIzaSyCWxM6Ic9zs-hZiovnMU8a4UJko7ObqPqU")
model = genai.GenerativeModel("gemini-2.0-flash")
# === Agent Prompt Functions ===
def manager_agent(idea):
prompt = f"""
You are the team manager for a 36-hour hackathon project.
Based on the following idea:
"{idea}"
Break the project into:
1. Frontend tasks
2. Backend tasks
3. AI/ML tasks (if any)
Format as:
### Frontend Tasks
- Task 1
- Task 2
...
### Backend Tasks
- Task 1
...
### AI/ML Tasks
- Task 1
...
"""
return model.generate_content(prompt).text
def frontend_agent(task):
prompt = f"""
You are a frontend developer using React and Tailwind.
Your task is: {task}
Generate code or explain how you'd implement this.
"""
return model.generate_content(prompt).text
def backend_agent(task):
prompt = f"""
You are a backend engineer using Python and FastAPI.
Your task is: {task}
Generate code or implementation steps.
"""
return model.generate_content(prompt).text
def ai_agent(task):
prompt = f"""
You are an AI/ML engineer.
Your task is: {task}
Generate code or describe how to implement the AI/ML part.
"""
return model.generate_content(prompt).text
# === Gradio App Logic ===
def run_agents(idea, f_task, b_task, a_task):
breakdown = manager_agent(idea)
frontend_code = frontend_agent(f_task)
backend_code = backend_agent(b_task)
ai_code = ai_agent(a_task)
return breakdown, frontend_code, backend_code, ai_code
# === Gradio UI ===
with gr.Blocks(title="Hackathon AI Agents") as demo:
gr.Markdown("# πŸ€– Hackathon AI Agent Team (Gemini 2.0 Flash)")
gr.Markdown("Describe your idea and get the full plan with code from multiple agents.")
with gr.Row():
idea = gr.Textbox(label="πŸ’‘ Hackathon Idea", placeholder="e.g., Voice-controlled browser for blind users", lines=3)
submit = gr.Button("🧠 Generate Plan")
breakdown = gr.Textbox(label="πŸ“‹ Task Breakdown", lines=12)
with gr.Row():
f_task = gr.Textbox(label="🎨 Frontend Task", placeholder="Enter frontend task or use auto from breakdown")
b_task = gr.Textbox(label="βš™οΈ Backend Task", placeholder="Enter backend task or use auto")
a_task = gr.Textbox(label="πŸ€– AI/ML Task", placeholder="Enter AI task if any")
run_all = gr.Button("πŸš€ Run All Agents")
frontend_output = gr.Code(label="🎨 Frontend Code (React/Tailwind)", language="javascript")
backend_output = gr.Code(label="βš™οΈ Backend Code (FastAPI)", language="python")
ai_output = gr.Code(label="πŸ€– AI Code / Logic", language="python")
submit.click(fn=manager_agent, inputs=idea, outputs=breakdown)
run_all.click(fn=run_agents, inputs=[idea, f_task, b_task, a_task], outputs=[breakdown, frontend_output, backend_output, ai_output])
demo.launch()