test / app.py
zyliu's picture
add api
f94af79
raw
history blame contribute delete
907 Bytes
import os
import gradio as gr
import json
import requests
url = os.environ.get("URL", None)
# url = "http://localhost:10024/chat"
# from apidemo.TranslateDemo import createRequest
def get_responce(msg):
# result_str = createRequest(msg)
# result = json.loads(result_str)
# return result["translation"][0]
# pass
data = {"text": msg}
response = requests.post(url, data=data)
print(response.content.decode('utf-8'))
return response.content.decode('utf-8')
with gr.Blocks() as demo:
chatbot = gr.Chatbot()
msg = gr.Textbox()
clear = gr.ClearButton([msg, chatbot])
def respond(message, chat_history):
bot_message = get_responce(message)
chat_history.append((message, bot_message))
# time.sleep(2)
return "", chat_history
msg.submit(respond, [msg, chatbot], [msg, chatbot])
if __name__ == "__main__":
demo.launch()