alperugurcan commited on
Commit
af37cdf
·
verified ·
1 Parent(s): 7971536

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +8 -4
app.py CHANGED
@@ -17,22 +17,26 @@ def analyze_face(image):
17
  else:
18
  analysis_result = analysis_results
19
 
20
- # Extract results
21
  age = analysis_result['age']
22
- gender = analysis_result['gender']
23
  race = analysis_result['dominant_race']
24
  emotion = analysis_result['dominant_emotion']
 
 
25
  emotions_detail = analysis_result['emotion']
 
 
26
 
27
  # Return the results
28
- return age, gender, race, emotion, emotions_detail
29
 
30
  # Define the Gradio interface
31
  iface = gr.Interface(
32
  fn=analyze_face,
33
  inputs=gr.Image(type="pil"),
34
  outputs=[gr.Number(label="Age"),
35
- gr.Text(label="Gender"),
36
  gr.Text(label="Race"),
37
  gr.Text(label="Dominant Emotion"),
38
  gr.JSON(label="Emotion Breakdown")]
 
17
  else:
18
  analysis_result = analysis_results
19
 
20
+ # Extract results with formatting
21
  age = analysis_result['age']
22
+ gender = f"{analysis_result['gender']} ({analysis_result['gender']})" # Gender and its probability
23
  race = analysis_result['dominant_race']
24
  emotion = analysis_result['dominant_emotion']
25
+
26
+ # Clean up the emotion breakdown
27
  emotions_detail = analysis_result['emotion']
28
+ # Format the emotions into a readable string
29
+ formatted_emotions = {key: f"{value:.2f}%" for key, value in emotions_detail.items()}
30
 
31
  # Return the results
32
+ return age, gender, race, emotion, formatted_emotions
33
 
34
  # Define the Gradio interface
35
  iface = gr.Interface(
36
  fn=analyze_face,
37
  inputs=gr.Image(type="pil"),
38
  outputs=[gr.Number(label="Age"),
39
+ gr.Text(label="Gender Probability"),
40
  gr.Text(label="Race"),
41
  gr.Text(label="Dominant Emotion"),
42
  gr.JSON(label="Emotion Breakdown")]