|
import os |
|
import gradio as gr |
|
import json |
|
import requests |
|
|
|
url = os.environ.get("URL", None) |
|
|
|
|
|
|
|
|
|
def get_responce(msg): |
|
|
|
|
|
|
|
|
|
|
|
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)) |
|
|
|
return "", chat_history |
|
|
|
msg.submit(respond, [msg, chatbot], [msg, chatbot]) |
|
|
|
if __name__ == "__main__": |
|
demo.launch() |
|
|