Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -7,7 +7,7 @@ DATASET_PATH = "face_dataset"
|
|
7 |
|
8 |
# Load dataset images (only image files are included)
|
9 |
dataset_images = {
|
10 |
-
filename: os.path.join(DATASET_PATH, filename)
|
11 |
for filename in os.listdir(DATASET_PATH)
|
12 |
if filename.lower().endswith(('.jpg', '.jpeg', '.png'))
|
13 |
}
|
@@ -15,7 +15,7 @@ dataset_images = {
|
|
15 |
def recognize_face(uploaded_image):
|
16 |
"""
|
17 |
Compare the uploaded image with dataset images using DeepFace.
|
18 |
-
Returns the matched model name and its image if a verified match is found.
|
19 |
"""
|
20 |
if uploaded_image is None:
|
21 |
return "No image uploaded.", None
|
@@ -30,7 +30,9 @@ def recognize_face(uploaded_image):
|
|
30 |
enforce_detection=False
|
31 |
)
|
32 |
if result.get("verified"):
|
33 |
-
|
|
|
|
|
34 |
except Exception as e:
|
35 |
print(f"Error processing {image_path}: {e}")
|
36 |
|
@@ -41,7 +43,7 @@ iface = gr.Interface(
|
|
41 |
fn=recognize_face,
|
42 |
inputs=gr.Image(type="numpy", label="Upload an Image"),
|
43 |
outputs=[
|
44 |
-
gr.
|
45 |
gr.Image(label="Matched Model Image")
|
46 |
],
|
47 |
title="Face Recognition App",
|
|
|
7 |
|
8 |
# Load dataset images (only image files are included)
|
9 |
dataset_images = {
|
10 |
+
os.path.splitext(filename)[0]: os.path.join(DATASET_PATH, filename) # Remove file extension
|
11 |
for filename in os.listdir(DATASET_PATH)
|
12 |
if filename.lower().endswith(('.jpg', '.jpeg', '.png'))
|
13 |
}
|
|
|
15 |
def recognize_face(uploaded_image):
|
16 |
"""
|
17 |
Compare the uploaded image with dataset images using DeepFace.
|
18 |
+
Returns the matched model name as an Instagram link and its image if a verified match is found.
|
19 |
"""
|
20 |
if uploaded_image is None:
|
21 |
return "No image uploaded.", None
|
|
|
30 |
enforce_detection=False
|
31 |
)
|
32 |
if result.get("verified"):
|
33 |
+
# Create an Instagram link
|
34 |
+
model_link = f'<a href="https://www.instagram.com/{model_name}/" target="_blank">{model_name}</a>'
|
35 |
+
return model_link, image_path
|
36 |
except Exception as e:
|
37 |
print(f"Error processing {image_path}: {e}")
|
38 |
|
|
|
43 |
fn=recognize_face,
|
44 |
inputs=gr.Image(type="numpy", label="Upload an Image"),
|
45 |
outputs=[
|
46 |
+
gr.HTML(label="Model Name"), # Use HTML for clickable link
|
47 |
gr.Image(label="Matched Model Image")
|
48 |
],
|
49 |
title="Face Recognition App",
|