Amandeep01 commited on
Commit
8fad91f
·
verified ·
1 Parent(s): 38abbac

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +26 -0
app.py ADDED
@@ -0,0 +1,26 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ import cv2
3
+ from deepface import DeepFace
4
+ import numpy as np
5
+
6
+ def predict_emotion(image):
7
+ # Convert Gradio image (PIL format) to an OpenCV image
8
+ img = cv2.cvtColor(np.array(image), cv2.COLOR_RGB2BGR)
9
+
10
+ # Analyze the emotion using DeepFace
11
+ result = DeepFace.analyze(img, actions=['emotion'])
12
+
13
+ # Get the dominant emotion
14
+ dominant_emotion = result[0]['dominant_emotion']
15
+
16
+ return dominant_emotion
17
+
18
+ # Define the Gradio interface using the new API
19
+ iface = gr.Interface(fn=predict_emotion,
20
+ inputs=gr.Image(type="pil"), # Updated gr.Image input
21
+ outputs="text", # Text output for dominant emotion
22
+ title="Real-time Facial Emotion Recognition",
23
+ description="Upload an image and get the predicted emotion")
24
+
25
+ # Launch the Gradio app
26
+ iface.launch(share=True)