File size: 16,149 Bytes
b2a5882
 
 
 
 
 
 
3703b6a
b2a5882
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1ee0c0f
3703b6a
b2a5882
 
 
af3a9ea
 
cfd32b7
af3a9ea
 
 
 
3703b6a
 
 
 
 
 
af3a9ea
 
e73f228
af3a9ea
b2a5882
af3a9ea
b2a5882
af3a9ea
 
 
 
 
cfd32b7
 
af3a9ea
 
cfd32b7
af3a9ea
b2a5882
cfd32b7
af3a9ea
 
 
 
3703b6a
 
af3a9ea
 
 
 
 
 
 
b2a5882
af3a9ea
 
 
 
3703b6a
 
af3a9ea
 
 
 
 
 
 
b2a5882
 
 
 
 
 
 
 
 
 
 
 
 
 
 
b76fa9b
b2a5882
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
3703b6a
 
 
 
 
 
 
 
 
 
b2a5882
 
 
 
 
 
 
 
 
 
 
 
 
 
f2ae91d
 
 
 
 
 
3703b6a
f2ae91d
 
 
 
3703b6a
f2ae91d
3703b6a
 
 
 
 
 
 
 
f2ae91d
 
 
 
30db1ac
f2ae91d
3703b6a
 
f2ae91d
30db1ac
dc9850f
3703b6a
30db1ac
3703b6a
 
 
962cda8
3703b6a
 
b69629d
d0e7aed
3703b6a
 
 
962cda8
 
f2ae91d
b76fa9b
 
b2a5882
 
adf8468
b2a5882
3703b6a
 
 
b2a5882
 
 
 
 
b76fa9b
 
af3a9ea
3703b6a
 
af3a9ea
 
 
 
b2a5882
 
 
b76fa9b
 
af3a9ea
3703b6a
 
af3a9ea
 
 
 
 
 
 
b2a5882
 
 
 
 
 
 
1ee0c0f
b2a5882
 
 
3703b6a
 
 
 
 
 
 
 
 
 
 
 
b2a5882
 
af3a9ea
cfd32b7
b2a5882
3703b6a
 
 
b2a5882
 
3703b6a
 
 
b2a5882
 
af3a9ea
 
 
3703b6a
 
 
af3a9ea
 
 
3703b6a
 
 
af3a9ea
1c18bb0
 
 
 
 
 
b2a5882
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
import os
import random
import datetime
import gradio as gr
from typing import Tuple, Optional

from utils.common import upload_to_github
from utils.postprocess import make_dialog_dict, dialog_translate



def sample_pair(dialog_dict: dict) -> Tuple[str, str, str, str]:
    """
    Sample two different models and one dialog from each.

    Args:
        dialog_dict (dict): Dictionary of dialogs per model.

    Returns:
        Tuple[str, str, str, str]: (model1 name, dialog1, model2 name, dialog2)
    """
    model1, model2 = random.sample(list(dialog_dict.keys()), 2)
    dialog1 = random.choice(dialog_dict[model1])
    dialog2 = random.choice(dialog_dict[model2])
    return model1, dialog1, model2, dialog2



def new_comparison(dialog_dict: dict) -> Tuple[str, str, str, str, gr.Row, gr.Row, gr.Row]:
    """
    Generate a new comparison pair and make the arena row visible.

    Args:
        dialog_dict (dict): Dictionary of dialogs per model.

    Returns:
        Tuple[str, str, str, str, gr.Row]: 
            (model1 name, dialog1, model2 name, dialog2, 
            arena row visibility update, submit button visibility update, new comparison button visibility update)
    """
    m1, d1, m2, d2 = sample_pair(dialog_dict)
    result_path = set_result_path()
    return m1, d1, m2, d2, d1, d2, gr.update(visible=True), gr.update(visible=True), gr.update(visible=False), result_path



