-
Notifications
You must be signed in to change notification settings - Fork 2k
Added sidebar layout and session state management for agent #797
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Added sidebar layout and session state management for agent #797
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the enhancement!
I have just fixed the style by running make style
.
Please note that when launching the application:
GradioUI(agent).launch()
I get an error:
ERROR: Exception in ASGI application
and more concretely:
AttributeError: 'NoneType' object has no attribute 'wait'
Here, the complete stack trace:
ERROR: Exception in ASGI application
Traceback (most recent call last):
File "/huggingface/smolagents/examples/open_deep_research/venv/lib/python3.12/site-packages/starlette/responses.py", line 268, in __call__
await wrap(partial(self.listen_for_disconnect, receive))
File "/huggingface/smolagents/examples/open_deep_research/venv/lib/python3.12/site-packages/starlette/responses.py", line 264, in wrap
await func()
File "/huggingface/smolagents/examples/open_deep_research/venv/lib/python3.12/site-packages/starlette/responses.py", line 233, in listen_for_disconnect
message = await receive()
^^^^^^^^^^^^^^^
File "/huggingface/smolagents/examples/open_deep_research/venv/lib/python3.12/site-packages/uvicorn/protocols/http/h11_impl.py", line 531, in receive
await self.message_event.wait()
File "/home/albert/.pyenv/versions/3.12.7/lib/python3.12/asyncio/locks.py", line 212, in wait
await fut
asyncio.exceptions.CancelledError: Cancelled by cancel scope 7f9d063544a0
During handling of the above exception, another exception occurred:
+ Exception Group Traceback (most recent call last):
| File "/huggingface/smolagents/examples/open_deep_research/venv/lib/python3.12/site-packages/uvicorn/protocols/http/h11_impl.py", line 403, in run_asgi
| result = await app( # type: ignore[func-returns-value]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
| File "/huggingface/smolagents/examples/open_deep_research/venv/lib/python3.12/site-packages/uvicorn/middleware/proxy_headers.py", line 60, in __call__
| return await self.app(scope, receive, send)
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
| File "/huggingface/smolagents/examples/open_deep_research/venv/lib/python3.12/site-packages/fastapi/applications.py", line 1054, in __call__
| await super().__call__(scope, receive, send)
| File "/huggingface/smolagents/examples/open_deep_research/venv/lib/python3.12/site-packages/starlette/applications.py", line 112, in __call__
| await self.middleware_stack(scope, receive, send)
| File "/huggingface/smolagents/examples/open_deep_research/venv/lib/python3.12/site-packages/starlette/middleware/errors.py", line 187, in __call__
| raise exc
| File "/huggingface/smolagents/examples/open_deep_research/venv/lib/python3.12/site-packages/starlette/middleware/errors.py", line 165, in __call__
| await self.app(scope, receive, _send)
| File "/huggingface/smolagents/examples/open_deep_research/venv/lib/python3.12/site-packages/gradio/route_utils.py", line 789, in __call__
| await self.app(scope, receive, send)
| File "/huggingface/smolagents/examples/open_deep_research/venv/lib/python3.12/site-packages/starlette/middleware/exceptions.py", line 62, in __call__
| await wrap_app_handling_exceptions(self.app, conn)(scope, receive, send)
| File "//huggingface/smolagents/examples/open_deep_research/venv/lib/python3.12/site-packages/starlette/_exception_handler.py", line 53, in wrapped_app
| raise exc
| File "/huggingface/smolagents/examples/open_deep_research/venv/lib/python3.12/site-packages/starlette/_exception_handler.py", line 42, in wrapped_app
| await app(scope, receive, sender)
| File "/huggingface/smolagents/examples/open_deep_research/venv/lib/python3.12/site-packages/starlette/routing.py", line 715, in __call__
| await self.middleware_stack(scope, receive, send)
| File "/huggingface/smolagents/examples/open_deep_research/venv/lib/python3.12/site-packages/starlette/routing.py", line 735, in app
| await route.handle(scope, receive, send)
| File "/huggingface/smolagents/examples/open_deep_research/venv/lib/python3.12/site-packages/starlette/routing.py", line 288, in handle
| await self.app(scope, receive, send)
| File "/huggingface/smolagents/examples/open_deep_research/venv/lib/python3.12/site-packages/starlette/routing.py", line 76, in app
| await wrap_app_handling_exceptions(app, request)(scope, receive, send)
| File "/huggingface/smolagents/examples/open_deep_research/venv/lib/python3.12/site-packages/starlette/_exception_handler.py", line 53, in wrapped_app
| raise exc
| File "/huggingface/smolagents/examples/open_deep_research/venv/lib/python3.12/site-packages/starlette/_exception_handler.py", line 42, in wrapped_app
| await app(scope, receive, sender)
| File "/huggingface/smolagents/examples/open_deep_research/venv/lib/python3.12/site-packages/starlette/routing.py", line 74, in app
| await response(scope, receive, send)
| File "/huggingface/smolagents/examples/open_deep_research/venv/lib/python3.12/site-packages/starlette/responses.py", line 261, in __call__
| async with anyio.create_task_group() as task_group:
| ^^^^^^^^^^^^^^^^^^^^^^^^^
| File "/huggingface/smolagents/examples/open_deep_research/venv/lib/python3.12/site-packages/anyio/_backends/_asyncio.py", line 767, in __aexit__
| raise BaseExceptionGroup(
| ExceptionGroup: unhandled errors in a TaskGroup (1 sub-exception)
+-+---------------- 1 ----------------
| Traceback (most recent call last):
| File "/huggingface/smolagents/examples/open_deep_research/venv/lib/python3.12/site-packages/starlette/responses.py", line 264, in wrap
| await func()
| File "/huggingface/smolagents/examples/open_deep_research/venv/lib/python3.12/site-packages/starlette/responses.py", line 245, in stream_response
| async for chunk in self.body_iterator:
| File "/huggingface/smolagents/examples/open_deep_research/venv/lib/python3.12/site-packages/gradio/routes.py", line 944, in iterator
| done = [d.result() for d in done]
| ^^^^^^^^^^
| File "/huggingface/smolagents/examples/open_deep_research/venv/lib/python3.12/site-packages/gradio/routes.py", line 929, in stop_stream
| await app.stop_event.wait()
| ^^^^^^^^^^^^^^^^^^^
| AttributeError: 'NoneType' object has no attribute 'wait'
+------------------------------------
I am using gradio-5.18.0.
ah, I think I know what went wrong, fixing it in a bit. Thanks @albertvillanova ! |
I think the issue had to do with my local event loop being already in use in the main thread... 😅 I managed to make it run in another environment. |
Perhaps it was that, or I faced another issue, which I have resolved now. I had unnecessary nested
|
Also tested the push to hub feature. The loading animation displays nicely while waiting for the next step to load. cc: @aymeric-roucher : |
I’m having trouble understanding the issue. Could you provide more details about it?
This might relate to a Gradio issue rather than a problem with |
Yes, I think it is a Gradio issue. This is what the agent logged in the terminal:
However, that text is rendered with wrong fonts (some smaller, some larger), as in the picture I attached above. |
Oh, another thing! This UI doesn’t currently support nested agents, but I plan to open a new PR for that in a couple of days. It looks like your logs relate to a nested use case, right?
|
Is it possible to provide a simple reproduction for this issue, @albertvillanova? I am trying to replicate it on my end as well in the meantime. |
I used the app in: And asked the question: "What were the names of the last three prime ministers in Spain?" |
For the text rendering issue, please note that it went wrong with the text between that No need of nested agents for these tags to appear... |
Wow @yvrjsharma the loading animation looks amazing! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@yvrjsharma the issue happens on line 91: the content here should be displayed as code, but I think it gets interpreted as Markdown. So mauybe you could wrap it in backquotes like f"```bash\n{content}\n```"
. To be clear the issue was preexistent to this PR!
1f3678b
to
60e8326
Compare
All good! Can't fix ruff error because it seems I have a version issue, maybe we should pin ruff version. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks a lot @yvrjsharma , this is a great improvement!
Changes made:
All these changes are inspired by the open-deep-research implementation while maintaining compatibility with the original API.