ekmpa commited on
Commit
a261c86
·
verified ·
1 Parent(s): 9839e20

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +33 -0
app.py ADDED
@@ -0,0 +1,33 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from fastapi import FastAPI, HTTPException
2
+ from huggingface_hub import hf_hub_download
3
+ import pandas as pd
4
+
5
+ DATASET_REPO = "credi-net/CrediPred"
6
+ FILENAME = "mlpnfer_dec2024_pc1_embeddinggemma-300m_GNN-RNI.parquet"
7
+
8
+ app = FastAPI(title="CrediNet API")
9
+
10
+ lookup = {}
11
+
12
+ @app.on_event("startup")
13
+ def load_data():
14
+ global lookup
15
+ path = hf_hub_download(
16
+ repo_id=DATASET_REPO,
17
+ filename=FILENAME,
18
+ repo_type="dataset"
19
+ )
20
+ df = pd.read_parquet(path, columns=["domain", "pc1_score"])
21
+ lookup = dict(zip(df["domain"], df["pc1_score"]))
22
+ print(f"Loaded {len(lookup):,} rows")
23
+
24
+ @app.get("/health")
25
+ def health():
26
+ return {"status": "ok", "rows": len(lookup)}
27
+
28
+ @app.get("/score")
29
+ def get_score(domain: str):
30
+ score = lookup.get(domain)
31
+ if score is None:
32
+ raise HTTPException(status_code=404, detail="Domain not found")
33
+ return {"domain": domain, "pc1_score": float(score)}