Spaces:
Runtime error
Runtime error
File size: 987 Bytes
6bcae89 f38a39c 6bcae89 f38a39c 6bcae89 f38a39c 6bcae89 f38a39c 6bcae89 608d3c0 | 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 | import gradio as gr
import requests
import os
root = os.environ["ROOT"]
#############################################################
thread = ""
while not thread.startswith("thread"):
url = root + "/api/create"
PARAMS = {'context1':"context1"}
response = requests.get(
url,
stream=True,
headers={"accept": "*/*"},
params = PARAMS
)
for chunk in response.iter_content(chunk_size=512):
thread = str(chunk, encoding="utf-8")
def predict(message, history):
url = root + "/api/chat"
PARAMS = {'query':message,
'thread':thread,
'context1':"context1",
'context2':"context2"}
response = requests.get(
url,
stream=True,
headers={"accept": "*/*"},
params = PARAMS
)
partial_message = ""
for chunk in response:
if chunk:
partial_message = partial_message + str(chunk, encoding="utf-8")
yield partial_message
gr.ChatInterface(predict).launch() |