Spaces:
Build error
Build error
Update app.py
Browse files
app.py
CHANGED
@@ -1,86 +1,89 @@
|
|
1 |
import cv2
|
2 |
-
import
|
3 |
import numpy as np
|
|
|
4 |
import tensorflow as tf
|
5 |
-
from tensorflow.keras.models import load_model
|
6 |
-
from flask import Flask, render_template
|
7 |
-
import requests
|
8 |
|
9 |
-
# Initialize Flask app
|
10 |
app = Flask(__name__)
|
11 |
|
12 |
-
#
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
# Load
|
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 |
-
return "Acne detected: Recommended product XYZ"
|
57 |
-
else:
|
58 |
-
return "Skin is clear: Recommended moisturizer ABC"
|
59 |
-
|
60 |
@app.route('/')
|
61 |
-
def
|
62 |
-
#
|
|
|
|
|
|
|
|
|
63 |
cap = cv2.VideoCapture(0)
|
64 |
ret, frame = cap.read()
|
65 |
-
|
66 |
-
|
67 |
-
|
68 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
69 |
|
70 |
-
|
71 |
-
|
72 |
-
for face in faces:
|
73 |
-
landmarks = predictor(cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY), face)
|
74 |
-
frame = apply_makeup(frame, lipstick)
|
75 |
-
|
76 |
-
# Get weather and outfit suggestion
|
77 |
-
weather = get_weather()
|
78 |
-
outfit_suggestion = suggest_outfit(weather)
|
79 |
-
|
80 |
-
# Display results on the web page
|
81 |
-
return render_template('index.html', skin_condition=skin_condition, outfit_suggestion=outfit_suggestion)
|
82 |
|
83 |
-
if __name__ ==
|
84 |
app.run(debug=True)
|
85 |
|
86 |
|
|
|
1 |
import cv2
|
2 |
+
import mediapipe as mp
|
3 |
import numpy as np
|
4 |
+
from flask import Flask, render_template, request
|
5 |
import tensorflow as tf
|
|
|
|
|
|
|
6 |
|
7 |
+
# Initialize the Flask app
|
8 |
app = Flask(__name__)
|
9 |
|
10 |
+
# Initialize Mediapipe for face detection
|
11 |
+
mp_face_detection = mp.solutions.face_detection
|
12 |
+
mp_drawing = mp.solutions.drawing_utils
|
13 |
+
|
14 |
+
# Load AI models for skin care, health, makeup, and fashion recommendations
|
15 |
+
# You should have these models pre-trained and available
|
16 |
+
# For simplicity, placeholders are used
|
17 |
+
skin_care_model = tf.keras.models.load_model('skin_care_model.h5') # Example placeholder
|
18 |
+
makeup_model = tf.keras.models.load_model('makeup_model.h5') # Example placeholder
|
19 |
+
health_model = tf.keras.models.load_model('health_model.h5') # Example placeholder
|
20 |
+
fashion_model = tf.keras.models.load_model('fashion_model.h5') # Example placeholder
|
21 |
+
|
22 |
+
# Function to detect faces using Mediapipe
|
23 |
+
def detect_faces(image):
|
24 |
+
with mp_face_detection.FaceDetection(min_detection_confidence=0.2) as face_detection:
|
25 |
+
# Convert the image to RGB for Mediapipe
|
26 |
+
rgb_image = cv2.cvtColor(image, cv2.COLOR_BGR2RGB)
|
27 |
+
results = face_detection.process(rgb_image)
|
28 |
+
if results.detections:
|
29 |
+
for detection in results.detections:
|
30 |
+
bboxC = detection.location_data.relative_bounding_box
|
31 |
+
ih, iw, _ = image.shape
|
32 |
+
x, y, w, h = int(bboxC.xmin * iw), int(bboxC.ymin * ih), int(bboxC.width * iw), int(bboxC.height * ih)
|
33 |
+
cv2.rectangle(image, (x, y), (x + w, y + h), (255, 0, 0), 2)
|
34 |
+
return image
|
35 |
+
|
36 |
+
# Placeholder recommendation functions (you should replace these with actual AI models)
|
37 |
+
def get_skin_care_recommendation(face_image):
|
38 |
+
# Analyze the skin condition (dummy function for example)
|
39 |
+
return "Recommended product: Vitamin C Serum"
|
40 |
+
|
41 |
+
def get_makeup_recommendation(face_image):
|
42 |
+
# Suggest makeup based on facial features (dummy function for example)
|
43 |
+
return "Suggested makeup: Natural look foundation"
|
44 |
+
|
45 |
+
def get_health_recommendation(face_image):
|
46 |
+
# Analyze health metrics (dummy function for example)
|
47 |
+
return "Health alert: Normal blood pressure"
|
48 |
+
|
49 |
+
def get_fashion_recommendation(face_image):
|
50 |
+
# Suggest outfits based on style and weather (dummy function for example)
|
51 |
+
return "Suggested outfit: Casual wear suitable for sunny weather"
|
52 |
+
|
53 |
+
# Route to handle the display of the mirror and recommendations
|
|
|
|
|
|
|
|
|
54 |
@app.route('/')
|
55 |
+
def index():
|
56 |
+
return render_template('index.html') # Add your HTML file here
|
57 |
+
|
58 |
+
@app.route('/capture', methods=['POST'])
|
59 |
+
def capture():
|
60 |
+
# Capture an image from the webcam
|
61 |
cap = cv2.VideoCapture(0)
|
62 |
ret, frame = cap.read()
|
63 |
+
if not ret:
|
64 |
+
return "Failed to capture image", 400
|
65 |
+
|
66 |
+
# Process the captured frame to detect faces and provide recommendations
|
67 |
+
frame = detect_faces(frame)
|
68 |
+
|
69 |
+
# Extract personalized recommendations (example placeholders)
|
70 |
+
skin_care = get_skin_care_recommendation(frame)
|
71 |
+
makeup = get_makeup_recommendation(frame)
|
72 |
+
health = get_health_recommendation(frame)
|
73 |
+
fashion = get_fashion_recommendation(frame)
|
74 |
+
|
75 |
+
# Return recommendations as response
|
76 |
+
recommendations = {
|
77 |
+
'skin_care': skin_care,
|
78 |
+
'makeup': makeup,
|
79 |
+
'health': health,
|
80 |
+
'fashion': fashion
|
81 |
+
}
|
82 |
|
83 |
+
cap.release()
|
84 |
+
return recommendations
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
85 |
|
86 |
+
if __name__ == "__main__":
|
87 |
app.run(debug=True)
|
88 |
|
89 |
|