def update_scores(score_a: Optional[int],
                  score_b: Optional[int],
                  win: Optional[int],
                  m1: str,
                  m2: str,
                  d1: str,
                  d2: str,
                  en1: str,
                  kr1: str,
                  en2: str,
                  kr2: str,
                  l_state1: str,
                  l_state2: str,
                  dialog_dict: dict,
                  score_state: dict,
                  is_dev: bool,
                  result_file_path: str):
    """
    Update score_state. If both scores exist, record and sample new dialog pair.
    """
    scores = score_state.copy()
    if score_a is not None:
        scores["A"] = score_a
    if score_b is not None:
        scores["B"] = score_b
    if win is not None:
        scores["win"] = win

    # Save the data
    if "A" in scores and "B" in scores and "win" in scores:
        # if not is_dev:
        with open(result_file_path, "a") as f:
            f.write(f"{scores['win']}\t{scores['A']}\t{scores['B']}\t{m1}\t{m2}\n")

        new_m1, new_d1, new_m2, new_d2 = sample_pair(dialog_dict)
        return (
            new_m1, new_d1, new_m2, new_d2, 
            new_d1, "", new_d2, "",
            "en", "en",
            gr.update(visible=True),    # arena
            gr.update(visible=False),   # rate A button
            gr.update(visible=False),   # rate B button
            gr.update(visible=True),    # vote A button
            gr.update(visible=True),    # vote B button
            "โœ… Both scores recorded!", {}
        )
    
    # Waiting the other score
    else:
        return (
            m1, d1, m2, d2, 
            en1, kr1, en2, kr2,
            l_state1, l_state2,
            gr.update(visible=True),    # arena
            gr.update(visible=True),    # rate A button
            gr.update(visible=True),    # rate B button
            gr.update(visible=False),   # vote A button
            gr.update(visible=False),   # vote B button
            "๐Ÿ• Waiting for the other score...", scores
        )



def save_data(path: str) -> str:
    """
    Save the human evaluation data.

    Args:
        path (str): Path to save the results.
    
    Returns:
        str: Message of the result submission.
    """
    try:
        upload_to_github(path, open(path).read())
        return "โœ… Results are successfully submitted!"
    except Exception as e:
        return f"โŒ Upload failed: {e}"



def set_result_path() -> str:
    """
    Set the result saving path.

    Returns:
        str: Path to save the results.
    """
    timestamp = datetime.datetime.now().strftime("%Y-%m-%d_%H-%M-%S")
    unique_id = os.urandom(4).hex()
    result_file = os.path.join("simulation_arena", f"result_{timestamp}_{unique_id}.txt")
    os.makedirs(os.path.dirname(result_file), exist_ok=True)
    return result_file



def toggle_language(en_dialog, kr_dialog, lang):
    if lang == "en":
        if not kr_dialog:
            kr_dialog = dialog_translate(en_dialog)
        return kr_dialog, "kr", kr_dialog
    else:
        return en_dialog, "en", kr_dialog



css = """
.dialog-box { 
    height: 600px;        
    overflow-y: auto;     
}
"""



