Spaces:
Runtime error
Runtime error
File size: 711 Bytes
043b5a4 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
import torch
from transformers import *
model_name = 'Helsinki-NLP/opus-mt-en-hi'
tokenizer = MarianTokenizer.from_pretrained(model_name)
model = MarianMTModel.from_pretrained(model_name)
device = torch.device('cuda' if torch.cuda.is_available() else 'cpu')
model.to(device)
def translate_english_to_telugu(text):
inputs = tokenizer(text, return_tensors="pt", truncation=True, padding=True, max_length=512).to(device)
translation = model.generate(**inputs)
translated_text = tokenizer.decode(translation[0], skip_special_tokens=True)
return translated_text
input_text = input('Enter text: ')
translated_text = translate_english_to_telugu(input_text)
print('Hindi translation: ', translated_text) |