Download app.py from faiz3123/agents: direct link, hf CLI and curl.
- Browser
- Download file 2.91 kB
-
https://huggingface.co/spaces/faiz3123/agents/resolve/main/app.py
- Command line
-
hf download hf://spaces/faiz3123/agents/app.py
-
curl -L -o app.py https://huggingface.co/spaces/faiz3123/agents/resolve/main/app.py
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() | |