Develop UI with Gradio¶
Gradio is the fastest way to demo stuff with a user interface. One of its advantages against StreamLit is the capacity to share data between pages and elements.
# For continuous development
gradio main.py
# For running a server
python main.app
Open in a browser on http://localhost:7860
Main concepts¶
- A python function can be wrapped with a user interface
- Use
gr.Blocks
to develop custom interface. Components are automatically added to the Blocks as they are created within thewith
clause. It is a classic python function. - Any Component that acts as an input to an event listener is made interactive
-
Global state can be set via variable at the top of the program, and are shared between connected session
-
Chatbot and ChatInterface to build simple user interface for a chat bot demo.
How to¶
- Add accordion to an interface
- To make an output R/W:
output = gr.Textbox(label="Output", interactive=True)
- Updating Component Configurations