Skip to content
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

Allow Gradio share parameter passthrough #490

Merged
merged 4 commits into from
Feb 13, 2025
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions docs/source/en/guided_tour.md
Original file line number Diff line number Diff line change
Expand Up @@ -395,6 +395,12 @@ agent = CodeAgent(tools=[image_generation_tool], model=model)
GradioUI(agent).launch()
```

If you prefer to keep this private and not accessible via a public link, you can set `share=False`:

```py
GradioUI(agent).launch(share=False)
```

Under the hood, when the user types a new answer, the agent is launched with `agent.run(user_request, reset=False)`.
The `reset=False` flag means the agent's memory is not flushed before launching this new task, which lets the conversation go on.

Expand Down
4 changes: 2 additions & 2 deletions src/smolagents/gradio_ui.py
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,7 @@ def log_user_message(self, text_input, file_uploads_log):
"",
)

def launch(self, **kwargs):
def launch(self, share: bool = True, **kwargs):
import gradio as gr

with gr.Blocks(fill_height=True) as demo:
Expand Down Expand Up @@ -290,7 +290,7 @@ def launch(self, **kwargs):
[stored_messages, text_input],
).then(self.interact_with_agent, [stored_messages, chatbot], [chatbot])

demo.launch(debug=True, share=True, **kwargs)
demo.launch(debug=True, share=share, **kwargs)


__all__ = ["stream_to_gradio", "GradioUI"]