songhune commited on
Commit
7cc53f7
·
1 Parent(s): e50fdaa

버그 픽싱 중

Browse files
Files changed (1) hide show
  1. gradio_interface.py +14 -8
gradio_interface.py CHANGED
@@ -1,5 +1,6 @@
1
  import gradio as gr
2
- from chatbot_utils import process_user_input, chatbot_response, delayed_offender_response
 
3
 
4
  def create_interface():
5
  def handle_user_response(user_input, selected_response, chatbot_history):
@@ -9,10 +10,14 @@ def create_interface():
9
  if input_text.strip().lower() == "종료":
10
  return new_history, gr.update(choices=[], interactive=False)
11
 
12
- # Schedule the offender's response to be added after a delay
13
- gr.Result(delayed_offender_response, [new_history, offender_response], _js="() => setTimeout(() => _js_return_(), 2000)")
14
 
15
- return new_history, gr.update(choices=choices)
 
 
 
 
16
 
17
  def handle_case_selection():
18
  initial_message = "발표가 망한 건 제 잘못도 좀 있지만, 팀장님은 아무것도 안 하면서 이러는 건 선 넘은거죠"
@@ -20,10 +25,11 @@ def create_interface():
20
  offender_response, _ = chatbot_response(initial_message, 'offender', n=1)
21
  _, victim_choices = chatbot_response(offender_response, 'victim', n=3)
22
 
23
- # Schedule the offender's response to be added after a delay
24
- gr.Result(delayed_offender_response, [chatbot_history, offender_response], _js="() => setTimeout(() => _js_return_(), 2000)")
25
-
26
- return chatbot_history, gr.update(choices=victim_choices)
 
27
 
28
  with gr.Blocks() as demo:
29
  screen = gr.Chatbot()
 
1
  import gradio as gr
2
+ from chatbot_utils import process_user_input, chatbot_response
3
+ import time
4
 
5
  def create_interface():
6
  def handle_user_response(user_input, selected_response, chatbot_history):
 
10
  if input_text.strip().lower() == "종료":
11
  return new_history, gr.update(choices=[], interactive=False)
12
 
13
+ # Add user's input to history
14
+ new_history = new_history + [(input_text, None)]
15
 
16
+ # Use a yield to first return the user's input, then the offender's response after a delay
17
+ yield new_history, gr.update(choices=choices)
18
+ time.sleep(2) # 2-second delay
19
+ new_history = new_history + [(None, offender_response)]
20
+ yield new_history, gr.update(choices=choices)
21
 
22
  def handle_case_selection():
23
  initial_message = "발표가 망한 건 제 잘못도 좀 있지만, 팀장님은 아무것도 안 하면서 이러는 건 선 넘은거죠"
 
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()