Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,68 +1,66 @@
|
|
| 1 |
import gradio as gr
|
|
|
|
| 2 |
from datasets import load_dataset
|
| 3 |
import random
|
| 4 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 5 |
def load_random_conversations():
|
| 6 |
-
|
| 7 |
-
|
| 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 |
-
#
|
| 16 |
-
|
| 17 |
-
for row in ds:
|
| 18 |
-
cid = row["conversation_id"]
|
| 19 |
-
groups.setdefault(cid, []).append(row)
|
| 20 |
|
| 21 |
-
|
| 22 |
-
|
| 23 |
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
return "Not enough unused conversations", "Not enough unused conversations"
|
| 27 |
|
| 28 |
-
#
|
| 29 |
-
|
|
|
|
| 30 |
|
| 31 |
-
#
|
| 32 |
-
|
| 33 |
-
|
| 34 |
|
| 35 |
-
return
|
| 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 |
-
#
|
| 47 |
with gr.Row():
|
| 48 |
-
conversation_A = gr.Textbox(label="Conversation A",
|
| 49 |
-
conversation_B = gr.Textbox(label="Conversation B",
|
| 50 |
|
| 51 |
-
#
|
| 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") #
|
| 58 |
-
btn_a_better
|
| 59 |
-
btn_b_better
|
| 60 |
-
btn_both_bad
|
| 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)
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
+
import pandas as pd
|
| 3 |
from datasets import load_dataset
|
| 4 |
import random
|
| 5 |
|
| 6 |
+
# 데이터셋 불러오기 및 전처리
|
| 7 |
+
dataset = load_dataset("gaeunseo/Taskmaster_sample_data", split='train')
|
| 8 |
+
df = dataset.to_pandas()
|
| 9 |
+
|
| 10 |
+
# 전역 변수 선언
|
| 11 |
+
statement = ""
|
| 12 |
+
|
| 13 |
+
def update_statement(value):
|
| 14 |
+
global statement
|
| 15 |
+
statement = value
|
| 16 |
+
return statement
|
| 17 |
+
|
| 18 |
def load_random_conversations():
|
| 19 |
+
# 'used'가 False인 그룹 필터링
|
| 20 |
+
unused_groups = df[df['used'] == False].groupby('conversation_id')
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 21 |
|
| 22 |
+
# 조건에 맞는 conversation_id 리스트
|
| 23 |
+
valid_conversation_ids = [cid for cid, group in unused_groups if len(group) >= 2]
|
|
|
|
|
|
|
|
|
|
| 24 |
|
| 25 |
+
if not valid_conversation_ids:
|
| 26 |
+
return "No available conversation", "No available conversation"
|
| 27 |
|
| 28 |
+
# 랜덤으로 하나의 conversation_id 선택
|
| 29 |
+
selected_id = random.choice(valid_conversation_ids)
|
|
|
|
| 30 |
|
| 31 |
+
# 선택된 그룹에서 두 개의 행을 랜덤 선택
|
| 32 |
+
selected_group = df[df['conversation_id'] == selected_id]
|
| 33 |
+
selected_conversations = selected_group.sample(2)
|
| 34 |
|
| 35 |
+
# 선택된 대화 텍스트 반환
|
| 36 |
+
conversation_A = selected_conversations.iloc[0]['text']
|
| 37 |
+
conversation_B = selected_conversations.iloc[1]['text']
|
| 38 |
|
| 39 |
+
return conversation_A, conversation_B
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 40 |
|
| 41 |
with gr.Blocks() as demo:
|
| 42 |
+
# 두 개의 대화창을 좌우에 배치합니다.
|
| 43 |
with gr.Row():
|
| 44 |
+
conversation_A = gr.Textbox(label="Conversation A", placeholder="Enter conversation A here...", lines=10)
|
| 45 |
+
conversation_B = gr.Textbox(label="Conversation B", placeholder="Enter conversation B here...", lines=10)
|
| 46 |
|
| 47 |
+
# 4개의 버튼을 한 행에 배치합니다.
|
|
|
|
|
|
|
|
|
|
|
|
|
| 48 |
with gr.Row():
|
| 49 |
+
btn_both_good = gr.Button("Both good") # "둘 다 좋음" → "BG"
|
| 50 |
+
btn_a_better = gr.Button("A is better") # "A가 더 좋음" → "AG"
|
| 51 |
+
btn_b_better = gr.Button("B is better") # "B가 더 좋음" → "BG"
|
| 52 |
+
btn_both_bad = gr.Button("Both not good") # "둘 다 별로임" → "BB"
|
| 53 |
|
| 54 |
+
# 선택된 statement 값을 보여주기 위한 출력 텍스트박스 (옵션)
|
| 55 |
statement_output = gr.Textbox(label="Selected Statement", value="", interactive=False)
|
| 56 |
|
| 57 |
+
# 대화를 불러오는 버튼
|
| 58 |
+
load_conversations_btn = gr.Button("Load Random Conversations")
|
| 59 |
+
|
| 60 |
+
# 대화 불러오기 버튼 클릭 시 대화 상자 업데이트
|
| 61 |
+
load_conversations_btn.click(fn=load_random_conversations, inputs=[], outputs=[conversation_A, conversation_B])
|
| 62 |
+
|
| 63 |
+
# 각 버튼 클릭 시 update_statement 함수를 호출하여 statement 값을 업데이트합니다.
|
| 64 |
btn_both_good.click(fn=lambda: update_statement("BG"), inputs=[], outputs=statement_output)
|
| 65 |
btn_a_better.click(fn=lambda: update_statement("AG"), inputs=[], outputs=statement_output)
|
| 66 |
btn_b_better.click(fn=lambda: update_statement("BG"), inputs=[], outputs=statement_output)
|