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

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +5 -13
app.py CHANGED
@@ -192,17 +192,10 @@ ctx = Context(workflow)
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:
@@ -218,13 +211,12 @@ async def respond(message, history):
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
 
 
192
 
193
  # New unified respond() function
194
  async def respond(message, history):
 
 
 
 
 
 
 
 
 
195
  out = await workflow.run(user_msg=message, ctx=ctx, memory=memory)
196
+ answer = out.response.blocks[0].text
197
+ # Return the full updated history
198
+ return history + [[message, answer]]
199
 
200
  # --- Gradio UI ---
201
  # with gr.Blocks() as demo:
 
211
  # txt.submit(respond_gradio, inputs=[txt, chatbot], outputs=chatbot)
212
 
213
  # demo.launch()
 
214
  with gr.Blocks() as demo:
215
  gr.Markdown("## 🗞️ Multi‐Agent News & Weather Chatbot")
216
  gr.Markdown(
217
  "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"
218
+ "🧪 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"
219
+ "🙌 Got ideas or improvements? PRs welcome! \n\n"
220
  "👉 _Try asking “What’s the weather in Montreal?” or “What’s in the news today?”_"
221
  )
222