Spaces:
Sleeping
Sleeping
| import streamlit as st | |
| import cv2 | |
| import numpy as np | |
| from fer import FER | |
| from PIL import Image | |
| detector = FER(mtcnn=True) | |
| def detect_emotion(image): | |
| img_array = np.array(image) | |
| emotions = detector.detect_emotions(img_array)[0] | |
| dominant_emotion = max(emotions['emotions'], key=emotions['emotions'].get) | |
| return dominant_emotion | |
| st.title("Emotion Detection from Photo") | |
| uploaded_file = st.file_uploader("Choose an image...", type=["jpg", "jpeg", "png"]) | |
| if uploaded_file is not None: | |
| image = Image.open(uploaded_file) | |
| st.image(image, caption="Uploaded Image", use_column_width=True) | |
| if st.button("Detect Emotion"): | |
| result = detect_emotion(image) | |
| st.write(f"Detected emotion: {result}") |