|
|
""" |
|
|
์ปค์คํ
๋ชจ๋ฌ ํ
์คํธ ๋ฐ๋ชจ |
|
|
gradio_modal ํจํค์ง ์์ด Gradio 6์์ ๋ชจ๋ฌ ๋์ ํ์ธ์ฉ |
|
|
""" |
|
|
|
|
|
import gradio as gr |
|
|
from frontend.components.custom_modal import Modal |
|
|
from frontend.components.failure_modal import FailureModalComponent |
|
|
|
|
|
|
|
|
def test_basic_modal(): |
|
|
"""๊ธฐ๋ณธ ๋ชจ๋ฌ ํ
์คํธ""" |
|
|
with gr.Blocks(title="Modal Test") as demo: |
|
|
gr.Markdown("# ๐งช ์ปค์คํ
๋ชจ๋ฌ ํ
์คํธ") |
|
|
gr.Markdown("gradio_modal ํจํค์ง ์์ด ์์ Gradio 6 ์ปดํฌ๋ํธ๋ก ๊ตฌํ") |
|
|
|
|
|
with gr.Row(): |
|
|
show_btn = gr.Button("๋ชจ๋ฌ ์ด๊ธฐ", variant="primary") |
|
|
show_btn2 = gr.Button("๋ค๋ฅธ ๋ด์ฉ์ผ๋ก ์ด๊ธฐ", variant="secondary") |
|
|
|
|
|
|
|
|
modal = Modal( |
|
|
visible=False, |
|
|
allow_user_close=True, |
|
|
elem_id="test-modal" |
|
|
) |
|
|
modal_component = modal.render() |
|
|
|
|
|
|
|
|
show_btn.click( |
|
|
fn=lambda: Modal.show("<h2>Hello World!</h2><p>๋ชจ๋ฌ์ด ์ ์ ์๋ํฉ๋๋ค.</p>"), |
|
|
outputs=[modal_component] |
|
|
) |
|
|
|
|
|
show_btn2.click( |
|
|
fn=lambda: Modal.show(""" |
|
|
<h2>๐ ์ฑ๊ณต!</h2> |
|
|
<p>ESC ํค, ๋ฐฐ๊ฒฝ ํด๋ฆญ, X ๋ฒํผ์ผ๋ก ๋ซ์ ์ ์์ต๋๋ค.</p> |
|
|
<ul> |
|
|
<li>ํญ๋ชฉ 1</li> |
|
|
<li>ํญ๋ชฉ 2</li> |
|
|
<li>ํญ๋ชฉ 3</li> |
|
|
</ul> |
|
|
"""), |
|
|
outputs=[modal_component] |
|
|
) |
|
|
|
|
|
return demo |
|
|
|
|
|
|
|
|
def test_failure_modal(): |
|
|
"""์คํจ ๋ชจ๋ฌ ์ปดํฌ๋ํธ ํ
์คํธ""" |
|
|
with gr.Blocks(title="Failure Modal Test") as demo: |
|
|
gr.Markdown("# ๐งช ์คํจ ๋ชจ๋ฌ ํ
์คํธ") |
|
|
|
|
|
with gr.Row(): |
|
|
test_btn = gr.Button("์คํจ ๋ชจ๋ฌ ํ
์คํธ", variant="stop") |
|
|
|
|
|
|
|
|
failure_modal = FailureModalComponent() |
|
|
modal_component = failure_modal.render() |
|
|
|
|
|
|
|
|
def show_failure(): |
|
|
content = FailureModalComponent.create_modal_content( |
|
|
recognized_text="์๋
ํ์ธ์ฌ", |
|
|
score=65, |
|
|
hint="'์' ๋ฐ์์ ๋ ๋ช
ํํ๊ฒ ํด๋ณด์ธ์!" |
|
|
) |
|
|
return Modal.show(content) |
|
|
|
|
|
test_btn.click( |
|
|
fn=show_failure, |
|
|
outputs=[modal_component] |
|
|
) |
|
|
|
|
|
return demo |
|
|
|
|
|
|
|
|
if __name__ == "__main__": |
|
|
|
|
|
demo = test_basic_modal() |
|
|
|
|
|
|
|
|
import os |
|
|
server_host = os.getenv("SERVER_HOST") |
|
|
demo.launch( |
|
|
server_name=server_host, |
|
|
server_port=7861, |
|
|
show_error=True |
|
|
) |
|
|
|