Spaces:
Sleeping
Sleeping
File size: 2,040 Bytes
95e6dc0 72a7b9b 95e6dc0 0a07e3b 72a7b9b 95e6dc0 72a7b9b 95e6dc0 72a7b9b 0a07e3b 95e6dc0 72a7b9b 95e6dc0 0a07e3b 72a7b9b 0a07e3b 72a7b9b 95e6dc0 3ff189a 95e6dc0 3ff189a 95e6dc0 0a07e3b 95e6dc0 0a07e3b 95e6dc0 72a7b9b |
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 |
import gradio as gr
from chatbot_utils import process_user_input, get_both_responses
import asyncio
def create_interface():
async 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 + [(input_text, "μ€νμ μ°Έκ°ν΄ μ£Όμ
μ κ°μ¬ν©λλ€. νμ μ§μλ₯Ό λ°λΌμ£ΌμΈμ")]
return new_history, gr.update(choices=[], interactive=False)
new_history, victim_choices = await process_user_input(input_text, chatbot_history)
return new_history, gr.update(choices=victim_choices)
async def handle_case_selection():
initial_message = "λ°νκ° λ§ν 건 μ μλͺ»λ μ’ μμ§λ§, νμ₯λμ μ무κ²λ μ νλ©΄μ μ΄λ¬λ 건 μ λμκ±°μ£ "
victim_response, victim_choices, offender_response = await get_both_responses(initial_message)
chatbot_history = [(initial_message, victim_response), (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
# Gradioμ launch ν¨μλ₯Ό μ¬μ©νμ¬ μΈν°νμ΄μ€λ₯Ό μ€νν©λλ€.
if __name__ == "__main__":
demo = create_interface()
demo.launch() |