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

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +44 -14
app.py CHANGED
@@ -180,27 +180,57 @@ workflow = AgentWorkflow(
180
  )
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()
 
180
  )
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
+ # New unified respond() function
194
+ async def respond(message, history):
195
+ # (Optional) Format history if needed by your agent system
196
+ formatted_history = []
197
+ for user_msg, bot_msg in history:
198
+ if user_msg: # User input
199
+ formatted_history.append({"role": "user", "content": user_msg})
200
+ if bot_msg: # Bot output
201
+ formatted_history.append({"role": "assistant", "content": bot_msg})
202
+
203
+ # Run the agent workflow
204
+ out = await workflow.run(user_msg=message, ctx=ctx, memory=memory)
205
+ return out.response.blocks[0].text
206
 
207
  # --- Gradio UI ---
208
+ # with gr.Blocks() as demo:
209
+ # gr.Markdown("## 🤖 Perspicacity")
210
+ # gr.Markdown(
211
+ # "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"
212
+ # "🧪 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"
213
+ # "🙌 Got ideas or improvements? PRs welcome!"
214
+ # )
215
+ # chatbot = gr.Chatbot()
216
+ # txt = gr.Textbox(placeholder="Ask me about news, weather, etc…")
217
+
218
+ # txt.submit(respond_gradio, inputs=[txt, chatbot], outputs=chatbot)
219
+
220
+ # demo.launch()
221
+
222
  with gr.Blocks() as demo:
223
+ gr.Markdown("## 🗞️ Multi‐Agent News & Weather Chatbot")
224
  gr.Markdown(
225
+ "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"
226
+ "🧪 Built for fun during the [AI Agents course](https://huggingface.co/learn/agents-course/unit0/introduction) — it's just a demo to show what agents can do.\n"
227
+ "🙌 Got ideas or improvements? PRs welcome!\n\n"
228
+ "👉 _Try asking “What’s the weather in Montreal?” or “What’s in the news today?”_"
229
  )
230
+
231
  chatbot = gr.Chatbot()
232
+ txt = gr.Textbox(placeholder="Ask me about news, weather or anything…")
233
 
234
+ txt.submit(respond, inputs=[txt, chatbot], outputs=chatbot)
235
 
236
  demo.launch()