fdfddfdsaassd commited on
Commit
2eefa69
·
verified ·
1 Parent(s): 27c1157

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +12 -23
app.py CHANGED
@@ -1,49 +1,38 @@
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)
 
 
 
 
1
  import streamlit as st
2
  import keras
3
  import numpy as np
4
  import cv2
5
  from PIL import Image
6
+ from huggingface_hub import hf_hub_download
7
 
8
  labels = ["angry","disgust","fear","happy","neutral","sad","surprise"]
9
 
10
  @st.cache_resource
11
  def load_model():
12
+ model_path = hf_hub_download(
13
+ repo_id="fdfddfdsaassd/vgg19-emotion-recognition-ckplus-rafdb",
14
+ filename="model.keras" # или model.h5 — СМОТРИ В РЕПО
15
  )
16
 
17
+ return keras.saving.load_model(model_path)
18
 
19
+ model = load_model()
 
20
 
21
+ st.title("🧠 Emotion AI")
 
 
 
22
 
23
+ file = st.file_uploader("Upload image")
24
 
25
  if file:
26
  img = Image.open(file)
27
+ st.image(img)
28
 
29
  img = np.array(img)
30
 
31
  if img.shape[-1] == 4:
32
  img = cv2.cvtColor(img, cv2.COLOR_RGBA2RGB)
33
 
34
+ img = cv2.resize(img, (224,224)) / 255.0
35
+ img = np.expand_dims(img, 0)
 
36
 
37
  pred = model.predict(img)[0]
38
+ st.write(labels[np.argmax(pred)])