Spaces:
Sleeping
Sleeping
yohannes-07
commited on
Commit
·
05062cc
1
Parent(s):
7ce58ad
fix main app
Browse files
app.py
CHANGED
|
@@ -47,6 +47,7 @@ async def load_resources():
|
|
| 47 |
repo_id="yohannes-07/lstm-blood-demand-predictor",
|
| 48 |
filename="lstm_blood_demand_v1_0.keras",
|
| 49 |
revision="main" ,
|
|
|
|
| 50 |
cache_dir='/app/.cache'
|
| 51 |
)
|
| 52 |
model = keras.models.load_model(model_path)
|
|
@@ -56,6 +57,7 @@ async def load_resources():
|
|
| 56 |
repo_id="yohannes-07/lstm-blood-demand-predictor",
|
| 57 |
filename="last_sequences.pkl",
|
| 58 |
revision="main",
|
|
|
|
| 59 |
cache_dir='/app/.cache'
|
| 60 |
)
|
| 61 |
with open(sequences_path, 'rb') as f:
|
|
@@ -66,6 +68,7 @@ async def load_resources():
|
|
| 66 |
repo_id="yohannes-07/lstm-blood-demand-predictor",
|
| 67 |
filename="feature_scaler.pkl",
|
| 68 |
revision="main",
|
|
|
|
| 69 |
cache_dir='/app/.cache'
|
| 70 |
)
|
| 71 |
with open(feature_scaler_path, 'rb') as f:
|
|
@@ -75,6 +78,7 @@ async def load_resources():
|
|
| 75 |
repo_id="yohannes-07/lstm-blood-demand-predictor",
|
| 76 |
filename="target_scaler.pkl",
|
| 77 |
revision="main",
|
|
|
|
| 78 |
cache_dir='/app/.cache'
|
| 79 |
)
|
| 80 |
with open(target_scaler_path, 'rb') as f:
|
|
@@ -115,6 +119,26 @@ def predict_next_n_days(last_sequence: np.ndarray, future_features: List[List[fl
|
|
| 115 |
|
| 116 |
return [int(round(x)) for x in real_predictions]
|
| 117 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 118 |
@app.post("/predict_all", response_model=PredictionResponse)
|
| 119 |
async def predict_all(request: PredictionRequest):
|
| 120 |
"""Predict blood demand for all hospital-blood group pairs"""
|
|
|
|
| 47 |
repo_id="yohannes-07/lstm-blood-demand-predictor",
|
| 48 |
filename="lstm_blood_demand_v1_0.keras",
|
| 49 |
revision="main" ,
|
| 50 |
+
force_download=True,
|
| 51 |
cache_dir='/app/.cache'
|
| 52 |
)
|
| 53 |
model = keras.models.load_model(model_path)
|
|
|
|
| 57 |
repo_id="yohannes-07/lstm-blood-demand-predictor",
|
| 58 |
filename="last_sequences.pkl",
|
| 59 |
revision="main",
|
| 60 |
+
force_download=True,
|
| 61 |
cache_dir='/app/.cache'
|
| 62 |
)
|
| 63 |
with open(sequences_path, 'rb') as f:
|
|
|
|
| 68 |
repo_id="yohannes-07/lstm-blood-demand-predictor",
|
| 69 |
filename="feature_scaler.pkl",
|
| 70 |
revision="main",
|
| 71 |
+
force_download=True,
|
| 72 |
cache_dir='/app/.cache'
|
| 73 |
)
|
| 74 |
with open(feature_scaler_path, 'rb') as f:
|
|
|
|
| 78 |
repo_id="yohannes-07/lstm-blood-demand-predictor",
|
| 79 |
filename="target_scaler.pkl",
|
| 80 |
revision="main",
|
| 81 |
+
force_download=True,
|
| 82 |
cache_dir='/app/.cache'
|
| 83 |
)
|
| 84 |
with open(target_scaler_path, 'rb') as f:
|
|
|
|
| 119 |
|
| 120 |
return [int(round(x)) for x in real_predictions]
|
| 121 |
|
| 122 |
+
@app.get("/")
|
| 123 |
+
async def root():
|
| 124 |
+
"""Default endpoint that provides API information"""
|
| 125 |
+
return {
|
| 126 |
+
"message": "Blood Demand Prediction API",
|
| 127 |
+
"endpoints": {
|
| 128 |
+
"predict_all": {
|
| 129 |
+
"method": "POST",
|
| 130 |
+
"path": "/predict_all",
|
| 131 |
+
"description": "Predict for multiple hospital-blood group pairs"
|
| 132 |
+
},
|
| 133 |
+
"predict_single": {
|
| 134 |
+
"method": "POST",
|
| 135 |
+
"path": "/predict_single",
|
| 136 |
+
"description": "Predict for a single hospital-blood group pair"
|
| 137 |
+
}
|
| 138 |
+
}
|
| 139 |
+
}
|
| 140 |
+
|
| 141 |
+
|
| 142 |
@app.post("/predict_all", response_model=PredictionResponse)
|
| 143 |
async def predict_all(request: PredictionRequest):
|
| 144 |
"""Predict blood demand for all hospital-blood group pairs"""
|