File size: 999 Bytes
75729f7
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
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()