Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -315,13 +315,20 @@ async def run_query(query: str):
|
|
315 |
instrumentor.flush()
|
316 |
|
317 |
# Gradio interface function
|
318 |
-
async def
|
319 |
history = chat_history or []
|
320 |
history.append({"role": "user", "content": user_input})
|
321 |
-
|
322 |
-
|
323 |
-
|
324 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
325 |
|
326 |
# Build and launch Gradio app
|
327 |
grb = gr.Blocks()
|
@@ -332,17 +339,18 @@ with grb:
|
|
332 |
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 tools working behind the scenes.\n\n
|
333 |
π§ͺ 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
|
334 |
π Got ideas or improvements? PRs welcome!\n\n
|
335 |
-
π
|
336 |
"""
|
337 |
)
|
338 |
chatbot = gr.Chatbot(type="messages")
|
339 |
txt = gr.Textbox(placeholder="Ask me anything...", show_label=False)
|
340 |
txt.submit(
|
341 |
-
|
342 |
inputs=[txt, chatbot],
|
343 |
-
outputs=[chatbot, chatbot]
|
|
|
344 |
)
|
345 |
-
gr.Button("Send").click(
|
346 |
|
347 |
if __name__ == "__main__":
|
348 |
grb.launch()
|
|
|
315 |
instrumentor.flush()
|
316 |
|
317 |
# Gradio interface function
|
318 |
+
async def gradio_query_stream(user_input, chat_history=None):
|
319 |
history = chat_history or []
|
320 |
history.append({"role": "user", "content": user_input})
|
321 |
+
# Start streaming response from the agent
|
322 |
+
result = await web_agent.run(user_input, ctx=ctx, streaming=True)
|
323 |
+
partial = ""
|
324 |
+
async for chunk in result.response_gen:
|
325 |
+
# If chunk is an object, use chunk.delta or chunk.text
|
326 |
+
partial += chunk
|
327 |
+
if len(history) > 1 and history[-1]["role"] == "assistant":
|
328 |
+
history[-1]["content"] = partial
|
329 |
+
else:
|
330 |
+
history.append({"role": "assistant", "content": partial})
|
331 |
+
yield history, history
|
332 |
|
333 |
# Build and launch Gradio app
|
334 |
grb = gr.Blocks()
|
|
|
339 |
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 tools working behind the scenes.\n\n
|
340 |
π§ͺ 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
|
341 |
π Got ideas or improvements? PRs welcome!\n\n
|
342 |
+
π Try asking 'What's the weather in Montreal?' or 'What's in the news today?'
|
343 |
"""
|
344 |
)
|
345 |
chatbot = gr.Chatbot(type="messages")
|
346 |
txt = gr.Textbox(placeholder="Ask me anything...", show_label=False)
|
347 |
txt.submit(
|
348 |
+
gradio_query_stream,
|
349 |
inputs=[txt, chatbot],
|
350 |
+
outputs=[chatbot, chatbot],
|
351 |
+
stream=True
|
352 |
)
|
353 |
+
gr.Button("Send").click(gradio_query_stream, [txt, chatbot], [chatbot, chatbot])
|
354 |
|
355 |
if __name__ == "__main__":
|
356 |
grb.launch()
|