Spaces:
Runtime error
Runtime error
Commit ·
3fa3145
1
Parent(s): a064905
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,22 +1,19 @@
|
|
| 1 |
-
from transformers import
|
| 2 |
-
import torch
|
| 3 |
-
|
| 4 |
-
model_name = "Helsinki-NLP/opus-mt-he-en"
|
| 5 |
-
model_version = "1.0.0" # Replace with the specific version you want to use
|
| 6 |
-
tokenizer = AutoTokenizer.from_pretrained(model_name, revision=model_version)
|
| 7 |
-
model = AutoModelForSeq2SeqLM.from_pretrained(model_name, revision=model_version)
|
| 8 |
|
| 9 |
def translate_hebrew_to_english(hebrew_text):
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 14 |
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
translated_text = translate_hebrew_to_english(hebrew_text)
|
| 18 |
-
print("Translated text:")
|
| 19 |
-
print(translated_text)
|
| 20 |
|
| 21 |
-
|
| 22 |
-
|
|
|
|
| 1 |
+
from transformers import pipeline
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2 |
|
| 3 |
def translate_hebrew_to_english(hebrew_text):
|
| 4 |
+
# Load the translation pipeline for Hebrew to English
|
| 5 |
+
translator = pipeline("translation", model="Helsinki-NLP/opus-mt-he-en")
|
| 6 |
+
|
| 7 |
+
# Translate the Hebrew text to English
|
| 8 |
+
translation = translator(hebrew_text, max_length=512)[0]["translation_text"]
|
| 9 |
+
|
| 10 |
+
return translation
|
| 11 |
+
|
| 12 |
+
# Prompt the user to input Hebrew text
|
| 13 |
+
hebrew_text = input("Enter the Hebrew text to be translated to English:\n")
|
| 14 |
|
| 15 |
+
# Translate the Hebrew text to English
|
| 16 |
+
english_text = translate_hebrew_to_english(hebrew_text)
|
|
|
|
|
|
|
|
|
|
| 17 |
|
| 18 |
+
# Display the translated text
|
| 19 |
+
print("\nEnglish Translation:\n", english_text)
|