-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.py
More file actions
25 lines (20 loc) · 830 Bytes
/
app.py
File metadata and controls
25 lines (20 loc) · 830 Bytes
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
from flask import Flask, request,render_template
from gensim.models import Word2Vec as w2v
app=Flask(__name__)
model = w2v.load('models/w2v.model')
keys = []
for index, word in enumerate(model.wv.index_to_key):
keys.append(word)
#default page of our web-app
@app.route('/')
def home():
return render_template('index.html', prediction_text = 'HOME')
@app.route("/predict", methods=['POST']) #decorator
def predict():
word = request.form["word"]
if word in keys:
prediction = model.wv.most_similar(word)
return render_template('index.html', prediction_text='Similar words would be $ {}'.format(prediction))
return render_template('index.html', prediction_text = "Given word is not key in w2v model")
if __name__ == '__main__':
app.run(debug=True,host='0.0.0.0')