shaktibiplab commited on
Commit
c33f8a0
·
verified ·
1 Parent(s): 2e59a1a

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +3 -23
app.py CHANGED
@@ -28,28 +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
- try:
32
- analysis = DeepFace.analyze(img_path=jpg_path, actions=["age", "gender", "emotion", "race"], enforce_detection=False)
33
- except ValueError as e:
34
- return {
35
- "age": "No face detected",
36
- "gender_scores": {"Man": 0, "Woman": 0},
37
- "predicted_gender": "No face detected",
38
- "emotion": "No face detected",
39
- "race": "No face detected",
40
- "handwriting": "No face detected"
41
- }
42
-
43
- if 'age' not in analysis or 'gender' not in analysis or 'dominant_emotion' not in analysis or 'dominant_race' not in analysis:
44
- return {
45
- "age": "No face detected",
46
- "gender_scores": {"Man": 0, "Woman": 0},
47
- "predicted_gender": "No face detected",
48
- "emotion": "No face detected",
49
- "race": "No face detected",
50
- "handwriting": "No face detected"
51
- }
52
-
53
  gender_scores = analysis["gender"] if not isinstance(analysis, list) else analysis[0]["gender"]
54
  predicted_gender = "Male" if gender_scores["Man"] > gender_scores["Woman"] else "Female"
55
 
@@ -59,7 +39,7 @@ def analyze_face(image_path):
59
  "predicted_gender": predicted_gender,
60
  "emotion": analysis["dominant_emotion"] if not isinstance(analysis, list) else analysis[0]["dominant_emotion"],
61
  "race": analysis["dominant_race"] if not isinstance(analysis, list) else analysis[0]["dominant_race"],
62
- "handwriting": perform_handwriting_recognition_easyocr(jpg_path),
63
  }
64
  return outputs
65
  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: