Broomva's picture
added spa-guc model
5d2f16c
raw
history blame
902 Bytes
import random
import time
import gradio as gr
from transformers import pipeline
translator = pipeline("translation", model=f'Broomva/bart-large-translation-spa-guc')
with gr.Blocks() as demo:
chatbot = gr.Chatbot()
msg = gr.Textbox()
clear = gr.Button("Clear")
def user(user_message, history):
return "", history + [[user_message, None]]
def bot(history):
#bot_message = random.choice(["How are you?", "I love you", "I'm very hungry"])
bot_message = translator(history)[0]['translation_text']
history[-1][1] = ""
for character in bot_message:
history[-1][1] += character
time.sleep(0.05)
yield history
msg.submit(user, [msg, chatbot], [msg, chatbot], queue=False).then(
bot, chatbot, chatbot
)
clear.click(lambda: None, None, chatbot, queue=False)
demo.queue()
demo.launch()