Spaces:
Runtime error
Runtime error
File size: 1,454 Bytes
c81175d |
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 42 43 44 45 46 |
import requests
import gradio as gr
import time
import re
import uuid
handshake_url = "http://120.46.146.21:7860/chatbot/"
dialog_url = "http://120.46.146.21:7860/chatbot/dialoginfo"
finish_query_url = "http://120.46.146.21:7860/chatbot/finishquery"
def get_internet_ip():
r = requests.get("http://txt.go.sohu.com/ip/soip")
ip = re.findall(r'\d+.\d+.\d+.\d+', r.text)
if ip is not None and len(ip) > 0:
return ip[0]
return None
def get_remote_stream(query, chatbot):
q_id = str(uuid.uuid1())
r = requests.post(handshake_url, json={"q_id": q_id, "query": query, 'history': chatbot})
if r.json()['code'] == 202:
for _ in range(1000):
r = requests.get(dialog_url, {"dialogid": q_id})
history = r.json()['history']
while len(history[-1]) == 0:
history.pop()
r_finish = requests.get(finish_query_url, {"dialogid": q_id})
if r_finish.json() == True:
yield history, ""
print('break')
break
yield history, ""
time.sleep(1)
with gr.Blocks() as demo:
chatbot = gr.Chatbot([[None, get_internet_ip()]], show_label=False, height=650)
query = gr.Textbox(show_label=False, placeholder="请输入提问内容,按回车进行提交")
query.submit(get_remote_stream,[query, chatbot], [chatbot, query])
demo.queue(concurrency_count=10)
demo.launch() |