|
import os |
|
import gradio as gr |
|
import json |
|
|
|
from apidemo.TranslateDemo import createRequest |
|
|
|
def get_responce(msg): |
|
|
|
result_str = createRequest(msg) |
|
result = json.loads(result_str) |
|
return result["translation"][0] |
|
|
|
|
|
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() |
|
|
|
|
|
|
|
|
|
|
|
|
|
|