fdfddfdsaassd commited on
Commit
91a6faf
·
verified ·
1 Parent(s): fed6a2e

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +49 -0
app.py ADDED
@@ -0,0 +1,49 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import os
2
+ os.environ["KERAS_BACKEND"] = "jax"
3
+
4
+ import streamlit as st
5
+ import keras
6
+ import numpy as np
7
+ import cv2
8
+ from PIL import Image
9
+
10
+ labels = ["angry","disgust","fear","happy","neutral","sad","surprise"]
11
+
12
+ @st.cache_resource
13
+ def load_model():
14
+ return keras.saving.load_model(
15
+ "hf://fdfddfdsaassd/vgg19-emotion-recognition-ckplus-rafdb"
16
+ )
17
+
18
+ model = load_model()
19
+
20
+ # UI DESIGN
21
+ st.set_page_config(page_title="Emotion AI", page_icon="🧠", layout="centered")
22
+
23
+ st.markdown("""
24
+ <h1 style='text-align:center; color:#6C63FF;'>🧠 Emotion AI Detector</h1>
25
+ <p style='text-align:center;'>Upload a face image and detect emotion using VGG19 (RAF-DB + CK+)</p>
26
+ """, unsafe_allow_html=True)
27
+
28
+ file = st.file_uploader("📤 Upload image", type=["jpg","png","jpeg"])
29
+
30
+ if file:
31
+ img = Image.open(file)
32
+ st.image(img, caption="Uploaded Image", use_container_width=True)
33
+
34
+ img = np.array(img)
35
+
36
+ if img.shape[-1] == 4:
37
+ img = cv2.cvtColor(img, cv2.COLOR_RGBA2RGB)
38
+
39
+ img = cv2.resize(img, (224,224))
40
+ img = img / 255.0
41
+ img = np.expand_dims(img, axis=0)
42
+
43
+ pred = model.predict(img)[0]
44
+ idx = np.argmax(pred)
45
+
46
+ st.markdown("---")
47
+ st.markdown(f"### 😶 Prediction: **{labels[idx]}**")
48
+
49
+ st.bar_chart(pred)