Spaces:
Running
Running
File size: 804 Bytes
ba4a662 e841ba5 ba4a662 e841ba5 ba4a662 e841ba5 ba4a662 e841ba5 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 30 31 32 33 34 35 36 37 38 39 40 |
import time
import gradio as gr
import modelscope_studio.components.base as ms
messages = {
'en': {
"hello": "Hello"
},
'en-US': {
"hello": "Hello"
},
'zh-CN': {
"hello": "你好"
}
}
default_lang = "en"
def mount(e: gr.EventData, _state):
lang = e._data["language"]
if (lang in messages):
_state["current_lang"] = lang
yield 'Switch Language...', _state
time.sleep(2)
yield messages[lang]["hello"], _state
with gr.Blocks() as demo:
with ms.Application() as app:
state = gr.State({"current_lang": default_lang})
markdown = gr.Markdown(value=messages[default_lang]["hello"])
app.mount(fn=mount, inputs=[state], outputs=[markdown, state])
if __name__ == "__main__":
demo.queue().launch()
|