PatriciaWening commited on
Commit
eb2d0bb
·
verified ·
1 Parent(s): 1d19d3b

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +12 -8
app.py CHANGED
@@ -15,19 +15,23 @@ from huggingface_hub import hf_hub_download
15
 
16
  emotion_model = None
17
 
18
- model_path = hf_hub_download(
19
- repo_id="PatriciaWening/moodDetection",
20
- filename="moodDetection.keras",
21
- cache_dir="/tmp" # <-- tambahkan ini
22
- )
 
 
 
 
 
 
 
23
 
24
- emotion_model = model_path
25
  emotion_labels = ['angry', 'disgust', 'fear', 'happy', 'neutral', 'sad', 'surprise']
26
 
27
  face_cascade = cv2.CascadeClassifier(cv2.data.haarcascades + 'haarcascade_frontalface_default.xml')
28
 
29
- app = FastAPI()
30
-
31
  app.add_middleware(
32
  CORSMiddleware,
33
  allow_origins=["*"],
 
15
 
16
  emotion_model = None
17
 
18
+ app = FastAPI()
19
+
20
+ @app.on_event("startup")
21
+ def load_model():
22
+ global emotion_model
23
+ model_path = hf_hub_download(
24
+ repo_id="PatriciaWening/moodDetection",
25
+ filename="converted_model.keras", # pastikan sesuai
26
+ cache_dir="/tmp"
27
+ )
28
+ # ini akan assign objek keras.Model
29
+ emotion_model = keras.models.load_model(model_path)
30
 
 
31
  emotion_labels = ['angry', 'disgust', 'fear', 'happy', 'neutral', 'sad', 'surprise']
32
 
33
  face_cascade = cv2.CascadeClassifier(cv2.data.haarcascades + 'haarcascade_frontalface_default.xml')
34
 
 
 
35
  app.add_middleware(
36
  CORSMiddleware,
37
  allow_origins=["*"],