energy_chatbot / gradio.py
Nebulae000's picture
Upload gradio.py
75729f7
raw
history blame
999 Bytes
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()