Spaces:
Configuration error
Configuration error
celpri commited on
Commit ·
c51dbd9
1
Parent(s): 00b43a2
fix: bypass HF feature download during tests
Browse files- src/api/main.py +11 -7
src/api/main.py
CHANGED
|
@@ -13,15 +13,19 @@ class ClientID(BaseModel):
|
|
| 13 |
|
| 14 |
|
| 15 |
def get_features_by_id(sk_id_curr: int) -> pd.DataFrame:
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 21 |
|
| 22 |
-
df = pd.read_csv(path)
|
| 23 |
row = df[df["SK_ID_CURR"] == sk_id_curr]
|
| 24 |
-
|
| 25 |
if row.empty:
|
| 26 |
raise KeyError("Client not found")
|
| 27 |
|
|
|
|
| 13 |
|
| 14 |
|
| 15 |
def get_features_by_id(sk_id_curr: int) -> pd.DataFrame:
|
| 16 |
+
# CAS TEST / LOCAL : features injectées par le test
|
| 17 |
+
if hasattr(app.state, "features") and app.state.features is not None:
|
| 18 |
+
df = app.state.features
|
| 19 |
+
else:
|
| 20 |
+
# CAS PROD HF
|
| 21 |
+
path = hf_hub_download(
|
| 22 |
+
repo_id="PCelia/credit-scoring-model",
|
| 23 |
+
filename="features_clients.csv",
|
| 24 |
+
token=os.environ.get("HF_TOKEN")
|
| 25 |
+
)
|
| 26 |
+
df = pd.read_csv(path)
|
| 27 |
|
|
|
|
| 28 |
row = df[df["SK_ID_CURR"] == sk_id_curr]
|
|
|
|
| 29 |
if row.empty:
|
| 30 |
raise KeyError("Client not found")
|
| 31 |
|