Spaces:
Runtime error
Runtime error
Commit
·
75729f7
1
Parent(s):
7a69eba
Upload gradio.py
Browse files
gradio.py
ADDED
@@ -0,0 +1,35 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
import random
|
3 |
+
import time
|
4 |
+
import socket ##
|
5 |
+
import json ##
|
6 |
+
|
7 |
+
#61.73.196.167
|
8 |
+
#192.168.0.100
|
9 |
+
host = "61.73.196.167"
|
10 |
+
port = 5050
|
11 |
+
|
12 |
+
with gr.Blocks() as demo:
|
13 |
+
chatbot = gr.Chatbot()
|
14 |
+
msg = gr.Textbox()
|
15 |
+
clear = gr.ClearButton([msg, chatbot])
|
16 |
+
|
17 |
+
def respond(message, chat_history):
|
18 |
+
query = message
|
19 |
+
mySocket = socket.socket() ###
|
20 |
+
mySocket.connect((host, port)) ###
|
21 |
+
json_data = { ###
|
22 |
+
'Query' : query, ###
|
23 |
+
'BotType' : "TEST" ###
|
24 |
+
}
|
25 |
+
_message = json.dumps(json_data) ### 질문 JSON 형식으로 보내기
|
26 |
+
mySocket.send(_message.encode()) ### 소켓 전송
|
27 |
+
data = mySocket.recv(4096).decode()
|
28 |
+
ret_data = json.loads(data)
|
29 |
+
#bot_message = random.choice(["How are you?", "I love you", "I'm very hungry"])
|
30 |
+
chat_history.append((message, ret_data['Answer']))
|
31 |
+
time.sleep(2)
|
32 |
+
return "", chat_history
|
33 |
+
msg.submit(respond, [msg, chatbot], [msg, chatbot])
|
34 |
+
|
35 |
+
demo.launch()
|