Spaces:
Sleeping
Sleeping
Sammy Harris
commited on
Commit
·
2cf61e8
1
Parent(s):
9c029b4
Fix Gradio compatibility: remove deprecated @gr .cache and add model download from HF Hub
Browse files
app.py
CHANGED
|
@@ -3,15 +3,21 @@ import tensorflow as tf
|
|
| 3 |
import numpy as np
|
| 4 |
from PIL import Image
|
| 5 |
import cv2
|
|
|
|
| 6 |
|
| 7 |
# Load the model
|
| 8 |
-
@gr.cache
|
| 9 |
def load_model():
|
| 10 |
"""Load the age group classification model"""
|
| 11 |
try:
|
| 12 |
-
model
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 13 |
return model
|
| 14 |
-
except:
|
|
|
|
| 15 |
# Fallback if model file not found
|
| 16 |
return None
|
| 17 |
|
|
|
|
| 3 |
import numpy as np
|
| 4 |
from PIL import Image
|
| 5 |
import cv2
|
| 6 |
+
from huggingface_hub import hf_hub_download
|
| 7 |
|
| 8 |
# Load the model
|
|
|
|
| 9 |
def load_model():
|
| 10 |
"""Load the age group classification model"""
|
| 11 |
try:
|
| 12 |
+
# Download model from Hugging Face Hub
|
| 13 |
+
model_path = hf_hub_download(
|
| 14 |
+
repo_id="Sharris/age-group-classifier",
|
| 15 |
+
filename="resnet50v2_age_classifier_best.h5"
|
| 16 |
+
)
|
| 17 |
+
model = tf.keras.models.load_model(model_path)
|
| 18 |
return model
|
| 19 |
+
except Exception as e:
|
| 20 |
+
print(f"Error loading model: {e}")
|
| 21 |
# Fallback if model file not found
|
| 22 |
return None
|
| 23 |
|