-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsci_fact_app.py
executable file
·53 lines (39 loc) · 1.86 KB
/
sci_fact_app.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
42
43
44
45
46
47
48
49
50
51
#!/usr/local/bin/python2
from flask import Flask, request, render_template, send_from_directory, Response
import json
from flavorNetwork.recommender import FlavorRecommender
from flavorNetwork.load_data import load_data
# Initialize the app
app = Flask(__name__, static_folder='output', static_url_path='', template_folder='output')
#load data and initialize recommender
data_dir = './pkld_data/'
comp_ing_dict, edge_dict, all_recipes, pre_match_dict = load_data(data_dir)
comptail_recommender = FlavorRecommender(comp_ing_dict, edge_dict, all_recipes, pre_match_dict)
new_drink = ['gin','lemon', 'cucumber']
# Homepage
@app.route("/")
def home_page():
return app.send_static_file('index.html')
@app.route('/recommender', methods=['GET', 'POST'])
def index():
query = request.form.get('ingredients', None)
button_message = "Enter ingredients separated by commas..."
recs = ['no recommendation'] * 4
insps = ['no recommendation'] * 4
if not query or (query is not None and len(query) == 0):
query = button_message
if query is not None and query != button_message:
recommendations = comptail_recommender.make_rec(query, 15)
try:
recs = [rec[0] for rec in recommendations]
insps = [rec[1] for rec in recommendations]
except IndexError:
recs = ['no recommendation'] * 4
insps = ['no recommendation'] * 4
return render_template('recommend.html', query=query, rec1=recs[0], insp1=insps[0],
rec2=recs[1], insp2=insps[1],
rec3=recs[2], insp3=insps[2],
rec4=recs[3], insp4=insps[3])
return render_template('recommend.html', query=query)
app.debug = True
app.run(host='127.0.0.1', port=8080)