File size: 907 Bytes
5a79bd6 f94af79 5a79bd6 f94af79 5a79bd6 f94af79 5a79bd6 |
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 |
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()
|