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()