import random import time import gradio as gr from transformers import pipeline translator = pipeline("translation", model=f'Broomva/bart-large-translation-spa-guc') def slow_echo(message, history): translated = translator(message)[0]['translation_text'] for i in range(len(translated)): time.sleep(0.05) yield translated[: i+1] demo = gr.ChatInterface(slow_echo).queue() if __name__ == "__main__": demo.launch()