Spaces:
Sleeping
Sleeping
| 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) | |
| 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) |