Spaces:
Sleeping
Sleeping
refactor chatbot
Browse files
app.py
CHANGED
|
@@ -6,27 +6,13 @@ from transformers import pipeline
|
|
| 6 |
|
| 7 |
translator = pipeline("translation", model=f'Broomva/bart-large-translation-spa-guc')
|
| 8 |
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
|
|
|
| 13 |
|
| 14 |
-
|
| 15 |
-
return "", history + [[user_message, None]]
|
| 16 |
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
bot_message = translator(history)[0]['translation_text']
|
| 20 |
-
history[-1][1] = ""
|
| 21 |
-
for character in bot_message:
|
| 22 |
-
history[-1][1] += character
|
| 23 |
-
time.sleep(0.05)
|
| 24 |
-
yield history
|
| 25 |
-
|
| 26 |
-
msg.submit(user, [msg, chatbot], [msg, chatbot], queue=False).then(
|
| 27 |
-
bot, chatbot, chatbot
|
| 28 |
-
)
|
| 29 |
-
clear.click(lambda: None, None, chatbot, queue=False)
|
| 30 |
-
|
| 31 |
-
demo.queue()
|
| 32 |
-
demo.launch()
|
|
|
|
| 6 |
|
| 7 |
translator = pipeline("translation", model=f'Broomva/bart-large-translation-spa-guc')
|
| 8 |
|
| 9 |
+
def slow_echo(message, history):
|
| 10 |
+
translated = translator(message)[0]['translation_text']
|
| 11 |
+
for i in range(len(translated)):
|
| 12 |
+
time.sleep(0.05)
|
| 13 |
+
yield message[: i+1]
|
| 14 |
|
| 15 |
+
demo = gr.ChatInterface(slow_echo).queue()
|
|
|
|
| 16 |
|
| 17 |
+
if __name__ == "__main__":
|
| 18 |
+
demo.launch()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|