File size: 750 Bytes
ba4a662
afb453a
1969c22
ba4a662
 
 
 
 
 
 
 
 
 
 
 
 
 
afb453a
ba4a662
 
 
 
 
 
 
 
 
 
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
import gradio as gr
import modelscope_studio.components.base as ms
import modelscope_studio.components.legacy as mgr


def mount(_lifecycle, _state):
    _state["theme"] = _lifecycle.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, ms.Application():
    lifecycle = mgr.Lifecycle()
    state = gr.State({"theme": "light"})
    btn = gr.Button()
    image = gr.Image()

    lifecycle.mount(fn=mount, inputs=[lifecycle, state], outputs=[state])
    btn.click(fn=fn, inputs=[state], outputs=[image])

if __name__ == "__main__":
    demo.queue().launch()