Created
July 11, 2024 15:42
-
-
Save carlthome/ca18845f07d5288b6b1d0dad7fab99d5 to your computer and use it in GitHub Desktop.
Example of using a dataclass with Gradio
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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