File size: 1,268 Bytes
a119103
 
 
 
8c71b10
 
a119103
8c71b10
a119103
8c71b10
a119103
 
8c71b10
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
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)
@st.cache_resource
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})