Spaces:
Sleeping
Sleeping
surbi karki commited on
Update app.py
Browse files
app.py
CHANGED
|
@@ -2,7 +2,6 @@ import os
|
|
| 2 |
import json
|
| 3 |
import uvicorn
|
| 4 |
import pandas as pd
|
| 5 |
-
import numpy as np
|
| 6 |
from fastapi import FastAPI, HTTPException
|
| 7 |
from fastapi.middleware.cors import CORSMiddleware
|
| 8 |
from pydantic import BaseModel, ConfigDict
|
|
@@ -33,7 +32,7 @@ app.add_middleware(
|
|
| 33 |
# ==========================================
|
| 34 |
|
| 35 |
BASE_DIR = os.path.dirname(os.path.abspath(__file__))
|
| 36 |
-
ARTIFACTS_DIR = os.path.
|
| 37 |
|
| 38 |
print("ARTIFACTS DIR:", ARTIFACTS_DIR)
|
| 39 |
print("EXISTS:", os.path.exists(ARTIFACTS_DIR))
|
|
@@ -56,17 +55,22 @@ try:
|
|
| 56 |
|
| 57 |
# B. Load Metadata
|
| 58 |
meta_path = os.path.join(ARTIFACTS_DIR, "catboost_metadata.json")
|
|
|
|
|
|
|
|
|
|
| 59 |
with open(meta_path, "r") as f:
|
| 60 |
metadata = json.load(f)
|
| 61 |
|
| 62 |
-
|
| 63 |
-
|
| 64 |
-
THRESHOLD = metadata["thresholds"]["optimal_balanced"]
|
| 65 |
|
| 66 |
print(f" Metadata Loaded. Threshold set to: {THRESHOLD}")
|
| 67 |
|
| 68 |
# C. Load UI Schema
|
| 69 |
ui_path = os.path.join(ARTIFACTS_DIR, "model_ui_schema.json")
|
|
|
|
|
|
|
|
|
|
| 70 |
with open(ui_path, "r") as f:
|
| 71 |
ui_schema = json.load(f)
|
| 72 |
print(" UI Schema Loaded.")
|
|
|
|
| 2 |
import json
|
| 3 |
import uvicorn
|
| 4 |
import pandas as pd
|
|
|
|
| 5 |
from fastapi import FastAPI, HTTPException
|
| 6 |
from fastapi.middleware.cors import CORSMiddleware
|
| 7 |
from pydantic import BaseModel, ConfigDict
|
|
|
|
| 32 |
# ==========================================
|
| 33 |
|
| 34 |
BASE_DIR = os.path.dirname(os.path.abspath(__file__))
|
| 35 |
+
ARTIFACTS_DIR = os.path.join(BASE_DIR, "artifacts_final") # Hugging Face compatible path
|
| 36 |
|
| 37 |
print("ARTIFACTS DIR:", ARTIFACTS_DIR)
|
| 38 |
print("EXISTS:", os.path.exists(ARTIFACTS_DIR))
|
|
|
|
| 55 |
|
| 56 |
# B. Load Metadata
|
| 57 |
meta_path = os.path.join(ARTIFACTS_DIR, "catboost_metadata.json")
|
| 58 |
+
if not os.path.exists(meta_path):
|
| 59 |
+
raise FileNotFoundError(f"Metadata not found at {meta_path}")
|
| 60 |
+
|
| 61 |
with open(meta_path, "r") as f:
|
| 62 |
metadata = json.load(f)
|
| 63 |
|
| 64 |
+
TOP_FEATURES = metadata.get("features_used", [])
|
| 65 |
+
THRESHOLD = metadata.get("thresholds", {}).get("optimal_balanced", 0.5)
|
|
|
|
| 66 |
|
| 67 |
print(f" Metadata Loaded. Threshold set to: {THRESHOLD}")
|
| 68 |
|
| 69 |
# C. Load UI Schema
|
| 70 |
ui_path = os.path.join(ARTIFACTS_DIR, "model_ui_schema.json")
|
| 71 |
+
if not os.path.exists(ui_path):
|
| 72 |
+
raise FileNotFoundError(f"UI schema not found at {ui_path}")
|
| 73 |
+
|
| 74 |
with open(ui_path, "r") as f:
|
| 75 |
ui_schema = json.load(f)
|
| 76 |
print(" UI Schema Loaded.")
|