-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAPI.py
More file actions
36 lines (27 loc) · 1.15 KB
/
Copy pathAPI.py
File metadata and controls
36 lines (27 loc) · 1.15 KB
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
import os
import requests
from flask import Flask, render_template, request # import
import analyser as an
from recipe_getter import get_ingr_list
app = Flask(__name__) # calling
@app.route("/", methods=['GET', 'POST']) # initialising
def home(): # function call
return render_template('home.html') # return and calling HTML page (designed templates)
@app.route("/predict", methods=['GET', 'POST'])
def predict():
if request.method == 'POST':
file = request.files['file']
filename = file.filename
file_path = os.path.join(r'static/', filename) # slashes should be handeled properly
file.save(file_path)
product = an.img_analysis(file_path)
if product:
return render_template('predict.html', product=product, user_image=file_path,
ingr=get_ingr_list(product).replace('\n', '<br>'))
else:
return render_template('predict.html', product='Cant detect', user_image=file_path,
ingr='')
else:
return requests.codes.bad_request
if __name__ == "__main__":
app.run()