Spaces:
Build error
Build error
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,5 +1,5 @@
|
|
| 1 |
-
import gradio as gr
|
| 2 |
import time
|
|
|
|
| 3 |
|
| 4 |
# ๋ฉ์์ง ๋ด์ฉ ์ค์
|
| 5 |
human_message = "Hello. I'd like to find a round trip commercial airline flight from San Francisco to Denver."
|
|
@@ -7,14 +7,13 @@ ai_message = "Hello, how can I help you?"
|
|
| 7 |
|
| 8 |
def stream_human_message():
|
| 9 |
"""
|
| 10 |
-
Human
|
| 11 |
-
๊ฐ
|
| 12 |
-
|
| 13 |
-
|
| 14 |
"""
|
| 15 |
-
#
|
| 16 |
-
|
| 17 |
-
script = """
|
| 18 |
<script>
|
| 19 |
if (window.cutDone === undefined) { window.cutDone = false; }
|
| 20 |
function handleClick(span) {
|
|
@@ -36,15 +35,14 @@ def stream_human_message():
|
|
| 36 |
}
|
| 37 |
</script>
|
| 38 |
"""
|
| 39 |
-
#
|
| 40 |
-
html =
|
| 41 |
-
"<div id='human_message' "
|
| 42 |
-
"
|
| 43 |
-
"border-radius: 10px; display: inline-block;'>"
|
| 44 |
)
|
| 45 |
-
# ์ด๊ธฐ ์ํ: ์์ง ๋ด์ฉ์ด ์์ ๋
|
| 46 |
yield html
|
| 47 |
-
#
|
| 48 |
for i, ch in enumerate(human_message):
|
| 49 |
html += f"<span data-index='{i}' onclick='handleClick(this)'>{ch}</span>"
|
| 50 |
yield html
|
|
@@ -68,9 +66,10 @@ with gr.Blocks() as demo:
|
|
| 68 |
# ์ค๋ฅธ์ชฝ: Human ๋งํ์ (์คํธ๋ฆฌ๋ฐ ํ
์คํธ)
|
| 69 |
with gr.Column():
|
| 70 |
human_bubble = gr.HTML("")
|
| 71 |
-
|
|
|
|
| 72 |
start_button = gr.Button("Start Typing")
|
| 73 |
-
|
|
|
|
| 74 |
|
| 75 |
demo.launch()
|
| 76 |
-
|
|
|
|
|
|
|
| 1 |
import time
|
| 2 |
+
import gradio as gr
|
| 3 |
|
| 4 |
# ๋ฉ์์ง ๋ด์ฉ ์ค์
|
| 5 |
human_message = "Hello. I'd like to find a round trip commercial airline flight from San Francisco to Denver."
|
|
|
|
| 7 |
|
| 8 |
def stream_human_message():
|
| 9 |
"""
|
| 10 |
+
Human ๋ฉ์์ง๋ฅผ ๋ฌธ์ ๋จ์๋ก ํ์ดํํ๋ ๊ฒ์ฒ๋ผ ์คํธ๋ฆฌ๋ฐํ๋ฉด์,
|
| 11 |
+
๊ฐ ๋ฌธ์์ ํด๋ฆญ ์ด๋ฒคํธ๋ฅผ ๋ถ์ฌํ์ฌ, ํด๋ฆญ ์ ํด๋น ๋ฌธ์ ์ดํ์ โ๏ธ ์ด๋ชจํฐ์ฝ ์ฝ์
๋ฐ ์์ฌ ๋ฌธ์ ํ์ ์ฒ๋ฆฌ๋ฅผ ์ํํฉ๋๋ค.
|
| 12 |
+
|
| 13 |
+
์ ๋๋ ์ดํฐ ํจ์๋ก ๊ตฌํํ์ฌ, ๋งค๋ฒ yield๋ก HTML์ ๋ฐํํจ์ผ๋ก์จ ์คํธ๋ฆฌ๋ฐ ํจ๊ณผ๋ฅผ ๋
๋๋ค.
|
| 14 |
"""
|
| 15 |
+
# ํ์ด์ง์ ์ฝ์
ํ JavaScript ์ฝ๋ (ํ ๋ฒ๋ง ์คํ๋๋๋ก ์ ์ญ ํ๋๊ทธ ์ฌ์ฉ)
|
| 16 |
+
js_script = """
|
|
|
|
| 17 |
<script>
|
| 18 |
if (window.cutDone === undefined) { window.cutDone = false; }
|
| 19 |
function handleClick(span) {
|
|
|
|
| 35 |
}
|
| 36 |
</script>
|
| 37 |
"""
|
| 38 |
+
# Human ๋งํ์ ์ HTML ์ปจํ
์ด๋ ์์ (์ค๋ฅธ์ชฝ ์ ๋ ฌ, ๋ฐฐ๊ฒฝ์ ๋ฑ ์คํ์ผ ์ง์ )
|
| 39 |
+
html = js_script + (
|
| 40 |
+
"<div id='human_message' style='text-align: right; background-color: #d0f0d0; "
|
| 41 |
+
"padding: 10px; border-radius: 10px; display: inline-block;'>"
|
|
|
|
| 42 |
)
|
| 43 |
+
# ์ด๊ธฐ ์ํ: ์์ง ๋ด์ฉ์ด ์์ ๋ yield
|
| 44 |
yield html
|
| 45 |
+
# ๋ฉ์์ง๋ฅผ ํ ๊ธ์์ฉ ์ถ๊ฐํ๋ฉฐ yield (ํ์ดํ ํจ๊ณผ)
|
| 46 |
for i, ch in enumerate(human_message):
|
| 47 |
html += f"<span data-index='{i}' onclick='handleClick(this)'>{ch}</span>"
|
| 48 |
yield html
|
|
|
|
| 66 |
# ์ค๋ฅธ์ชฝ: Human ๋งํ์ (์คํธ๋ฆฌ๋ฐ ํ
์คํธ)
|
| 67 |
with gr.Column():
|
| 68 |
human_bubble = gr.HTML("")
|
| 69 |
+
|
| 70 |
+
# ํ์ดํ ํจ๊ณผ๋ฅผ ์์ํ ๋ฒํผ
|
| 71 |
start_button = gr.Button("Start Typing")
|
| 72 |
+
# ์ ๋๋ ์ดํฐ ํจ์๋ฅผ click ์ด๋ฒคํธ์ ๋ฑ๋ก (stream ์ธ์ ์์ด๋ ์ ๋๋ ์ดํฐ ํจ์์ yield๊ฐ ์์ฐจ์ ์ผ๋ก ๋ฐ์๋ฉ๋๋ค)
|
| 73 |
+
start_button.click(fn=stream_human_message, outputs=human_bubble)
|
| 74 |
|
| 75 |
demo.launch()
|
|
|