Update app.py
Browse files
app.py
CHANGED
@@ -28,16 +28,8 @@ def perform_handwriting_recognition_easyocr(image_path):
|
|
28 |
def analyze_face(image_path):
|
29 |
try:
|
30 |
jpg_path = convert_to_jpg(image_path)
|
|
|
31 |
analysis = DeepFace.analyze(img_path=jpg_path, actions=["age", "gender", "emotion", "race"])
|
32 |
-
if 'age' not in analysis or 'gender' not in analysis or 'dominant_emotion' not in analysis or 'dominant_race' not in analysis:
|
33 |
-
return {
|
34 |
-
"age": "No face detected",
|
35 |
-
"gender_scores": {"Man": 0, "Woman": 0},
|
36 |
-
"predicted_gender": "No face detected",
|
37 |
-
"emotion": "No face detected",
|
38 |
-
"race": "No face detected",
|
39 |
-
"handwriting": "No face detected"
|
40 |
-
}
|
41 |
gender_scores = analysis["gender"] if not isinstance(analysis, list) else analysis[0]["gender"]
|
42 |
predicted_gender = "Male" if gender_scores["Man"] > gender_scores["Woman"] else "Female"
|
43 |
|
@@ -47,7 +39,7 @@ def analyze_face(image_path):
|
|
47 |
"predicted_gender": predicted_gender,
|
48 |
"emotion": analysis["dominant_emotion"] if not isinstance(analysis, list) else analysis[0]["dominant_emotion"],
|
49 |
"race": analysis["dominant_race"] if not isinstance(analysis, list) else analysis[0]["dominant_race"],
|
50 |
-
"handwriting":
|
51 |
}
|
52 |
return outputs
|
53 |
except Exception as e:
|
|
|
28 |
def analyze_face(image_path):
|
29 |
try:
|
30 |
jpg_path = convert_to_jpg(image_path)
|
31 |
+
handwriting_result = perform_handwriting_recognition_easyocr(jpg_path)
|
32 |
analysis = DeepFace.analyze(img_path=jpg_path, actions=["age", "gender", "emotion", "race"])
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
33 |
gender_scores = analysis["gender"] if not isinstance(analysis, list) else analysis[0]["gender"]
|
34 |
predicted_gender = "Male" if gender_scores["Man"] > gender_scores["Woman"] else "Female"
|
35 |
|
|
|
39 |
"predicted_gender": predicted_gender,
|
40 |
"emotion": analysis["dominant_emotion"] if not isinstance(analysis, list) else analysis[0]["dominant_emotion"],
|
41 |
"race": analysis["dominant_race"] if not isinstance(analysis, list) else analysis[0]["dominant_race"],
|
42 |
+
"handwriting": handwriting_result,
|
43 |
}
|
44 |
return outputs
|
45 |
except Exception as e:
|