AreesaAshfaq commited on
Commit
842a9ce
·
verified ·
1 Parent(s): eada1d2

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +3 -2
app.py CHANGED
@@ -1,17 +1,18 @@
1
  import streamlit as st
2
  from transformers import MarianMTModel, MarianTokenizer
3
 
4
- # Load the pre-trained 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
 
9
  def translate_text(text, target_lang):
10
- # Translate English to the target language
11
  inputs = tokenizer.encode(text, return_tensors="pt")
12
  translated = model.generate(inputs, decoder_start_token_id=tokenizer.lang_code_to_id[target_lang])
13
  translated_text = tokenizer.decode(translated[0], skip_special_tokens=True)
14
  return translated_text
 
15
  def main():
16
  st.title("English to Any Language Translator")
17
 
 
1
  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
 
9
  def translate_text(text, target_lang):
10
+ # Prepare the input and translate
11
  inputs = tokenizer.encode(text, return_tensors="pt")
12
  translated = model.generate(inputs, decoder_start_token_id=tokenizer.lang_code_to_id[target_lang])
13
  translated_text = tokenizer.decode(translated[0], skip_special_tokens=True)
14
  return translated_text
15
+
16
  def main():
17
  st.title("English to Any Language Translator")
18