Added my translation script
Browse files- translate_script.py +44 -0
translate_script.py
ADDED
|
@@ -0,0 +1,44 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Your script here
|
| 2 |
+
from transformers import MarianMTModel, MarianTokenizer
|
| 3 |
+
|
| 4 |
+
model_name = "Helsinki-NLP/opus-mt-en-hi"
|
| 5 |
+
model = MarianMTModel.from_pretrained(model_name)
|
| 6 |
+
tokenizer = MarianTokenizer.from_pretrained(model_name)
|
| 7 |
+
|
| 8 |
+
def translate_english_to_hindi(text):
|
| 9 |
+
inputs = tokenizer(text, return_tensors="pt", padding=True, truncation=True)
|
| 10 |
+
translated = model.generate(**inputs)
|
| 11 |
+
translated_text = tokenizer.decode(translated[0], skip_special_tokens=True)
|
| 12 |
+
return translated_text
|
| 13 |
+
|
| 14 |
+
idiom_meanings = {
|
| 15 |
+
"Break the ice": "पहली बार बातचीत शुरू करना, ताकि माहौल हल्का हो सके",
|
| 16 |
+
"A blessing in disguise": "कोई नज़र में मुश्किल, लेकिन अंत में फायदेमंद",
|
| 17 |
+
"Hit the nail on the head": "सही बात कहना या करना",
|
| 18 |
+
"Bite the bullet": "मुसीबत को सहना और उसका सामना करना",
|
| 19 |
+
"Burn the midnight oil": "रात-रात भर काम करना",
|
| 20 |
+
"Cry over spilt milk": "जो हो चुका है उसके लिए पछताना",
|
| 21 |
+
"Cut to the chase": "सीधे मुद्दे पर आना",
|
| 22 |
+
"Give someone the cold shoulder": "किसी को अनदेखा करना",
|
| 23 |
+
"Once in a blue moon": "बहुत कम होना",
|
| 24 |
+
"Out of the blue": "अचानक से",
|
| 25 |
+
"Spill the beans": "गुप्त बातों का खुलासा करना",
|
| 26 |
+
"The ball is in your court": "अब तुम्हारी बारी है",
|
| 27 |
+
"Through thick and thin": "सुख-दुख में साथ देना",
|
| 28 |
+
"Under the weather": "स्वस्थ नहीं होना",
|
| 29 |
+
"When pigs fly": "जब कुछ असंभव हो",
|
| 30 |
+
"Your guess is as good as mine": "मुझे भी उतना ही पता है जितना तुम्हें",
|
| 31 |
+
"You scratch my back, and I’ll scratch yours": "आप मेरी मदद करेंगे तो मैं भी आपकी मदद करूंगा"
|
| 32 |
+
}
|
| 33 |
+
|
| 34 |
+
def get_meaning_and_translation(idiom):
|
| 35 |
+
meaning = idiom_meanings.get(idiom, "Meaning not found.")
|
| 36 |
+
translation = translate_english_to_hindi(idiom)
|
| 37 |
+
return {"idiom": idiom, "meaning": meaning, "translation": translation}
|
| 38 |
+
|
| 39 |
+
input_idiom = "When pigs fly"
|
| 40 |
+
result = get_meaning_and_translation(input_idiom)
|
| 41 |
+
|
| 42 |
+
print(f"Idiom: {result['idiom']}")
|
| 43 |
+
print(f"Meaning: {result['meaning']}")
|
| 44 |
+
print(f"Translation: {result['translation']}")
|