# Arena GUI
is_dev = False
dialog_dict = make_dialog_dict()
with gr.Blocks(title="1:1 Outpatient Model Simulation Arena", css=css) as demo:
    gr.Markdown("# ๐Ÿค– Model Arena Evaluation")
    gr.Markdown("## Compare two model simulations and choose the better one!")
    
    # English version
    gr.Markdown("### Situation")
    gr.Markdown("* This scenario assumes that the patient called the hospital's administrative office for an outpatient inquiry.")
    gr.Markdown("* Depending on the patient, some may already know their condition because they have diagnostic records from a smaller clinic they previously visited, while others may only know their symptoms since itโ€™s their first visit to the hospital.")
    gr.Markdown("<br>")
    
    gr.Markdown("### Procedure and Explanation")
    gr.Markdown("* First step: Arena! Please choose which of the two simulations you think is better.")
    gr.Markdown("* Second step: After making your choice, a scoring panel will appear. Please rate each simulation on a scale of 1 to 5.")
    gr.Markdown("* Regardless of which one you selected in step 1, please rate each simulation indepentently based on the criteria below.")
    gr.Markdown("* Thereโ€™s no required number! Just do as many as you feel like, and hit the submit button before you leave. You can always come back and do a few more later if youโ€™re bored!.")
    gr.Markdown("<br>")

    gr.Markdown("### Evaluation Criteria")
    gr.Markdown("If the simulation satisfies all four criteria below, please give it 5 points. Deduct 1 point for each criterion that is not met. If none of the criteria are satisfied, assign a score of 1 point.")
    gr.Markdown("* **Patient**: The patient expresses symptoms naturally without using excessive medical jargon.")
    gr.Markdown("* **Staff**  : The staff does not diagnose like a doctor or provide treatment based on previous medical records, but instead focuses on asking appropriate questions within the scope of symptom checking, registration, and guidance. The tone of language is empathetic and polite.")
    gr.Markdown("* **Flow**   : The conversation proceeds naturally in the following order โ€” greeting โ†’ patient information collection โ†’ symptom collection โ†’ department assignment โ€” and each stage achieves its intended purpose.")
    gr.Markdown("* **Overall**: The conversation overall feels realistic, resembling an actual hospital reception scenario (sentences are concise and the closing expressions sound natural).")

    # Korean version
    gr.Markdown("---")
    gr.Markdown("### ์ƒํ™ฉ")
    gr.Markdown("* ํ™˜์ž๊ฐ€ ๋ณ‘์› ์›๋ฌด๊ณผ์— ์™ธ๋ž˜ ์ง„๋ฃŒ ๋ฌธ์˜๋ฅผ ์œ„ํ•ด ์ „ํ™”ํ•œ ์ƒํ™ฉ์„ ๊ฐ€์ •ํ•ฉ๋‹ˆ๋‹ค.")
    gr.Markdown("* ํ™˜์ž์— ๋”ฐ๋ผ ์ด์ „ ์ž‘์€ ๋ณ‘์›์—์„œ ๋ฐ›์€ ์ง„๋‹จ ๊ธฐ๋ก์„ ๊ฐ€์ง€๊ณ  ์žˆ์–ด ์ž์‹ ์˜ ์งˆ๋ณ‘์„ ์ด๋ฏธ ์•Œ๊ณ  ์žˆ๋Š” ๊ฒฝ์šฐ๋„ ์žˆ๊ณ , ๋ณ‘์›์„ ์ฒ˜์Œ ๋ฐฉ๋ฌธํ•ด ์ฆ์ƒ๋งŒ ์•Œ๊ณ  ์žˆ๋Š” ๊ฒฝ์šฐ๋„ ์žˆ์Šต๋‹ˆ๋‹ค.")
    gr.Markdown("<br>")

    gr.Markdown("### ๊ณผ์ • ๋ฐ ์„ค๋ช…")
    gr.Markdown("* **First Step: Arena!** ๋‘ ๊ฐœ์˜ ์‹œ๋ฎฌ๋ ˆ์ด์…˜ ์ค‘์—์„œ, ์‹ค์ œ ๋ณ‘์› ์›๋ฌด๊ณผ ์ง์›๊ณผ์˜ ๋Œ€ํ™”๊ฐ€ **๋” ํ˜„์‹ค์  ๊ฒƒ**์„ ์„ ํƒํ•ด์ฃผ์„ธ์š”.")
    gr.Markdown("* **Second step: Rate!** ์„ ํƒ์ด ๋๋‚˜๋ฉด ์ ์ˆ˜ํŒ์ด ๋œน๋‹ˆ๋‹ค. ๊ฐ๊ฐ์˜ ์‹œ๋ฎฌ๋ ˆ์ด์…˜์— 1~5์  ์‚ฌ์ด ์ ์ˆ˜๋ฅผ ๋งค๊ฒจ์ฃผ์„ธ์š”. ํ‰๊ฐ€ ๊ธฐ์ค€์€ ์•„๋ž˜ ์„น์…˜์„ ์ฐธ๊ณ  ํ•ด์ฃผ์„ธ์š”!")
    gr.Markdown("* 1๋ฒˆ์—์„œ ์–ด๋–ค ๊ฑธ ๊ณจ๋ž๋Š”์ง€์™€ ์ƒ๊ด€์—†์ด, ๋‘ ์‹œ๋ฎฌ๋ ˆ์ด์…˜์„ ๋ณด๊ณ  ์•„๋ž˜ ํ‰๊ฐ€ ๊ธฐ์ค€์— ๋งž์ถฐ์„œ ์ ์ˆ˜๋ฅผ ๋งค๊ฒจ์ฃผ์„ธ์š”.")
    gr.Markdown("* ๊ฐœ์ˆ˜๋Š” ์ƒ๊ด€ ์—†์Šต๋‹ˆ๋‹ค(๊ทธ๋ž˜๋„ ์ตœ์†Œ 10๊ฐœ์ •๋„๋งŒ ๋ถ€ํƒ๋“œ๋ ค์šฉ).. ๊ทธ๋ƒฅ ์ ๋‹นํžˆ ํ•˜์‹ค๋งŒํผ ํ•˜์‹œ๋‹ค๊ฐ€ <i>**๋‹คํ•˜๊ณ  ๋‚˜๊ฐ€์‹œ๊ธฐ ์ „์— ๊ผญ submit ๋ฒ„ํŠผ๋งŒ ๋ˆŒ๋Ÿฌ์ฃผ์‹œ๋ฉด ๋ผ์š”!**</i> ๊ทธ๋ฆฌ๊ณ  ๋‚˜์ค‘์— ์‹ฌ์‹ฌํ•˜์‹œ๋ฉด ์ซŒ์ซŒ๋”ฐ๋ฆฌ ํ•ด์ฃผ์…”๋„ ์ข‹์•„์—ฌ..")
    gr.Markdown("<br>")
    
    gr.Markdown("### ์ ์ˆ˜ ํ‰๊ฐ€ ๊ธฐ์ค€")
    gr.Markdown("**์•„๋ž˜์˜ 4๊ฐ€์ง€ ๊ธฐ์ค€์„ ๋ชจ๋‘ ๋งŒ์กฑํ•˜๋ฉด 5์ , ๊ธฐ์ค€์„ ์ถฉ์กฑํ•˜์ง€ ๋ชปํ•œ ํ•ญ๋ชฉ์ด ํ•˜๋‚˜ ์žˆ์„ ๋•Œ๋งˆ๋‹ค 1์ ์”ฉ ๊ฐ์ ํ•ด ์ฃผ์„ธ์š”. ๋ชจ๋“  ๊ธฐ์ค€์„ ๋งŒ์กฑํ•˜์ง€ ๋ชปํ•œ ๊ฒฝ์šฐ๋Š” 1์ ์„ ๋ถ€์—ฌํ•˜๋ฉด ๋ฉ๋‹ˆ๋‹ค.**")
    gr.Markdown("* **Patient**: ์ฆ์ƒ ํ˜ธ์†Œ๊ฐ€ ์ž์—ฐ์Šค๋Ÿฝ๊ณ , ๊ณผ๋„ํ•œ ์˜ํ•™ ์ „๋ฌธ ์šฉ์–ด๊ฐ€ ์‚ฌ์šฉ๋˜์ง€ ์•Š์•˜๋Š”์ง€.")
    gr.Markdown("* **Staff**  : ์˜์‚ฌ์ฒ˜๋Ÿผ ์ง„๋‹จํ•˜๊ฑฐ๋‚˜ ํ˜น์ธ ์ด์ „ ์ง„๋‹จ ๊ธฐ๋ก์„ ๋ฐ”ํƒ•์œผ๋กœ ์น˜๋ฃŒ๋ฅผ ํ•˜์ง€ ์•Š๊ณ , ์ฆ์ƒ ํ™•์ธยท์ ‘์ˆ˜ยท์•ˆ๋‚ด ๋ฒ”์œ„ ๋‚ด์—์„œ ์งˆ์˜๋ฅผ ์ž˜ ์ˆ˜ํ–‰ํ–ˆ๋Š”์ง€, ์–ธ์–ด ํ†ค์ด ๊ณต๊ฐ ์žˆ๊ณ  ์นœ์ ˆํ–ˆ๋Š”์ง€.")
    gr.Markdown("* **Flow**   : ์ธ์‚ฌ โ†’ ํ™˜์ž ์ •๋ณด ์ˆ˜์ง‘ โ†’ ์ฆ์ƒ ์ˆ˜์ง‘ ๋ฐ ์ด์ „ ์ง„๋‹จ ๊ธฐ๋ก ์—ฌ๋ถ€ โ†’ ์ง„๋ฃŒ๊ณผ ๋ฐฐ์ • ์ˆœ์„œ๋กœ ์ž์—ฐ์Šค๋Ÿฝ๊ฒŒ ์ง„ํ–‰๋˜์—ˆ๊ณ , ๊ฐ ๋‹จ๊ณ„์˜ ๋ชฉ์ ์ด ๋ชจ๋‘ ๋‹ฌ์„ฑ๋˜์—ˆ๋Š”์ง€.")
    gr.Markdown("* **Overall**: ์ „์ฒด์ ์œผ๋กœ ์‹ค์ œ ๋ณ‘์› ์ ‘์ˆ˜ ์ƒํ™ฉ์ฒ˜๋Ÿผ ๋А๊ปด์ง€๋Š”์ง€(๋ฌธ์žฅ ํ‘œํ˜„์ด ๊ฐ„๊ฒฐํ•˜๊ณ , ๋Œ€ํ™”์˜ ๋๋งบ์Œ์ด ์ž์—ฐ์Šค๋Ÿฌ์šด์ง€ ๋“ฑ).") 
    gr.Markdown("<br>")

    gr.Markdown("### ๊ธฐํƒ€")
    gr.Markdown("ํŽธ์˜๋ฅผ ์œ„ํ•ด LLM ๋ฒˆ์—ญ ๊ธฐ๋Šฅ์„ ์ถ”๊ฐ€ํ–ˆ๋Š”๋ฐ(Change language), ๋ฒˆ์—ญํ•˜๋Š” ๋ฐ ์‹œ๊ฐ„์ด ๊ฑธ๋ฆด ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. GPT-5 Nano ๋ชจ๋ธ์„ ์‚ฌ์šฉํ•˜๊ณ  ์žˆ์–ด์„œ ๋ถ€์ •ํ™•ํ•  ์ˆ˜ ์žˆ์œผ๋‹ˆ ๋ฒˆ์—ญ๋ณธ์€ ์ฐธ๊ณ ์šฉ์œผ๋กœ๋งŒ ํ•ด์ฃผ์‹œ๋ฉด ๊ฐ์‚ฌํ•˜๊ฒ ์Šต๋‹ˆ๋‹ค.")
    gr.Markdown("* ๊ฐ€๋ น 'I am sorry to hear that'์ด๋ผ๋Š” ๋ฌธ์žฅ์„ '๋“ฃ๊ธฐ์— ์ฃ„์†กํ•ฉ๋‹ˆ๋‹ค' ์ด๋ ‡๊ฒŒ ์ด์ƒํ•˜๊ฒŒ ํ•ด์„๋˜๋Š” ๊ฒฝ์šฐ๊ฐ€ ์žˆ์„ ์ˆ˜ ์žˆ๋Š”๋ฐ, ๋ฒˆ์—ญํ•ด์„œ ์ฝ๋‹ค๊ฐ€ ์ด์ƒํ•œ ๋ถ€๋ถ„์€ ์˜์–ด๋กœ ์ž ๊น ๋ฐ”๊ฟ”์„œ ์›๋ฌธ์„ ๋ด์ฃผ์‹œ๋ฉด ๋ฉ๋‹ˆ๋‹ค. ์ด๋Ÿฌํ•œ ๊ฒฝ์šฐ ๋ฒˆ์—ญ์˜ ์˜ค๋ฅ˜์ด๋ฏ€๋กœ ์ด ๋ถ€๋ถ„์€ ๊ฐ์•ˆํ•˜๊ณ  ์ ์ˆ˜๋ฅผ ๋งค๊ฒจ์ฃผ์‹œ๊ธฐ ๋ฐ”๋ž๋‹ˆ๋‹ค.")

    gr.Markdown("<br><br>")
    gr.Markdown("---")

    # New comparison button
    btn_new = gr.Button("๐ŸฅŠ Start Arena!! ๐ŸฅŠ") 
    state_dict = gr.State(dialog_dict)
    en1_dialog_box, en2_dialog_box = gr.State(""), gr.State("")
    kr1_dialog_box, kr2_dialog_box = gr.State(""), gr.State("")
    lang_state1, lang_state2 = gr.State("en"), gr.State("en")

    # Showing two model simulations side by side
    with gr.Row(visible=False) as arena_row:
        with gr.Column():
            model1_name = gr.Textbox(label="Model A", interactive=False, visible=is_dev)
            if not is_dev:
                msg = gr.Markdown("## Anonymous Model A")
            dialog1_box = gr.Markdown(label="Simulation A", elem_classes="dialog-box")
            with gr.Row(visible=True) as translate_A:
                tr1 = gr.Button("Change language")
            with gr.Row(visible=True) as vote1_row:
                vote1 = gr.Button("๐Ÿ‘ Choose A")
            with gr.Row(visible=False) as scoreA_row:
                scoreA_buttons = [gr.Button(str(i)) for i in range(1, 6)]

        with gr.Column():
            model2_name = gr.Textbox(label="Model B", interactive=False, visible=is_dev)
            if not is_dev:
                msg = gr.Markdown("## Anonymous Model B")
            dialog2_box = gr.Markdown(label="Simulation B", elem_classes="dialog-box")
            with gr.Row(visible=True) as translate_B:
                tr2 = gr.Button("Change language")
            with gr.Row(visible=True) as vote2_row:
                vote2 = gr.Button("๐Ÿ‘ Choose B")
            with gr.Row(visible=False) as scoreB_row:
                scoreB_buttons = [gr.Button(str(i)) for i in range(1, 6)]
    
    # Showing the status
    msg = gr.Markdown("")

    # Submit button
    with gr.Row(visible=False) as submit_row:
        submit_btn = gr.Button("๐Ÿ“ค Submit All Results")
        submit_msg = gr.Markdown("")
        
    # Button actions
    result_save_state = gr.State(None)
    btn_new.click(
        fn=new_comparison,
        inputs=[state_dict],
        outputs=[model1_name, dialog1_box, model2_name, dialog2_box, en1_dialog_box, en2_dialog_box, arena_row, submit_row, btn_new, result_save_state],
    )
    tr1.click(
        fn=toggle_language,
        inputs=[en1_dialog_box, kr1_dialog_box, lang_state1],
        outputs=[dialog1_box, lang_state1, kr1_dialog_box]
    )

    tr2.click(
        fn=toggle_language,
        inputs=[en2_dialog_box, kr2_dialog_box, lang_state2],
        outputs=[dialog2_box, lang_state2, kr2_dialog_box]
    )

    # First step: Arena, Choose the only one!
    score_state = gr.State({})
    vote1.click(
        fn=lambda m1, m2, d1, d2, en1, kr1, en2, kr2, l_state1, l_state2, scores, result_file_path: update_scores(None, None, 'A', m1, m2, d1, d2, en1, kr1, en2, kr2, l_state1, l_state2, dialog_dict, scores, is_dev, result_file_path),
        inputs=[model1_name, model2_name, dialog1_box, dialog2_box, en1_dialog_box, kr1_dialog_box, en2_dialog_box, kr2_dialog_box, lang_state1, lang_state2, score_state, result_save_state],
        outputs=[model1_name, dialog1_box, model2_name, dialog2_box, en1_dialog_box, kr1_dialog_box, en2_dialog_box, kr2_dialog_box, lang_state1, lang_state2, arena_row, scoreA_row, scoreB_row, vote1_row, vote2_row, msg, score_state],
    )
    vote2.click(
        fn=lambda m1, m2, d1, d2, en1, kr1, en2, kr2, l_state1, l_state2, scores, result_file_path: update_scores(None, None, 'B', m1, m2, d1, d2, en1, kr1, en2, kr2, l_state1, l_state2, dialog_dict, scores, is_dev, result_file_path),
        inputs=[model1_name, model2_name, dialog1_box, dialog2_box, en1_dialog_box, kr1_dialog_box, en2_dialog_box, kr2_dialog_box, lang_state1, lang_state2, score_state, result_save_state],
        outputs=[model1_name, dialog1_box, model2_name, dialog2_box, en1_dialog_box, kr1_dialog_box, en2_dialog_box, kr2_dialog_box, lang_state1, lang_state2, arena_row, scoreA_row, scoreB_row, vote1_row, vote2_row, msg, score_state],
    )

    # Second step: Rate, Rate the each score!
    for btn in scoreA_buttons:
        btn.click(
            fn=lambda score, m1, m2, d1, d2, en1, kr1, en2, kr2, l_state1, l_state2, scores, result_file_path: update_scores(int(score), None, None, m1, m2, d1, d2, en1, kr1, en2, kr2, l_state1, l_state2, dialog_dict, scores, is_dev, result_file_path),
            inputs=[gr.State(btn.value), model1_name, model2_name, dialog1_box, dialog2_box, en1_dialog_box, kr1_dialog_box, en2_dialog_box, kr2_dialog_box, lang_state1, lang_state2, score_state, result_save_state],
            outputs=[model1_name, dialog1_box, model2_name, dialog2_box, en1_dialog_box, kr1_dialog_box, en2_dialog_box, kr2_dialog_box, lang_state1, lang_state2, arena_row, scoreA_row, scoreB_row, vote1_row, vote2_row, msg, score_state],
        )
    for btn in scoreB_buttons:
        btn.click(
            fn=lambda score, m1, m2, d1, d2, en1, kr1, en2, kr2, l_state1, l_state2, scores, result_file_path: update_scores(None, int(score), None, m1, m2, d1, d2, en1, kr1, en2, kr2, l_state1, l_state2, dialog_dict, scores, is_dev, result_file_path),
            inputs=[gr.State(btn.value), model1_name, model2_name, dialog1_box, dialog2_box, en1_dialog_box, kr1_dialog_box, en2_dialog_box, kr2_dialog_box, lang_state1, lang_state2, score_state, result_save_state],
            outputs=[model1_name, dialog1_box, model2_name, dialog2_box, en1_dialog_box, kr1_dialog_box, en2_dialog_box, kr2_dialog_box, lang_state1, lang_state2, arena_row, scoreA_row, scoreB_row, vote1_row, vote2_row, msg, score_state],
        )
    
    submit_btn.click(
        fn=save_data,
        inputs=[result_save_state],
        outputs=[submit_msg],
    )

# Launch the app
if is_dev:
    demo.launch(server_port=7860)
else:
    demo.launch()