Spaces:
Runtime error
Runtime error
Update app.py
Browse files12312345678910111415121314151618171820211920232425262122282324252632272829303132333940413435363744454647484938import osos.environ["KERAS_BACKEND"] = "jax"
import streamlit as stimport kerasimport numpy as npimport cv2from PIL import Imagefrom huggingface_hub import hf_hub_download
labels = ["angry","disgust","fear","happy","neutral","sad","surprise"]
@st.cache_resourcedef load_model(): return keras.saving.load_model( "hf://fdfddfdsaassd/vgg19-emotion-recognition-ckplus-rafdb" model_path = hf_hub_download( repo_id="fdfddfdsaassd/vgg19-emotion-recognition-ckplus-rafdb", filename="model.keras" # или model.h5 — СМОТРИ В РЕПО )
model = load_model() return keras.saving.load_model(model_path)
# UI DESIGNst.set_page_config(page_title="Emotion AI", page_icon="🧠", layout="centered")model = load_model()
st.markdown(""" <h1 style='text-align:center; color:#6C63FF;'>🧠 Emotion AI Detector</h1> <p style='text-align:center;'>Upload a face image and detect emotion using VGG19 (RAF-DB + CK+)</p>""", unsafe_allow_html=True)st.title("🧠 Emotion AI")
file = st.file_uploader("📤 Upload image", type=["jpg","png","jpeg"])file = st.file_uploader("Upload image")
if file: img = Image.open(file) st.image(img, caption="Uploaded Image", use_container_width=True) st.image(img)
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) img = cv2.resize(img, (224,224)) / 255.0 img = np.expand_dims(img, 0)
pred = model.predict(img)[0] idx = np.argmax(pred)
st.markdown("---") st.markdown(f"### 😶 Prediction: **{labels[idx]}**")
st.bar_chart(pred) st.write(labels[np.argmax(pred)])app.py+12-23