Spaces:
Sleeping

AIEngineer / app.py
Fsubhan786's picture
Upload 6 files
2131907 verified
Raw History Blame Contribute Delete
1.59 kB
"""
app.py — agent UI that shows BOTH the final answer and the tool-call trace,
so reviewers can see the agent reasoning, not just the result.
Deploys free to Hugging Face Spaces.
"""
import gradio as gr
from agent import run
def respond(goal):
if not goal.strip():
return "Give the agent a goal.", ""
try:
answer, trace = run(goal)
trace_text = "\n".join(trace) if trace else "(no tools were needed)"
return answer, trace_text
except Exception as e:
message = str(e)
if "RESOURCE_EXHAUSTED" in message or "429" in message:
return (
"Gemini free-tier quota is temporarily exhausted. Wait and retry, "
"or set GEMINI_MODEL=gemini-2.5-flash-lite in .env / Space variables.",
message,
)
return "The agent hit an error. See the trace box for details.", message
with gr.Blocks(title="AI Engineer — Project 3 Agent") as demo:
gr.Markdown("# Tool-Using Agent\n"
"Calculator · live weather · persistent notes. Bounded loop with guardrails. "
"Project 3 of 4.")
goal = gr.Textbox(label="Goal",
placeholder="e.g. What's sqrt(2025)? Save it as a note, then list my notes.")
go = gr.Button("Run agent", variant="primary")
answer = gr.Markdown(label="Answer")
trace = gr.Textbox(label="Tool-call trace", lines=8, interactive=False)
go.click(respond, [goal], [answer, trace])
goal.submit(respond, [goal], [answer, trace])
if __name__ == "__main__":
demo.launch()