fdaudens HF Staff commited on
Commit
7fed917
·
verified ·
1 Parent(s): df80b38

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +18 -6
app.py CHANGED
@@ -181,14 +181,26 @@ workflow = AgentWorkflow(
181
  ctx = Context(workflow)
182
 
183
  # Sync wrapper
184
- def respond(query: str) -> str:
185
- out = asyncio.run(workflow.run(user_msg=query, ctx=ctx, memory=memory))
186
  return out.response.blocks[0].text
 
 
 
 
 
187
 
188
  # --- Gradio UI ---
189
  with gr.Blocks() as demo:
190
- gr.Markdown("## 🗞️ Multi‐Agent News & Weather Chatbot")
 
 
 
 
 
191
  chatbot = gr.Chatbot()
192
- txt = gr.Textbox(placeholder="Ask me about news, weather or anything…")
193
- txt.submit(lambda q, chat: (chat + [[q, respond(q)]]), [txt, chatbot], chatbot)
194
- demo.launch()
 
 
 
181
  ctx = Context(workflow)
182
 
183
  # Sync wrapper
184
+ async def respond(query: str) -> str:
185
+ out = await workflow.run(user_msg=query, ctx=ctx, memory=memory)
186
  return out.response.blocks[0].text
187
+
188
+ # Async response handler for Gradio
189
+ async def respond_gradio(query, chat_history):
190
+ answer = await respond(query)
191
+ return chat_history + [[query, answer]]
192
 
193
  # --- Gradio UI ---
194
  with gr.Blocks() as demo:
195
+ gr.Markdown("## 🤖 Perspicacity")
196
+ gr.Markdown(
197
+ "This bot can check the news, tell you the weather, and even browse websites to answer follow-up questions — all powered by a team of tiny AI agents working behind the scenes. \n\n"
198
+ "🧪 Built for fun during the [AI Agents course](https://huggingface.co/learn/agents-course/unit0/introduction) at Hugging Face — it's just a demo to show what agents can do. \n"
199
+ "🙌 Got ideas or improvements? PRs welcome!"
200
+ )
201
  chatbot = gr.Chatbot()
202
+ txt = gr.Textbox(placeholder="Ask me about news, weather, etc…")
203
+
204
+ txt.submit(respond_gradio, inputs=[txt, chatbot], outputs=chatbot)
205
+
206
+ demo.launch()