File size: 937 Bytes
a261c86
 
 
 
 
9e52e51
a261c86
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
fa6920b
 
a261c86
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
from fastapi import FastAPI, HTTPException
from huggingface_hub import hf_hub_download
import pandas as pd

DATASET_REPO = "credi-net/CrediPred"
FILENAME = "mlpInfer_dec2024_pc1_embeddinggemma-300m_GNN-RNI.parquet"

app = FastAPI(title="CrediNet API")

lookup = {}

@app.on_event("startup")
def load_data():
    global lookup
    path = hf_hub_download(
        repo_id=DATASET_REPO,
        filename=FILENAME,
        repo_type="dataset"
    )
    df = pd.read_parquet(path, columns=["domain", "pc1_score"])
    lookup = dict(zip(df["domain"], df["pc1_score"]))
    print(f"Loaded {len(lookup):,} rows")

@app.get("/health")
def health():
    return {"status": "ok", "rows": len(lookup)}

@app.get("/by_domain/{domain}")
def get_score_score(domain: str):
    score = lookup.get(domain)
    if score is None:
        raise HTTPException(status_code=404, detail="Domain not found")
    return {"domain": domain, "pc1_score": float(score)}