Spaces:
Sleeping
Sleeping
pavanhitloop
commited on
Commit
•
e06f9a5
1
Parent(s):
ee8f74d
Update app.py
Browse files
app.py
CHANGED
@@ -9,7 +9,7 @@ import json
|
|
9 |
|
10 |
class LTRC_Translation_API():
|
11 |
def __init__(self, url = 'https://ssmt.iiit.ac.in/onemt', src_lang = 'en', tgt_lang = 'te'):
|
12 |
-
self.lang_map = {'te': 'tel', 'en': 'eng', 'ta': 'tam', 'ml': 'mal', 'mr': 'mar', 'kn': 'kan', 'hi': 'hin'
|
13 |
self.url = url
|
14 |
|
15 |
self.headers = {
|
@@ -17,10 +17,11 @@ class LTRC_Translation_API():
|
|
17 |
'Accept': 'application/json'
|
18 |
}
|
19 |
|
20 |
-
|
|
|
21 |
|
22 |
self.src_lang = src_lang
|
23 |
-
self.tgt_lang =
|
24 |
|
25 |
def translate(self, text):
|
26 |
try:
|
@@ -127,7 +128,7 @@ class LTRC_Translation_API():
|
|
127 |
# return " ".join(decoded_output)
|
128 |
|
129 |
|
130 |
-
def get_prediction(text,
|
131 |
# if len(sys.argv)<3:
|
132 |
# print("Usage: python app.py <text_file_path> <lang_id>")
|
133 |
# print("Text file should contain the article news")
|
@@ -165,7 +166,7 @@ def get_prediction(text, lang_id, translate = False):
|
|
165 |
# return "Headline: " + headline + "\nSummary: " + summary
|
166 |
# return [text, summary, headline]
|
167 |
|
168 |
-
translator = LTRC_Translation_API(tgt_lang =
|
169 |
text = translator.translate(text)
|
170 |
|
171 |
return text
|
|
|
9 |
|
10 |
class LTRC_Translation_API():
|
11 |
def __init__(self, url = 'https://ssmt.iiit.ac.in/onemt', src_lang = 'en', tgt_lang = 'te'):
|
12 |
+
self.lang_map = {'te': 'tel', 'en': 'eng', 'ta': 'tam', 'ml': 'mal', 'mr': 'mar', 'kn': 'kan', 'hi': 'hin'}
|
13 |
self.url = url
|
14 |
|
15 |
self.headers = {
|
|
|
17 |
'Accept': 'application/json'
|
18 |
}
|
19 |
|
20 |
+
tgt_lang = self.lang_map.get(tgt_lang, 'te')
|
21 |
+
src_lang = self.lang_map.get(src_lang, 'en')
|
22 |
|
23 |
self.src_lang = src_lang
|
24 |
+
self.tgt_lang = tgt_lang
|
25 |
|
26 |
def translate(self, text):
|
27 |
try:
|
|
|
128 |
# return " ".join(decoded_output)
|
129 |
|
130 |
|
131 |
+
def get_prediction(text, src_lang_id, tgt_lang_id, translate = False):
|
132 |
# if len(sys.argv)<3:
|
133 |
# print("Usage: python app.py <text_file_path> <lang_id>")
|
134 |
# print("Text file should contain the article news")
|
|
|
166 |
# return "Headline: " + headline + "\nSummary: " + summary
|
167 |
# return [text, summary, headline]
|
168 |
|
169 |
+
translator = LTRC_Translation_API(src_lang = src_lang_id, tgt_lang = tgt_lang_id)
|
170 |
text = translator.translate(text)
|
171 |
|
172 |
return text
|