From e3ea1c6255637a77abbd675428dafa22bad79e1e Mon Sep 17 00:00:00 2001 From: Joseph Geo Benjamin Date: Fri, 1 May 2020 18:25:43 +0530 Subject: [PATCH] [app] Add ai4bharat SSL support for hosting --- apps/api_expose.py | 26 +++++++++++++++----------- utilities/lang_data_utils.py | 2 +- 2 files changed, 16 insertions(+), 12 deletions(-) diff --git a/apps/api_expose.py b/apps/api_expose.py index c584e37..41a83c4 100644 --- a/apps/api_expose.py +++ b/apps/api_expose.py @@ -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 @@ -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//', methods = ['GET', 'POST']) def ai4bharat_xlit(lang_code, eng_word): @@ -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): @@ -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: @@ -108,4 +108,8 @@ def _clean(self, word): if __name__ == '__main__': engine = XlitEngine() - app.run(debug=True, host='0.0.0.0', port=8000) \ No newline at end of file + 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) \ No newline at end of file diff --git a/utilities/lang_data_utils.py b/utilities/lang_data_utils.py index 4f0cc32..c85873e 100644 --- a/utilities/lang_data_utils.py +++ b/utilities/lang_data_utils.py @@ -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 = {}