Download app.py from faiz3123/agent: direct link, hf CLI and curl.
- Browser
- Download file 3.71 kB
-
https://huggingface.co/spaces/faiz3123/agent/resolve/main/app.py
- Command line
-
hf download hf://spaces/faiz3123/agent/app.py
-
curl -L -o app.py https://huggingface.co/spaces/faiz3123/agent/resolve/main/app.py
3.71 kB
| import gradio as gr | |
| import google.generativeai as genai | |
| # β Configure Gemini 2.0 Flash with your public API key | |
| genai.configure(api_key="AIzaSyCWxM6Ic9zs-hZiovnMU8a4UJko7ObqPqU") | |
| model = genai.GenerativeModel("gemini-2.0-flash") | |
| # === π Auto Stack Detection === | |
| def detect_stack(idea): | |
| idea = idea.lower() | |
| if "streamlit" in idea: | |
| return "Streamlit" | |
| elif "gradio" in idea: | |
| return "Gradio" | |
| elif "react" in idea: | |
| return "React + Tailwind" | |
| elif "flask" in idea: | |
| return "Flask" | |
| elif "fastapi" in idea: | |
| return "FastAPI" | |
| elif "django" in idea: | |
| return "Django" | |
| elif "html" in idea or "vanilla" in idea: | |
| return "Vanilla JS/HTML/CSS" | |
| else: | |
| return "Python" | |
| # === π§ Task Breakdown Agent === | |
| 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 strictly as: | |
| ### Frontend Tasks | |
| - ... | |
| ### Backend Tasks | |
| - ... | |
| ### AI/ML Tasks | |
| - ... | |
| """ | |
| return model.generate_content(prompt).text | |
| # === π§° Code-Only Developer Agent === | |
| def agent_prompt(role, task, stack): | |
| return f""" | |
| You are a professional {role} developer. | |
| Your only task is to generate PURE, WORKING code in {stack} for: | |
| \"{task}\" | |
| β οΈ NO explanations. | |
| β οΈ NO comments. | |
| β οΈ NO greetings. | |
| β οΈ Output ONLY the CODE. | |
| """ | |
| def frontend_agent(task, stack): | |
| return model.generate_content(agent_prompt("frontend", task, stack)).text | |
| def backend_agent(task, stack): | |
| return model.generate_content(agent_prompt("backend", task, stack)).text | |
| def ai_agent(task, stack): | |
| return model.generate_content(agent_prompt("AI/ML", task, stack)).text | |
| # === π Main Multi-Agent Pipeline === | |
| def run_agents(idea, tech_stack, f_task, b_task, a_task): | |
| stack = tech_stack if tech_stack.strip() else detect_stack(idea) | |
| breakdown = manager_agent(idea) | |
| frontend_code = frontend_agent(f_task, stack) | |
| backend_code = backend_agent(b_task, stack) | |
| ai_code = ai_agent(a_task, stack) | |
| return stack, breakdown, frontend_code, backend_code, ai_code | |
| # === π¨ Gradio UI === | |
| with gr.Blocks(title="Hackathon AI Agent Team") as demo: | |
| gr.Markdown("# π€ Hackathon AI Agent Team (Gemini 2.0 Flash)") | |
| gr.Markdown("Enter your idea, optionally suggest a tech stack, and let your agents do the coding.") | |
| with gr.Row(): | |
| idea = gr.Textbox(label="π‘ Hackathon Idea", placeholder="e.g., AI agent that builds projects", lines=3) | |
| tech_stack = gr.Textbox(label="π¦ Suggested Tech Stack (optional)", placeholder="e.g., React + FastAPI") | |
| submit = gr.Button("π§ Generate Task Breakdown") | |
| breakdown = gr.Textbox(label="π Task Breakdown", lines=12) | |
| with gr.Row(): | |
| f_task = gr.Textbox(label="π¨ Frontend Task", placeholder="Copy from breakdown or write manually") | |
| b_task = gr.Textbox(label="βοΈ Backend Task") | |
| a_task = gr.Textbox(label="π€ AI/ML Task") | |
| run_all = gr.Button("π Run All Agents") | |
| detected_stack = gr.Textbox(label="π§ Detected/Used Stack", interactive=False) | |
| frontend_output = gr.Code(label="π¨ Frontend Code", language="javascript") | |
| backend_output = gr.Code(label="βοΈ Backend Code", language="python") | |
| ai_output = gr.Code(label="π€ AI/ML Code", language="python") | |
| submit.click(fn=manager_agent, inputs=idea, outputs=breakdown) | |
| run_all.click(fn=run_agents, | |
| inputs=[idea, tech_stack, f_task, b_task, a_task], | |
| outputs=[detected_stack, breakdown, frontend_output, backend_output, ai_output]) | |
| demo.launch() | |