Spaces:
Sleeping
Sleeping
File size: 1,587 Bytes
73fe831 2131907 73fe831 2131907 73fe831 2131907 73fe831 2131907 73fe831 2131907 73fe831 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 | """
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()
|