Spaces:
Sleeping
Sleeping
위치 변경 및 2번 나오는 내용 수정
Browse files- gradio_interface.py +23 -15
gradio_interface.py
CHANGED
|
@@ -5,39 +5,47 @@ import time
|
|
| 5 |
def create_interface():
|
| 6 |
def handle_user_response(user_input, selected_response, chatbot_history):
|
| 7 |
input_text = user_input if user_input else selected_response
|
| 8 |
-
new_history, offender_response, choices = process_user_input(input_text, chatbot_history)
|
| 9 |
|
| 10 |
if input_text.strip().lower() == "종료":
|
| 11 |
-
|
|
|
|
| 12 |
|
| 13 |
# Add user's input to history
|
| 14 |
-
|
|
|
|
| 15 |
|
| 16 |
-
#
|
| 17 |
-
|
| 18 |
time.sleep(2) # 2-second delay
|
| 19 |
-
|
| 20 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 21 |
|
| 22 |
def handle_case_selection():
|
| 23 |
initial_message = "발표가 망한 건 제 잘못도 좀 있지만, 팀장님은 아무것도 안 하면서 이러는 건 선 넘은거죠"
|
| 24 |
chatbot_history = [(initial_message, None)]
|
|
|
|
|
|
|
| 25 |
offender_response, _ = chatbot_response(initial_message, 'offender', n=1)
|
|
|
|
|
|
|
|
|
|
| 26 |
_, victim_choices = chatbot_response(offender_response, 'victim', n=3)
|
| 27 |
|
| 28 |
-
# Use a yield to first return the initial message, then the offender's response after a delay
|
| 29 |
-
yield chatbot_history, gr.update(choices=victim_choices)
|
| 30 |
-
time.sleep(2) # 2-second delay
|
| 31 |
-
chatbot_history = chatbot_history + [(None, offender_response)]
|
| 32 |
yield chatbot_history, gr.update(choices=victim_choices)
|
| 33 |
|
| 34 |
with gr.Blocks() as demo:
|
|
|
|
| 35 |
screen = gr.Chatbot()
|
| 36 |
-
user_input = gr.Textbox(label="
|
| 37 |
-
response_choices = gr.Dropdown(label="
|
| 38 |
-
submit_button = gr.Button(value="
|
| 39 |
|
| 40 |
-
case_selection_button = gr.Button("발표가 망한 건 제 잘못도 좀 있지만, 팀장님은 아무것도 안 하면서 이러는 건 선 넘은거죠")
|
| 41 |
case_selection_button.click(handle_case_selection, inputs=[], outputs=[screen, response_choices])
|
| 42 |
|
| 43 |
submit_button.click(handle_user_response, inputs=[user_input, response_choices, screen], outputs=[screen, response_choices])
|
|
|
|
| 5 |
def create_interface():
|
| 6 |
def handle_user_response(user_input, selected_response, chatbot_history):
|
| 7 |
input_text = user_input if user_input else selected_response
|
|
|
|
| 8 |
|
| 9 |
if input_text.strip().lower() == "종료":
|
| 10 |
+
chatbot_history.append((input_text, "실험에 참가해 주셔서 감사합니다. 후속 지시를 따라주세요"))
|
| 11 |
+
return chatbot_history, gr.update(choices=[], interactive=False)
|
| 12 |
|
| 13 |
# Add user's input to history
|
| 14 |
+
chatbot_history.append((input_text, None))
|
| 15 |
+
yield chatbot_history, gr.update(choices=[]) # Immediately show user input
|
| 16 |
|
| 17 |
+
# Get offender's response
|
| 18 |
+
offender_response, _ = chatbot_response(input_text, 'offender', n=1)
|
| 19 |
time.sleep(2) # 2-second delay
|
| 20 |
+
|
| 21 |
+
# Add offender's response to history
|
| 22 |
+
chatbot_history.append((None, offender_response))
|
| 23 |
+
|
| 24 |
+
# Generate victim choices for the next turn
|
| 25 |
+
_, victim_choices = chatbot_response(offender_response, 'victim', n=3)
|
| 26 |
+
|
| 27 |
+
yield chatbot_history, gr.update(choices=victim_choices)
|
| 28 |
|
| 29 |
def handle_case_selection():
|
| 30 |
initial_message = "발표가 망한 건 제 잘못도 좀 있지만, 팀장님은 아무것도 안 하면서 이러는 건 선 넘은거죠"
|
| 31 |
chatbot_history = [(initial_message, None)]
|
| 32 |
+
yield chatbot_history, gr.update(choices=[])
|
| 33 |
+
|
| 34 |
offender_response, _ = chatbot_response(initial_message, 'offender', n=1)
|
| 35 |
+
time.sleep(2) # 2-second delay
|
| 36 |
+
|
| 37 |
+
chatbot_history.append((None, offender_response))
|
| 38 |
_, victim_choices = chatbot_response(offender_response, 'victim', n=3)
|
| 39 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 40 |
yield chatbot_history, gr.update(choices=victim_choices)
|
| 41 |
|
| 42 |
with gr.Blocks() as demo:
|
| 43 |
+
case_selection_button = gr.Button("발표가 망한 건 제 잘못도 좀 있지만, 팀장님은 아무것도 안 하면서 이러는 건 선 넘은거죠")
|
| 44 |
screen = gr.Chatbot()
|
| 45 |
+
user_input = gr.Textbox(label="이곳에 대답을 입력하세요")
|
| 46 |
+
response_choices = gr.Dropdown(label="또는 대답을 선택해 주세요", choices=[], interactive=True)
|
| 47 |
+
submit_button = gr.Button(value="제출")
|
| 48 |
|
|
|
|
| 49 |
case_selection_button.click(handle_case_selection, inputs=[], outputs=[screen, response_choices])
|
| 50 |
|
| 51 |
submit_button.click(handle_user_response, inputs=[user_input, response_choices, screen], outputs=[screen, response_choices])
|