Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -142,18 +142,48 @@ def load_results():
|
|
| 142 |
Load latest artifacts from artifacts/py and artifacts/r.
|
| 143 |
Returns values in the order used by the Gradio outputs.
|
| 144 |
"""
|
|
|
|
|
|
|
| 145 |
# Python artifacts
|
| 146 |
-
|
| 147 |
-
|
| 148 |
-
|
| 149 |
-
|
| 150 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 151 |
|
|
|
|
| 152 |
# R artifacts
|
| 153 |
-
|
| 154 |
-
|
| 155 |
-
|
| 156 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 157 |
|
| 158 |
return py_metrics, r_metrics, py_conf, py_roc, r_roc, py_fi, r_coef, py_pred, r_pred
|
| 159 |
|
|
|
|
| 142 |
Load latest artifacts from artifacts/py and artifacts/r.
|
| 143 |
Returns values in the order used by the Gradio outputs.
|
| 144 |
"""
|
| 145 |
+
|
| 146 |
+
# --------------------
|
| 147 |
# Python artifacts
|
| 148 |
+
# --------------------
|
| 149 |
+
py_metrics = _safe_read_json(BASE_DIR / "artifacts" / "py" / "metrics" / "metrics.json")
|
| 150 |
+
if py_metrics is None:
|
| 151 |
+
py_metrics = {}
|
| 152 |
+
|
| 153 |
+
py_conf_path = BASE_DIR / "artifacts" / "py" / "figures" / "confusion_matrix.png"
|
| 154 |
+
py_roc_path = BASE_DIR / "artifacts" / "py" / "figures" / "roc_curve.png"
|
| 155 |
+
|
| 156 |
+
py_fi = _safe_read_csv(BASE_DIR / "artifacts" / "py" / "tables" / "feature_importances.csv")
|
| 157 |
+
if py_fi is None:
|
| 158 |
+
py_fi = pd.DataFrame()
|
| 159 |
+
|
| 160 |
+
py_pred = _safe_read_csv(BASE_DIR / "artifacts" / "py" / "tables" / "test_predictions.csv", nrows=50)
|
| 161 |
+
if py_pred is None:
|
| 162 |
+
py_pred = pd.DataFrame()
|
| 163 |
|
| 164 |
+
# --------------------
|
| 165 |
# R artifacts
|
| 166 |
+
# --------------------
|
| 167 |
+
r_metrics = _safe_read_json(BASE_DIR / "artifacts" / "r" / "metrics" / "metrics.json")
|
| 168 |
+
if r_metrics is None:
|
| 169 |
+
r_metrics = {}
|
| 170 |
+
|
| 171 |
+
r_roc_path = BASE_DIR / "artifacts" / "r" / "figures" / "roc_curve.png"
|
| 172 |
+
|
| 173 |
+
r_coef = _safe_read_csv(BASE_DIR / "artifacts" / "r" / "tables" / "coefficients.csv", nrows=50)
|
| 174 |
+
if r_coef is None:
|
| 175 |
+
r_coef = pd.DataFrame()
|
| 176 |
+
|
| 177 |
+
r_pred = _safe_read_csv(BASE_DIR / "artifacts" / "r" / "tables" / "test_predictions.csv", nrows=50)
|
| 178 |
+
if r_pred is None:
|
| 179 |
+
r_pred = pd.DataFrame()
|
| 180 |
+
|
| 181 |
+
# Gradio Image(type="filepath") works best with:
|
| 182 |
+
# - a string path if the file exists
|
| 183 |
+
# - None if it does not exist
|
| 184 |
+
py_conf = str(py_conf_path) if py_conf_path.exists() else None
|
| 185 |
+
py_roc = str(py_roc_path) if py_roc_path.exists() else None
|
| 186 |
+
r_roc = str(r_roc_path) if r_roc_path.exists() else None
|
| 187 |
|
| 188 |
return py_metrics, r_metrics, py_conf, py_roc, r_roc, py_fi, r_coef, py_pred, r_pred
|
| 189 |
|