Spaces:
Runtime error
Runtime error
| import gradio as gr | |
| import random | |
| import time | |
| import socket ## | |
| import json ## | |
| #61.73.196.167 | |
| #192.168.0.100 | |
| host = "61.73.196.167" | |
| port = 5050 | |
| with gr.Blocks() as demo: | |
| chatbot = gr.Chatbot() | |
| msg = gr.Textbox() | |
| clear = gr.ClearButton([msg, chatbot]) | |
| def respond(message, chat_history): | |
| query = message | |
| mySocket = socket.socket() ### | |
| mySocket.connect((host, port)) ### | |
| json_data = { ### | |
| 'Query' : query, ### | |
| 'BotType' : "TEST" ### | |
| } | |
| _message = json.dumps(json_data) ### 질문 JSON 형식으로 보내기 | |
| mySocket.send(_message.encode()) ### 소켓 전송 | |
| data = mySocket.recv(4096).decode() | |
| ret_data = json.loads(data) | |
| #bot_message = random.choice(["How are you?", "I love you", "I'm very hungry"]) | |
| chat_history.append((message, ret_data['Answer'])) | |
| time.sleep(2) | |
| return "", chat_history | |
| msg.submit(respond, [msg, chatbot], [msg, chatbot]) | |
| demo.launch() |