-
Notifications
You must be signed in to change notification settings - Fork 0
/
english_to_hinglish.py
40 lines (33 loc) · 1.04 KB
/
english_to_hinglish.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# -*- coding: utf-8 -*-
"""English_to_Hinglish.ipynb
Automatically generated by Colaboratory.
Original file is located at
https://colab.research.google.com/drive/1Pxo-aRbdtkJJ-NqUcsOjw1ceBMnMKGGt
"""
from transformers import pipeline
# Create a translation pipeline for English to Hindi
translator = pipeline("translation", model="Helsinki-NLP/opus-mt-en-hi")
translation_dict = {
"प्रतिक्रिया": "feedback",
"टिप्पणी": "comment",
"खण्ड": "section",
"वीडियो": "video",
"उत्पादों": "products",
"मिनट": "minute",
"डेमो": "demo",
"सिरसेट":"headset",
"बैग": "bag"
}
# Input English text
english_text = input()
# Translate English text to Hinglish
hinglish_text = translator(english_text, max_length=100)[0]['translation_text']
words=hinglish_text.split(' ')
sentence=""
for word in words:
if word in translation_dict:
word=translation_dict[word]
sentence+=" "+word
else:
sentence+=" "+word
print(sentence)