shibly100 commited on
Commit
04c29ee
·
verified ·
1 Parent(s): adc0b71

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +6 -19
app.py CHANGED
@@ -1,24 +1,11 @@
1
- import gradio as gr
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.lower().startswith("french:"):
11
- return translator_en_fr(message.replace("French:", "").strip())[0]['translation_text']
12
- elif message.lower().startswith("spanish:"):
13
- return translator_en_es(message.replace("Spanish:", "").strip())[0]['translation_text']
14
  else:
15
- return "Please specify a language (e.g., 'French: Hello' or 'Spanish: Hello')."
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