-
Notifications
You must be signed in to change notification settings - Fork 1
Gradio Notes
j-sawn edited this page Apr 15, 2025
·
20 revisions
In a new terminal run (see below if this doesn't work):
docker pull matimedes/southerncrossai:modelworks
docker run -it --name modelworks-container -p 7860:7860 matimedes/southerncrossai:modelworks
or run container with GPU:
docker run -it --gpus all --runtime=nvidia --name modelworks-container-gpu -p 7860:7860 matimedes/southerncrossai:modelworks /bin/bash
use cd to move to the dir you want to work in then run
python3 -m venv ./app/venv
source ./app/venv/bin/activate
pip install gradio
touch ./app/app.py
open the app.py file and write the following inside
import gradio as gr
def greet(name, intensity):
return "Hello, " + name + "!" * int(intensity)
demo = gr.Interface(
fn=greet,
inputs=["text", "slider"],
outputs=["text"],
)
demo.launch(server_name="0.0.0.0", server_port=7860)
save that then in the same directory run
python ./app/app.py
open a browser and go to http://localhost:7860
More information on Interfaces can be found at Gradio's Documentation
- Official page on Gradio Docs: https://www.gradio.app/docs/gradio/interface
- Pros:
- Most UI elements are all in one place
- Good for something meant for easy use (such as a chatbot)
- Most UI elements are all in one place
- Cons:
- Limited input and output options
- Expects text inputs and outputs only
- Expects text inputs and outputs only
- Limited input and output options
- Official page on Gradio Docs: https://www.gradio.app/docs/gradio/chatinterface
- Pros:
- Good for inputs and outputs of differing types
- e.g. This would be the perfect interface for an image generator (inputs =
"text", outputs ="image")
- e.g. This would be the perfect interface for an image generator (inputs =
- Good for inputs and outputs of differing types
- Cons:
- Components are all separated
- This could be unnecessary for something simpler like a chatbot
- This could be unnecessary for something simpler like a chatbot
- Components are all separated
- Official page on Gradio Docs: https://www.gradio.app/docs/gradio/blocks
- This is not necessarily an interface, but rather a functionality of Gradio that can combine both components and interfaces
- It does, however, have a way of distributing attributes across all components/interfaces
- This allows for UI to be more unique, but also uniform
- You can set it up by pretty much stacking components and interfaces on top of each other
- An example can be seen below:
with gr.Blocks( ... ) as demo:
gr.Markdown( ... ),
gr.ChatInterface(
fn=...,
type="messages",
# ... insert any other attributes here
)
.
.
.
- Official page on Gradio Docs: https://www.gradio.app/docs/gradio/markdown
- Pros:
- A straightforward way of implementing simple UI changes
- e.g. You are able to add an image
- Pretty simple once you get the hang of the Markdown language
- A straightforward way of implementing simple UI changes
- Cons:
- Official page on Gradio Docs: https://www.gradio.app/docs/gradio/row
- This is another functionality of Gradio that can connect components/interfaces together. This time, it groups components/interfaces side by side, as seen below (code credit (thank you!)):
with gr.Blocks() as demo:
.
.
.
# Places two or more components side by side
with gr.Row():
pdf_input = gr.File(label="π€ Upload PDF file", type="filepath")
pdf_output = gr.Textbox(label="π Processing Result")
.
.
.
- wip
- Has CSS-like notation
- Utils it uses (e.g. color, font) can be found here
- Colours
- Gradio has a selection of colours you can choose from (you can refer to all possible names here)
- You can make custom Gradio colours by typing the following:
example_hue = gr.themes.Color(
c50=[colour 1], # colour of chatwindow (light)*
c100=[colour 2], # text colour outside
c200=[colour 3], # text/icon colour of chatwindow (dark), inside of textbox (light)
c300=[colour 4], # what
c400=[colour 5],
c500=[colour 6], # text/icon inside chatwindow (light)
c600=[colour 7],
c700=[colour 8], # inside textbox/textbubble, border (dark)*
c800=[colour 9], # outside textbox (dark), text colour (light)*
c900=[colour 10], # colour of chatwindow*
c950=[colour 11]), # error colour and dark mode settings window
- More information can be found here
- This can be achieved by just copying and pasting CSS or JS code into a
String, turning it into a variable in Python, and assigning it as a parameter of a given interface.- e.g., follow the instructions below:
- Make up a random bit of CSS (e.g.
.gradio-container {background-color: red}) - Make a variable (e.g.
my_css) - Write
css = "[INSERT YOUR CSS HERE]" - Within the brackets of your Gradio interface, insert "
css=my_css")
- Make up a random bit of CSS (e.g.
- e.g., follow the instructions below:
- More information can be found here
- If you want to make the app.py file from the command line type vi /app.py and then press i to insert code then copy in the necessary code. Then press Esc then type
:wqthen Enter - Otherwise, you might want to do the following if you want to test files that are already in your system but you are using a non-Linux device:
docker cp "[INSERT LOCAL PATH TO YOUR FILE YOU WANT TO RUN]" [INSERT CONTAINER NAME]:[INSERT DIRECTORY OF CONTAINER YOU WANT TO SAVE THE FILE IN]
- Alternatively, if you already have Gradio installed in a container but did not expose the port (
-p 7860:7860), then you can run the following:docker commit [INSERT CONTAINER NAME] [INSERT WHAT YOU'D LIKE TO CALL YOUR NEW IMAGE]docker run -it --name [INSERT WHAT YOU'D LIKE TO CALL YOUR NEW CONTAINER] -p 7860:7860 [INSERT WHAT YOU'D LIKE TO CALL YOUR NEW IMAGE]
Welcome to the ModelWorks Wiki! Use the links below to navigate our resources quickly.
Product Information
- π¦ !! JoeyLLM Guide !! π¦
- Shared Product Vision
- Personas, Scenarios, & User Stories
- Procedure to Resolve Conflicts
- Project Milestones
- Decision Making Protocol
- Story Point Estimation Algorithm
- Gradio Notes
- Javascript Notes (split into two)
- Ollama Notes
- Langchain Notes
- Chroma Notes
- GPU Monitor Notes
- Open WebUI Notes
- Web Search Notes
- Chat History Notes
- Meeting Minute 1
- Meeting Minute 2
- Meeting Minute 3
- Meeting Minute 4
- Meeting Minute 5
- Meeting Minute 6
- Meeting Minute 7
- Meeting Minute 8
- Meeting Minute 9
- Meeting Minute 10
- Meeting Minute 11