alperugurcan commited on
Commit
692f0b0
·
verified ·
1 Parent(s): b45b92d

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +32 -12
app.py CHANGED
@@ -1,16 +1,36 @@
1
- import streamlit as st
2
  from deepface import DeepFace
 
 
3
 
4
- st.title("DeepFace Face Analysis")
 
 
 
5
 
6
- uploaded_file = st.file_uploader("Upload an image for face analysis:", type=["jpg", "png", "jpeg"])
7
-
8
- if uploaded_file is not None:
9
  # Perform DeepFace analysis
10
- analysis_result = DeepFace.analyze(img_path=uploaded_file, actions=['age', 'gender', 'race', 'emotion'])
11
-
12
- # Display analysis results
13
- st.write("Age:", analysis_result['age'])
14
- st.write("Gender:", analysis_result['gender'])
15
- st.write("Race:", analysis_result['dominant_race'])
16
- st.write("Emotion:", analysis_result['dominant_emotion'])
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
  from deepface import DeepFace
3
+ from PIL import Image
4
+ import numpy as np
5
 
6
+ # Function to analyze the uploaded image
7
+ def analyze_face(image):
8
+ # Convert the image to a numpy array
9
+ image_array = np.array(image)
10
 
 
 
 
11
  # Perform DeepFace analysis
12
+ analysis_result = DeepFace.analyze(img_path=image_array, actions=['age', 'gender', 'race', 'emotion'])
13
+
14
+ # Extract results
15
+ age = analysis_result['age']
16
+ gender = analysis_result['gender']
17
+ race = analysis_result['dominant_race']
18
+ emotion = analysis_result['dominant_emotion']
19
+ emotions_detail = analysis_result['emotion']
20
+
21
+ # Return the results
22
+ return age, gender, race, emotion, emotions_detail
23
+
24
+ # Define the Gradio interface
25
+ iface = gr.Interface(
26
+ fn=analyze_face,
27
+ inputs=gr.Image(type="pil"),
28
+ outputs=[gr.Number(label="Age"),
29
+ gr.Text(label="Gender"),
30
+ gr.Text(label="Race"),
31
+ gr.Text(label="Dominant Emotion"),
32
+ gr.JSON(label="Emotion Breakdown")]
33
+ )
34
+
35
+ # Launch the Gradio app
36
+ iface.launch()