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