AreesaAshfaq commited on
Commit
ae981e1
1 Parent(s): 06ccd11

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +2 -3
app.py CHANGED
@@ -19,9 +19,8 @@ language_codes = {
19
  def translate_text(text, target_lang_code):
20
  # Prepare the input and translate
21
  inputs = tokenizer.encode(text, return_tensors="pt")
22
- # Set the decoder start token ID based on language code
23
- decoder_start_token_id = tokenizer.convert_tokens_to_ids(f"<{target_lang_code}>")
24
- translated = model.generate(inputs, decoder_start_token_id=decoder_start_token_id)
25
  translated_text = tokenizer.decode(translated[0], skip_special_tokens=True)
26
  return translated_text
27
 
 
19
  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