Spaces:
Running
Running
File size: 890 Bytes
e841ba5 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
import gradio as gr
import modelscope_studio.components.antd as antd
import modelscope_studio.components.base as ms
def mount(e: gr.EventData, _state):
_state["theme"] = e._data["theme"]
yield _state
def fn(_state):
theme = _state["theme"]
color = '000/fff' if theme == 'dark' else 'fff/000'
yield gr.update(
value=f"https://dummyimage.com/200x100/{color}.png&text={theme}")
with gr.Blocks() as demo:
state = gr.State({"theme": "light"})
with ms.Application() as app:
with antd.ConfigProvider():
btn = antd.Button(
"Run",
type="primary",
block=True,
)
image = antd.Image()
app.mount(fn=mount, inputs=[state], outputs=[state])
btn.click(fn=fn, inputs=[state], outputs=[image])
if __name__ == "__main__":
demo.queue().launch()
|