Spaces:
Build error
Build error
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,24 +1,11 @@
|
|
| 1 |
-
|
| 2 |
-
from transformers import pipeline
|
| 3 |
-
|
| 4 |
-
# Load AI translation models
|
| 5 |
-
translator_en_fr = pipeline("translation_en_to_fr", model="Helsinki-NLP/opus-mt-en-fr")
|
| 6 |
translator_en_es = pipeline("translation_en_to_es", model="Helsinki-NLP/opus-mt-en-es")
|
| 7 |
|
| 8 |
-
# Function to translate messages
|
| 9 |
def chatbot_translate(message, history):
|
| 10 |
-
if message.
|
| 11 |
-
return translator_en_fr(message.replace("French:", "")
|
| 12 |
-
elif message.
|
| 13 |
-
return translator_en_es(message.replace("Spanish:", "")
|
| 14 |
else:
|
| 15 |
-
return "Please specify
|
| 16 |
-
|
| 17 |
-
# Create Gradio chatbot UI
|
| 18 |
-
iface = gr.ChatInterface(
|
| 19 |
-
chatbot_translate,
|
| 20 |
-
title="AI Translator Bot",
|
| 21 |
-
description="Type 'French: [your text]' or 'Spanish: [your text]' to translate!",
|
| 22 |
-
)
|
| 23 |
|
| 24 |
-
iface.launch()
|
|
|
|
| 1 |
+
translator_en_fr = pipeline("translation_en_to_fr", model="Helsinki-NLP/opus-mt-en-fr")
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2 |
translator_en_es = pipeline("translation_en_to_es", model="Helsinki-NLP/opus-mt-en-es")
|
| 3 |
|
|
|
|
| 4 |
def chatbot_translate(message, history):
|
| 5 |
+
if message.startswith("French:"):
|
| 6 |
+
return translator_en_fr(message.replace("French:", ""))[0]['translation_text']
|
| 7 |
+
elif message.startswith("Spanish:"):
|
| 8 |
+
return translator_en_es(message.replace("Spanish:", ""))[0]['translation_text']
|
| 9 |
else:
|
| 10 |
+
return "Please specify the language (French or Spanish)."
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 11 |
|
|
|