Spaces:
Runtime error
Runtime error
from transformers import AutoTokenizer, AutoModelForSeq2SeqLM | |
import joblib | |
tokenizer = AutoTokenizer.from_pretrained("Helsinki-NLP/opus-mt-en-hi") | |
model = AutoModelForSeq2SeqLM.from_pretrained("Helsinki-NLP/opus-mt-en-hi") | |
joblib.dump(model, 'model.sav') | |
loaded_model = joblib.load('model.sav') | |
joblib.dump(tokenizer, 'tokenizer.sav') | |
loaded_tokenizer = joblib.load('tokenizer.sav') | |
def translator(text): | |
# function to translate english text to hindi | |
input_ids = loaded_tokenizer.encode(text, return_tensors="pt", padding=True) | |
outputs = loaded_model.generate(input_ids) | |
decoded_text = loaded_tokenizer.decode(outputs[0], skip_special_tokens=True) | |
return decoded_text | |
texts = ["I spend a few hours a day maintaining my website.", | |
"Where do random thoughts come from?", | |
"I can't believe that she is older than my mother.", | |
"My Mum tries to be cool by saying that she likes all the same things that I do", | |
"A song can make or ruin a person’s day if they let it get to them."] | |
for text in texts: | |
print("English Text: ", text) | |
print("Hindi Translation: ", translator(text)) | |
print("*"*50,"\n") |