alperugurcan commited on
Commit
26a82a4
·
verified ·
1 Parent(s): 10b4a46

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +26 -0
app.py ADDED
@@ -0,0 +1,26 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ import cv2
3
+ import numpy as np
4
+ from fer import FER
5
+ from PIL import Image
6
+
7
+ detector = FER(mtcnn=True)
8
+
9
+ def detect_emotion(image):
10
+ img_array = np.array(image)
11
+ emotions = detector.detect_emotions(img_array)[0]
12
+ dominant_emotion = max(emotions['emotions'], key=emotions['emotions'].get)
13
+
14
+ return dominant_emotion
15
+
16
+ st.title("Emotion Detection from Photo")
17
+
18
+ uploaded_file = st.file_uploader("Choose an image...", type=["jpg", "jpeg", "png"])
19
+
20
+ if uploaded_file is not None:
21
+ image = Image.open(uploaded_file)
22
+ st.image(image, caption="Uploaded Image", use_column_width=True)
23
+
24
+ if st.button("Detect Emotion"):
25
+ result = detect_emotion(image)
26
+ st.write(f"Detected emotion: {result}")