Johnnyyyyy56 commited on
Commit
e7681ed
·
verified ·
1 Parent(s): d640e7d

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +35 -0
app.py CHANGED
@@ -6,6 +6,41 @@ import cv2
6
  import gradio as gr
7
  from deepface import DeepFace
8
  import time
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
9
 
10
  # Emotion mapping with emojis
11
  EMOJI_MAP = {
 
6
  import gradio as gr
7
  from deepface import DeepFace
8
  import time
9
+ import numpy as np
10
+
11
+ # ======== ADD THE MODEL CHECK HERE ========
12
+ def check_models():
13
+ model_path = os.path.join(DeepFace.get_deepface_home(), "weights")
14
+ print("\n=== Model Verification ===")
15
+
16
+ if not os.path.exists(model_path):
17
+ print("❌ Model directory doesn't exist!")
18
+ return False
19
+
20
+ files = os.listdir(model_path)
21
+ print(f"Found {len(files)} files in {model_path}:")
22
+ for f in files:
23
+ print(f"- {f}")
24
+
25
+ emotion_model = "facial_expression_model_weights.h5"
26
+ has_emotion_model = emotion_model in files
27
+ print(f"\nEmotion model present? {'✅' if has_emotion_model else '❌'}")
28
+ return has_emotion_model
29
+
30
+ # Force model download if missing
31
+ if not check_models():
32
+ print("\n⚠️ Downloading missing models...")
33
+ try:
34
+ DeepFace.analyze(
35
+ img_path=np.zeros((48, 48, 3), # Dummy image
36
+ actions=['emotion'],
37
+ enforce_detection=False,
38
+ silent=False
39
+ )
40
+ check_models() # Verify after download
41
+ except Exception as e:
42
+ print(f"❌ Model download failed: {str(e)}")
43
+ # ======== END OF MODEL CHECK ========
44
 
45
  # Emotion mapping with emojis
46
  EMOJI_MAP = {