-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmlpredictweb.py
31 lines (25 loc) · 987 Bytes
/
mlpredictweb.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
import os
from flask import Flask, jsonify, render_template, request
from MalayalamMarkovChain import MalayalamMarkov
os.chdir(os.path.dirname(os.path.realpath(__file__)))
app = Flask(__name__,
static_folder="./dist/static",
template_folder="./dist")
@app.route("/", defaults={'path': ''})
@app.route('/<path:path>')
def index(path):
return render_template('index.html',)
@app.route("/api/predict", methods=['GET'])
def do_generate():
start = request.args.get('start')
number_words = request.args.get('w')
if not number_words:
number_words = 2
number_results = request.args.get('c')
if not number_results:
number_results = 1
mlmarkov = MalayalamMarkov(input_db='./malayalam.db')
results = mlmarkov.predict(start, int(number_words), int(number_results))
return jsonify(word=start, predictions=results)
if __name__ == "__main__":
app.run(debug=True,host='0.0.0.0',port=int(os.environ.get('PORT', 8080)))