Spaces:
Sleeping
Sleeping
| import streamlit as st | |
| from transformers import pipeline | |
| from PIL import Image | |
| st.title("📸 Facial Expression Recognition") | |
| st.write("Upload a photo or use your webcam to detect emotions.") | |
| # Load Vision AI (Lightweight) | |
| def load_model(): | |
| return pipeline("image-classification", model="dima806/facial_emotions_image_detection") | |
| with st.spinner("Loading Vision AI..."): | |
| classifier = load_model() | |
| # Input Options | |
| option = st.radio("Choose Input:", ["Webcam", "Upload Image"], horizontal=True) | |
| if option == "Webcam": | |
| image_input = st.camera_input("Take a picture") | |
| if image_input: | |
| img = Image.open(image_input) | |
| results = classifier(img) | |
| st.success(f"Prediction: **{results[0]['label']}** ({round(results[0]['score']*100, 1)}%)") | |
| st.bar_chart({x['label']: x['score'] for x in results}) | |
| elif option == "Upload Image": | |
| uploaded_file = st.file_uploader("Choose an image...", type=["jpg", "png", "jpeg"]) | |
| if uploaded_file: | |
| img = Image.open(uploaded_file) | |
| st.image(img, width=300) | |
| results = classifier(img) | |
| st.success(f"Prediction: **{results[0]['label']}** ({round(results[0]['score']*100, 1)}%)") | |
| st.bar_chart({x['label']: x['score'] for x in results}) |