Spaces:
Sleeping
Sleeping
Upload streamlit_app.py
Browse files- src/streamlit_app.py +9 -6
src/streamlit_app.py
CHANGED
|
@@ -11,6 +11,11 @@ import tensorflow.keras.backend as K
|
|
| 11 |
from huggingface_hub import hf_hub_download
|
| 12 |
import os
|
| 13 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 14 |
# === Custom Metric ===
|
| 15 |
def pearson_corr(y_true, y_pred):
|
| 16 |
x = y_true - K.mean(y_true)
|
|
@@ -18,19 +23,17 @@ def pearson_corr(y_true, y_pred):
|
|
| 18 |
return K.sum(x * y) / (K.sqrt(K.sum(K.square(x))) * K.sqrt(K.sum(K.square(y))) + K.epsilon())
|
| 19 |
|
| 20 |
# === Load model and scaler ===
|
| 21 |
-
# β
Force cache to local writable directory
|
| 22 |
-
os.makedirs("./hf_home/hub_cache", exist_ok=True)
|
| 23 |
-
os.environ["HF_HOME"] = "./hf_home"
|
| 24 |
-
os.environ["HF_HUB_CACHE"] = "./hf_home/hub_cache"
|
| 25 |
|
| 26 |
model_path = hf_hub_download(
|
| 27 |
repo_id="jiinkwan/bmi-model", # π This should match your new model repo
|
| 28 |
-
filename="bmi_model_gender.keras"
|
|
|
|
| 29 |
)
|
| 30 |
|
| 31 |
scaler_path = hf_hub_download(
|
| 32 |
repo_id="jiinkwan/bmi-model", # π This should match your new model repo
|
| 33 |
-
filename="label_scaler.keras"
|
|
|
|
| 34 |
)
|
| 35 |
|
| 36 |
model = tf.keras.models.load_model(model_path, custom_objects={'pearson_corr': pearson_corr})
|
|
|
|
| 11 |
from huggingface_hub import hf_hub_download
|
| 12 |
import os
|
| 13 |
|
| 14 |
+
# β
Safe directory for Spaces
|
| 15 |
+
os.environ["HF_HOME"] = "/tmp/hf_home"
|
| 16 |
+
os.environ["HF_HUB_CACHE"] = "/tmp/hf_home/hub_cache"
|
| 17 |
+
os.environ["MPLCONFIGDIR"] = "/tmp/matplotlib"
|
| 18 |
+
|
| 19 |
# === Custom Metric ===
|
| 20 |
def pearson_corr(y_true, y_pred):
|
| 21 |
x = y_true - K.mean(y_true)
|
|
|
|
| 23 |
return K.sum(x * y) / (K.sqrt(K.sum(K.square(x))) * K.sqrt(K.sum(K.square(y))) + K.epsilon())
|
| 24 |
|
| 25 |
# === Load model and scaler ===
|
|
|
|
|
|
|
|
|
|
|
|
|
| 26 |
|
| 27 |
model_path = hf_hub_download(
|
| 28 |
repo_id="jiinkwan/bmi-model", # π This should match your new model repo
|
| 29 |
+
filename="bmi_model_gender.keras",
|
| 30 |
+
repo_type="space"
|
| 31 |
)
|
| 32 |
|
| 33 |
scaler_path = hf_hub_download(
|
| 34 |
repo_id="jiinkwan/bmi-model", # π This should match your new model repo
|
| 35 |
+
filename="label_scaler.keras",
|
| 36 |
+
repo_type="space"
|
| 37 |
)
|
| 38 |
|
| 39 |
model = tf.keras.models.load_model(model_path, custom_objects={'pearson_corr': pearson_corr})
|