AreesaAshfaq commited on
Commit
4438826
1 Parent(s): ae981e1

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +11 -3
app.py CHANGED
@@ -2,7 +2,7 @@ import streamlit as st
2
  from transformers import MarianMTModel, MarianTokenizer
3
 
4
  # Load the MarianMT model and tokenizer
5
- model_name = "Helsinki-NLP/opus-mt-en-ROMANCE"
6
  model = MarianMTModel.from_pretrained(model_name)
7
  tokenizer = MarianTokenizer.from_pretrained(model_name)
8
 
@@ -13,6 +13,14 @@ language_codes = {
13
  'Italian': 'it',
14
  'Portuguese': 'pt',
15
  'Spanish': 'es',
 
 
 
 
 
 
 
 
16
  # Add more languages if needed
17
  }
18
 
@@ -20,12 +28,12 @@ def translate_text(text, target_lang_code):
20
  # Prepare the input and translate
21
  inputs = tokenizer.encode(text, return_tensors="pt")
22
  # Generate the translation
23
- translated = model.generate(inputs, decoder_start_token_id=tokenizer.get_lang_id(target_lang_code))
24
  translated_text = tokenizer.decode(translated[0], skip_special_tokens=True)
25
  return translated_text
26
 
27
  def main():
28
- st.title("English to Any Language Translator")
29
 
30
  # User input for English text
31
  text_to_translate = st.text_area("Enter text in English:")
 
2
  from transformers import MarianMTModel, MarianTokenizer
3
 
4
  # Load the MarianMT model and tokenizer
5
+ model_name = "Helsinki-NLP/opus-mt-en-many-to-many-mmt"
6
  model = MarianMTModel.from_pretrained(model_name)
7
  tokenizer = MarianTokenizer.from_pretrained(model_name)
8
 
 
13
  'Italian': 'it',
14
  'Portuguese': 'pt',
15
  'Spanish': 'es',
16
+ 'Chinese': 'zh',
17
+ 'Japanese': 'ja',
18
+ 'Korean': 'ko',
19
+ 'Russian': 'ru',
20
+ 'Arabic': 'ar',
21
+ 'Turkish': 'tr',
22
+ 'Hindi': 'hi',
23
+ 'Swahili': 'sw',
24
  # Add more languages if needed
25
  }
26
 
 
28
  # Prepare the input and translate
29
  inputs = tokenizer.encode(text, return_tensors="pt")
30
  # Generate the translation
31
+ translated = model.generate(inputs, decoder_start_token_id=tokenizer.lang_code_to_id[target_lang_code])
32
  translated_text = tokenizer.decode(translated[0], skip_special_tokens=True)
33
  return translated_text
34
 
35
  def main():
36
+ st.title("Multilingual Translator")
37
 
38
  # User input for English text
39
  text_to_translate = st.text_area("Enter text in English:")