Skip to content

Instantly share code, notes, and snippets.

@carlthome
Created July 11, 2024 15:42
Show Gist options
  • Save carlthome/ca18845f07d5288b6b1d0dad7fab99d5 to your computer and use it in GitHub Desktop.
Save carlthome/ca18845f07d5288b6b1d0dad7fab99d5 to your computer and use it in GitHub Desktop.
Example of using a dataclass with Gradio
import numpy as np
from dataclasses import dataclass
import gradio as gr
@dataclass
class A:
x: int
y: int
z: np.ndarray
def update_dropdown(a: A):
return a.x + a.y
with gr.Blocks() as demo:
a = gr.State(A(1, 2, np.zeros(3)))
dropdown = gr.Dropdown(choices=["a", "b", "c"], label="Select a letter")
result = gr.Number(label="Number")
dropdown.input(update_dropdown, inputs=[a], outputs=[result])
if __name__ == "__main__":
demo.launch()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment