test / app.py
zwgao's picture
add app
5a79bd6
raw
history blame
712 Bytes
import os
import gradio as gr
import json
# api_key = os.environ.get('OPENAI_KEY', None)
from apidemo.TranslateDemo import createRequest
def get_responce(msg):
result_str = createRequest(msg)
result = json.loads(result_str)
return result["translation"][0]
# pass
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()