Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -2,7 +2,7 @@ import gradio as gr
|
|
2 |
from deepface import DeepFace
|
3 |
import tempfile
|
4 |
import os
|
5 |
-
import
|
6 |
|
7 |
def analyze_image(image):
|
8 |
try:
|
@@ -11,28 +11,30 @@ def analyze_image(image):
|
|
11 |
image.save(temp_file.name)
|
12 |
temp_path = temp_file.name
|
13 |
|
14 |
-
# Run
|
15 |
result = DeepFace.analyze(
|
16 |
img_path=temp_path,
|
17 |
-
actions=["
|
18 |
enforce_detection=False
|
19 |
-
)
|
20 |
|
21 |
-
os.remove(temp_path)
|
22 |
|
23 |
-
|
24 |
-
|
|
|
|
|
25 |
|
26 |
except Exception as e:
|
27 |
-
|
|
|
28 |
|
29 |
-
# Gradio app
|
30 |
demo = gr.Interface(
|
31 |
fn=analyze_image,
|
32 |
inputs=gr.Image(type="pil"),
|
33 |
-
outputs=gr.Textbox(label="
|
34 |
-
title="DeepFace
|
35 |
-
description="Upload a face image. Model
|
36 |
)
|
37 |
|
38 |
demo.launch()
|
|
|
2 |
from deepface import DeepFace
|
3 |
import tempfile
|
4 |
import os
|
5 |
+
import traceback
|
6 |
|
7 |
def analyze_image(image):
|
8 |
try:
|
|
|
11 |
image.save(temp_file.name)
|
12 |
temp_path = temp_file.name
|
13 |
|
14 |
+
# Run analysis
|
15 |
result = DeepFace.analyze(
|
16 |
img_path=temp_path,
|
17 |
+
actions=["emotion", "gender"],
|
18 |
enforce_detection=False
|
19 |
+
)[0]
|
20 |
|
21 |
+
os.remove(temp_path)
|
22 |
|
23 |
+
emotion = result.get("dominant_emotion", "Unknown")
|
24 |
+
gender = result.get("dominant_gender", "Unknown")
|
25 |
+
|
26 |
+
return f"Gender: {gender}\nEmotion: {emotion}"
|
27 |
|
28 |
except Exception as e:
|
29 |
+
tb = traceback.format_exc()
|
30 |
+
return f"Error occurred:\n{e}\n\nTraceback:\n{tb}"
|
31 |
|
|
|
32 |
demo = gr.Interface(
|
33 |
fn=analyze_image,
|
34 |
inputs=gr.Image(type="pil"),
|
35 |
+
outputs=gr.Textbox(label="Prediction"),
|
36 |
+
title="DeepFace: Emotion & Gender Detection",
|
37 |
+
description="Upload a clear face image. Model predicts gender and emotion."
|
38 |
)
|
39 |
|
40 |
demo.launch()
|