File size: 2,352 Bytes
95e6dc0
 
 
0a07e3b
 
95e6dc0
 
 
0a07e3b
95e6dc0
 
0a07e3b
 
 
 
 
 
 
 
95e6dc0
0a07e3b
95e6dc0
 
0a07e3b
 
 
 
 
 
 
95e6dc0
0a07e3b
95e6dc0
 
 
3ff189a
 
95e6dc0
3ff189a
 
 
95e6dc0
0a07e3b
95e6dc0
0a07e3b
95e6dc0
0a07e3b
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
import gradio as gr
from chatbot_utils import process_user_input, chatbot_response

def create_interface():
    def handle_user_response(user_input, selected_response, chatbot_history):
        input_text = user_input if user_input else selected_response
        
        if input_text.strip().lower() == "μ’…λ£Œ":
            new_history = chatbot_history + [("μ’…λ£Œ", "μ‹€ν—˜μ— μ°Έκ°€ν•΄ μ£Όμ…”μ„œ κ°μ‚¬ν•©λ‹ˆλ‹€. 후속 μ§€μ‹œλ₯Ό λ”°λΌμ£Όμ„Έμš”")]
            return new_history, gr.update(choices=[], interactive=False)
        
        # Get victim's response first
        victim_response, victim_choices = chatbot_response(input_text, 'victim', n=3)
        
        # Then get offender's response
        offender_response, _ = chatbot_response(input_text, 'offender', n=1)
        
        new_history = chatbot_history + [(input_text, victim_response), (None, offender_response)]
        return new_history, gr.update(choices=victim_choices)

    def handle_case_selection():
        initial_message = "λ°œν‘œκ°€ λ§ν•œ 건 제 잘λͺ»λ„ μ’€ μžˆμ§€λ§Œ, νŒ€μž₯λ‹˜μ€ 아무것도 μ•ˆ ν•˜λ©΄μ„œ μ΄λŸ¬λŠ” 건 μ„  λ„˜μ€κ±°μ£ "
        chatbot_history = [(initial_message, None)]
        
        # Get victim's response first
        victim_response, victim_choices = chatbot_response(initial_message, 'victim', n=3)
        chatbot_history.append((None, victim_response))
        
        # Then get offender's response
        offender_response, _ = chatbot_response(initial_message, 'offender', n=1)
        chatbot_history.append((None, offender_response))
        
        return chatbot_history, gr.update(choices=victim_choices)

    with gr.Blocks() as demo:
        case_selection_button = gr.Button("λ°œν‘œκ°€ λ§ν•œ 건 제 잘λͺ»λ„ μ’€ μžˆμ§€λ§Œ, νŒ€μž₯λ‹˜μ€ 아무것도 μ•ˆ ν•˜λ©΄μ„œ μ΄λŸ¬λŠ” 건 μ„  λ„˜μ€κ±°μ£ ")

        screen = gr.Chatbot()
        user_input = gr.Textbox(label="μž…λ ₯ν•˜μ„Έμš”")
        response_choices = gr.Dropdown(label="λ‹΅μ•ˆμ„ κ³¨λΌμ£Όμ„Έμš”", choices=[], interactive=True)
        submit_button = gr.Button(value="전솑")

        case_selection_button.click(handle_case_selection, inputs=[], outputs=[screen, response_choices])
        
        submit_button.click(handle_user_response, inputs=[user_input, response_choices, screen], outputs=[screen, response_choices])

    return demo