-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.py
More file actions
71 lines (59 loc) · 2.27 KB
/
app.py
File metadata and controls
71 lines (59 loc) · 2.27 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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
from flask import Flask, render_template, request
import os
from model.predict import predict_skin_type_condition # Import your prediction model
from recommender.recommender import recommender # Import your recommender function
app = Flask(__name__)
app.config['UPLOAD_FOLDER'] = 'static/uploaded_images'
@app.route("/", methods=["GET", "POST"])
def index():
if request.method == "POST":
# Check if a file is part of the request
if 'file' not in request.files:
print("No file uploaded")
return "No file uploaded"
file = request.files['file']
# If no file is selected
if file.filename == '':
print("No file selected")
return "No file selected"
# Save the file
file_path = os.path.join(app.config['UPLOAD_FOLDER'], file.filename)
try:
file.save(file_path)
print(f"File saved at: {file_path}")
except Exception as e:
print(f"Error saving file: {e}")
return "Error saving file"
# Predict skin type and condition
try:
skin_type, skin_condition = predict_skin_type_condition(file_path)
print(f"Predicted Skin Type: {skin_type}, Skin Condition: {skin_condition}")
except Exception as e:
print(f"Error in prediction: {e}")
return "Error in prediction"
# Get recommendations
try:
recommendations = recommender(skin_type, skin_condition)
print(f"Recommendations: {recommendations}")
except Exception as e:
print(f"Error in recommendation: {e}")
return "Error in recommendation"
# Render results
if recommendations:
return render_template(
"results.html",
skin_type=skin_type,
skin_condition=skin_condition,
recommendations=recommendations
)
else:
print("No recommendations found")
return render_template(
"results.html",
skin_type=skin_type,
skin_condition=skin_condition,
recommendations=[]
)
return render_template("index.html")
if __name__ == "__main__":
app.run(debug=True)