VoiceSementle / client /test_modal.py
SJLee-0525
[CHORE] test9
9f30ef0
raw
history blame
2.71 kB
"""
์ปค์Šคํ…€ ๋ชจ๋‹ฌ ํ…Œ์ŠคํŠธ ๋ฐ๋ชจ
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()
# demo = test_failure_modal()
import os
server_host = os.getenv("SERVER_HOST")
demo.launch(
server_name=server_host,
server_port=7861, # ํ…Œ์ŠคํŠธ์šฉ ๋ณ„๋„ ํฌํŠธ
show_error=True
)