Skip to content
This repository has been archived by the owner on Sep 15, 2022. It is now read-only.

Commit

Permalink
[app] Add ai4bharat SSL support for hosting
Browse files Browse the repository at this point in the history
  • Loading branch information
JosephGeoBenjamin committed May 1, 2020
1 parent 8afae3b commit e3ea1c6
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 12 deletions.
26 changes: 15 additions & 11 deletions apps/api_expose.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
"""

from flask import Flask, jsonify, request
from flask_cors import CORS, cross_origin
from datetime import datetime
import traceback
import os
Expand All @@ -24,10 +25,9 @@ class XlitError(enum.Enum):

## Set in order to host in specific domain
SSL_FILES = None
'''
SSL_FILES = ('/etc/letsencrypt/live/domain.com/fullchain.pem',
'/etc/letsencrypt/live/domain.com/privkey.pem')
'''
# SSL_FILES = ('/etc/letsencrypt/live/xlit-api.ai4bharat.org/fullchain.pem',
# '/etc/letsencrypt/live/xlit-api.ai4bharat.org/privkey.pem')


@app.route('/tl/<lang_code>/<eng_word>', methods = ['GET', 'POST'])
def ai4bharat_xlit(lang_code, eng_word):
Expand Down Expand Up @@ -66,21 +66,21 @@ def ai4bharat_xlit(lang_code, eng_word):

class XlitEngine():
def __init__(self):
self.langs = ["hi", "knk"]
self.langs = ["hi", "gom"]

try:
from bins.hindi.program85 import inference_engine as hindi_engine
self.hindi_engine = hindi_engine
except:
print("!!! Failure in loading Hindi")
print("Failure in loading Hindi")
self.langs.remove('hi')

try:
from bins.konkani.knk_program104 import inference_engine as konkani_engine
from bins.konkani.gom_program104 import inference_engine as konkani_engine
self.konkani_engine = konkani_engine
except:
print("!!! Failure in loading Konkani")
self.langs.remove('knk')
print("Failure in loading Konkani")
self.langs.remove('gom')


def transliterate(self, lang_code, eng_word):
Expand All @@ -93,7 +93,7 @@ def transliterate(self, lang_code, eng_word):
try:
if lang_code == "hi":
return self.hindi_engine(eng_word)
elif lang_code == "knk":
elif lang_code == "gom":
return self.konkani_engine(eng_word)

except:
Expand All @@ -108,4 +108,8 @@ def _clean(self, word):

if __name__ == '__main__':
engine = XlitEngine()
app.run(debug=True, host='0.0.0.0', port=8000)
if SSL_FILES:
cors = CORS(app, resources={r"/*": {"origins": "*"}})
app.run(host='0.0.0.0', port=443, ssl_context=SSL_FILES)
else:
app.run(debug=True, host='0.0.0.0', port=8000)
2 changes: 1 addition & 1 deletion utilities/lang_data_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ def __init__(self, lang = 'en'):
self.lang = lang
if lang == 'en':
self.glyphs = indoarab_numeric + english_smallcase
elif lang in ['hi', 'knk']:
elif lang in ['hi', 'gom']:
self.glyphs = indoarab_numeric + devanagari_scripts

self.char2idx = {}
Expand Down

0 comments on commit e3ea1c6

Please sign in to comment.