-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.py
41 lines (27 loc) · 1.19 KB
/
main.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
41
'''
Runs a flask service for exposing the APIs.
Exposes one api :/transliterate to get this up and working.
Return output json, after processing the input which in recieved as a json.
Does error detection, for wrong inputs, using the error cases implemented in the errorCheck.py
'''
from flask import Flask, render_template, request, flash, url_for, jsonify
from isotrans import isotrans
from errorCheck import *
def errorDetect(text):
ec = errorCheck(text)
return ec.CheckInput()
app = Flask(__name__)
@app.route('/transliterate', methods=['POST'])
def transliterate():
req_data = request.get_json()
text = req_data['text']
errorStatus = errorDetect(text)#errorStatus is True is one of the validation cases fails, False otherwise.
if errorStatus == False:
transliterator = isotrans()
transliterated_text = transliterator.transliterate(text)
td = {'transliterated_text' : transliterated_text,'error':'None'}
return jsonify(td)
else:
return jsonify({'transliterated_text':'None','error':errorStatus})
if __name__ == '__main__':
app.run(host='0.0.0.0', port = 7000, debug=True)#can be changed by user if this to be run on another port.