gaeunseo commited on
Commit
b63078f
ยท
verified ยท
1 Parent(s): 0d9db4d

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +51 -13
app.py CHANGED
@@ -1,30 +1,68 @@
1
  import gradio as gr
 
 
2
 
3
- # ์ „์—ญ ๋ณ€์ˆ˜ ์„ ์–ธ
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
4
  statement = ""
5
 
6
- def update_statement(value):
7
  global statement
8
- statement = value
9
  return statement
10
 
11
  with gr.Blocks() as demo:
12
- # ๋‘ ๊ฐœ์˜ ๋Œ€ํ™”์ฐฝ์„ ์ขŒ์šฐ์— ๋ฐฐ์น˜ํ•ฉ๋‹ˆ๋‹ค.
13
  with gr.Row():
14
- conversation_A = gr.Textbox(label="Conversation A", placeholder="Enter conversation A here...", lines=10)
15
- conversation_B = gr.Textbox(label="Conversation B", placeholder="Enter conversation B here...", lines=10)
 
 
 
 
16
 
17
- # 4๊ฐœ์˜ ๋ฒ„ํŠผ์„ ํ•œ ํ–‰์— ๋ฐฐ์น˜ํ•ฉ๋‹ˆ๋‹ค.
18
  with gr.Row():
19
- btn_both_good = gr.Button("Both good") # "๋‘˜ ๋‹ค ์ข‹์Œ" โ†’ "BG"
20
- btn_a_better = gr.Button("A is better") # "A๊ฐ€ ๋” ์ข‹์Œ" โ†’ "AG"
21
- btn_b_better = gr.Button("B is better") # "B๊ฐ€ ๋” ์ข‹์Œ" โ†’ "BG"
22
- btn_both_bad = gr.Button("Both not good") # "๋‘˜ ๋‹ค ๋ณ„๋กœ์ž„" โ†’ "BB"
23
 
24
- # ์„ ํƒ๋œ statement ๊ฐ’์„ ๋ณด์—ฌ์ฃผ๊ธฐ ์œ„ํ•œ ์ถœ๋ ฅ ํ…์ŠคํŠธ๋ฐ•์Šค (์˜ต์…˜)
25
  statement_output = gr.Textbox(label="Selected Statement", value="", interactive=False)
26
 
27
- # ๊ฐ ๋ฒ„ํŠผ ํด๋ฆญ ์‹œ update_statement ํ•จ์ˆ˜๋ฅผ ํ˜ธ์ถœํ•˜์—ฌ statement ๊ฐ’์„ ์—…๋ฐ์ดํŠธํ•ฉ๋‹ˆ๋‹ค.
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)