Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,30 +1,68 @@
|
|
| 1 |
import gradio as gr
|
|
|
|
|
|
|
| 2 |
|
| 3 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 4 |
statement = ""
|
| 5 |
|
| 6 |
-
def update_statement(
|
| 7 |
global statement
|
| 8 |
-
statement =
|
| 9 |
return statement
|
| 10 |
|
| 11 |
with gr.Blocks() as demo:
|
| 12 |
-
# ๋ ๊ฐ์
|
| 13 |
with gr.Row():
|
| 14 |
-
conversation_A = gr.Textbox(label="Conversation A", placeholder="
|
| 15 |
-
conversation_B = gr.Textbox(label="Conversation B", placeholder="
|
|
|
|
|
|
|
|
|
|
|
|
|
| 16 |
|
| 17 |
-
#
|
| 18 |
with gr.Row():
|
| 19 |
-
btn_both_good = gr.Button("Both good") #
|
| 20 |
-
btn_a_better = gr.Button("A is better") #
|
| 21 |
-
btn_b_better = gr.Button("B is better") #
|
| 22 |
-
btn_both_bad = gr.Button("Both not good") #
|
| 23 |
|
| 24 |
-
# ์ ํ๋ statement
|
| 25 |
statement_output = gr.Textbox(label="Selected Statement", value="", interactive=False)
|
| 26 |
|
| 27 |
-
# ๊ฐ ๋ฒํผ ํด๋ฆญ ์
|
| 28 |
btn_both_good.click(fn=lambda: update_statement("BG"), inputs=[], outputs=statement_output)
|
| 29 |
btn_a_better.click(fn=lambda: update_statement("AG"), inputs=[], outputs=statement_output)
|
| 30 |
btn_b_better.click(fn=lambda: update_statement("BG"), inputs=[], outputs=statement_output)
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
+
from datasets import load_dataset
|
| 3 |
+
import random
|
| 4 |
|
| 5 |
+
def load_random_conversations():
|
| 6 |
+
"""
|
| 7 |
+
๋ฐ์ดํฐ์
'gaeunseo/Taskmaster_sample_data'์ train split์์
|
| 8 |
+
conversation_id๋ณ๋ก ๊ทธ๋ฃนํํ ํ, ๊ฐ ๊ทธ๋ฃน์ ๋ชจ๋ ํ์ used๊ฐ False์ธ
|
| 9 |
+
๊ทธ๋ฃน๋ค ์ค์์ ๋๋คํ๊ฒ 2๊ฐ ๊ทธ๋ฃน์ ์ ํํ์ฌ, ๊ฐ ๊ทธ๋ฃน์ utterance๋ค์
|
| 10 |
+
newline์ผ๋ก joinํ ๋ฌธ์์ด์ ๋ฐํํฉ๋๋ค.
|
| 11 |
+
"""
|
| 12 |
+
# ๋ฐ์ดํฐ์
๋ก๋ (split ์ด๋ฆ์ ์ํฉ์ ๋ง๊ฒ ์์ )
|
| 13 |
+
ds = load_dataset("gaeunseo/Taskmaster_sample_data")["train"]
|
| 14 |
+
|
| 15 |
+
# conversation_id๋ณ๋ก ๊ทธ๋ฃนํ (๊ทธ๋ฃน์ ๋ฆฌ์คํธ๋ก ์ ์ฅ)
|
| 16 |
+
groups = {}
|
| 17 |
+
for row in ds:
|
| 18 |
+
cid = row["conversation_id"]
|
| 19 |
+
groups.setdefault(cid, []).append(row)
|
| 20 |
+
|
| 21 |
+
# ๋ชจ๋ ํ์ used ์ปฌ๋ผ์ด False์ธ ๊ทธ๋ฃน๋ง ํํฐ๋ง
|
| 22 |
+
valid_groups = [grp for grp in groups.values() if all(not row["used"] for row in grp)]
|
| 23 |
+
|
| 24 |
+
if len(valid_groups) < 2:
|
| 25 |
+
# ์กฐ๊ฑด์ ๋ง์กฑํ๋ ๊ทธ๋ฃน์ด 2๊ฐ ๋ฏธ๋ง์ด๋ฉด ์๋ฌ ๋ฉ์์ง ๋ฐํ
|
| 26 |
+
return "Not enough unused conversations", "Not enough unused conversations"
|
| 27 |
+
|
| 28 |
+
# ์ ํจํ ๊ทธ๋ฃน ์ค์์ ๋๋คํ๊ฒ 2๊ฐ ๊ทธ๋ฃน ์ ํ
|
| 29 |
+
selected_groups = random.sample(valid_groups, 2)
|
| 30 |
+
|
| 31 |
+
# ๊ฐ ๊ทธ๋ฃน์ ๋ชจ๋ utterance๋ฅผ ์ด์ด๋ถ์ฌ ํ๋์ ๋ํ ๋ฌธ์์ด๋ก ์์ฑ
|
| 32 |
+
conv_A = "\n".join(row["utterance"] for row in selected_groups[0])
|
| 33 |
+
conv_B = "\n".join(row["utterance"] for row in selected_groups[1])
|
| 34 |
+
|
| 35 |
+
return conv_A, conv_B
|
| 36 |
+
|
| 37 |
+
# ํ๊ฐ ๋ฒํผ์ ๋๋ ์ ๋ ์
๋ฐ์ดํธํ ์ ์ญ ๋ณ์
|
| 38 |
statement = ""
|
| 39 |
|
| 40 |
+
def update_statement(val):
|
| 41 |
global statement
|
| 42 |
+
statement = val
|
| 43 |
return statement
|
| 44 |
|
| 45 |
with gr.Blocks() as demo:
|
| 46 |
+
# ์๋จ: ๋ ๊ฐ์ ๋ํ์ฐฝ (Conversation A, Conversation B)
|
| 47 |
with gr.Row():
|
| 48 |
+
conversation_A = gr.Textbox(label="Conversation A", lines=10, placeholder="Conversation A will be loaded here...")
|
| 49 |
+
conversation_B = gr.Textbox(label="Conversation B", lines=10, placeholder="Conversation B will be loaded here...")
|
| 50 |
+
|
| 51 |
+
# 'Load Random Conversations' ๋ฒํผ์ ๋๋ฌ ๋ฐ์ดํฐ์
์์ ๋ํ๋ค์ ๋ถ๋ฌ์ต๋๋ค.
|
| 52 |
+
load_btn = gr.Button("Load Random Conversations")
|
| 53 |
+
load_btn.click(fn=load_random_conversations, inputs=[], outputs=[conversation_A, conversation_B])
|
| 54 |
|
| 55 |
+
# ํ๋จ: ํ๊ฐ ๋ฒํผ 4๊ฐ ๋ฐฐ์น
|
| 56 |
with gr.Row():
|
| 57 |
+
btn_both_good = gr.Button("Both good") # โ๋ ๋ค ์ข์โ โ "BG"
|
| 58 |
+
btn_a_better = gr.Button("A is better") # โA๊ฐ ๋ ์ข์โ โ "AG"
|
| 59 |
+
btn_b_better = gr.Button("B is better") # โB๊ฐ ๋ ์ข์โ โ "BG"
|
| 60 |
+
btn_both_bad = gr.Button("Both not good") # โ๋ ๋ค ๋ณ๋ก์โ โ "BB"
|
| 61 |
|
| 62 |
+
# ์ ํ๋ statement๋ฅผ ๋ณด์ฌ์ฃผ๋ ํ
์คํธ๋ฐ์ค (์
๋ฐ์ดํธ ์ ์ญ๋ณ์)
|
| 63 |
statement_output = gr.Textbox(label="Selected Statement", value="", interactive=False)
|
| 64 |
|
| 65 |
+
# ๊ฐ ๋ฒํผ ํด๋ฆญ ์ ํด๋น ๊ฐ์ ์ ์ญ๋ณ์์ ์ ์ฅํ์ฌ ์ถ๋ ฅ
|
| 66 |
btn_both_good.click(fn=lambda: update_statement("BG"), inputs=[], outputs=statement_output)
|
| 67 |
btn_a_better.click(fn=lambda: update_statement("AG"), inputs=[], outputs=statement_output)
|
| 68 |
btn_b_better.click(fn=lambda: update_statement("BG"), inputs=[], outputs=statement_output)
|