File size: 1,309 Bytes
91a6faf
 
 
 
4da10da
2eefa69
91a6faf
4da10da
 
 
 
 
 
cccfea0
4da10da
91a6faf
 
 
2eefa69
 
cccfea0
91a6faf
4da10da
91a6faf
2eefa69
91a6faf
4da10da
91a6faf
 
 
4da10da
91a6faf
 
 
 
 
 
4da10da
 
 
91a6faf
 
4da10da
 
 
 
 
 
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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
import streamlit as st
import numpy as np
import cv2
from PIL import Image
import keras
from huggingface_hub import hf_hub_download

labels = ["angry", "disgust", "fear", "happy", "neutral", "sad", "surprise"]

st.set_page_config(page_title="Emotion AI", page_icon="🧠", layout="centered")

st.markdown("""
    <h1 style='text-align:center;'>🧠 Emotion Recognition AI</h1>
    <p style='text-align:center;'>Upload a face image to detect emotion</p>
""", unsafe_allow_html=True)

@st.cache_resource
def load_model():
    model_path = hf_hub_download(
        repo_id="fdfddfdsaassd/vgg19-emotion-recognition-ckplus-rafdb",
        filename="emotion_vgg19_model.h5"
    )
    return keras.models.load_model(model_path, compile=False)

model = load_model()

file = st.file_uploader("📤 Upload image", type=["jpg", "png", "jpeg"])

if file:
    img = Image.open(file)
    st.image(img, caption="Uploaded Image", use_container_width=True)

    img = np.array(img)

    if img.shape[-1] == 4:
        img = cv2.cvtColor(img, cv2.COLOR_RGBA2RGB)

    img = cv2.resize(img, (224, 224))
    img = img / 255.0
    img = np.expand_dims(img, axis=0)

    pred = model.predict(img)[0]
    idx = np.argmax(pred)

    st.markdown("---")
    st.markdown(f"## 😶 Prediction: **{labels[idx]}**")

    st.bar_chart(pred)