File size: 646 Bytes
59edf2a
3ee223a
ee82622
6286030
 
670b0ed
 
 
ee82622
3ee223a
 
 
 
a27be5a
 
 
59edf2a
 
670b0ed
 
3ee223a
a27be5a
ee82622
 
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
from fastapi import FastAPI
import pandas as pd
import joblib
from huggingface_hub import hf_hub_download

app = FastAPI()

# Load model from HF repo
model_path = hf_hub_download(repo_id="danialsiddiqui/task6-model", filename="model.joblib")
model_data = joblib.load(model_path)
model = model_data["model"]
columns = model_data["columns"]

@app.get("/")
def home():
    return {"status": "API is running"}

@app.post("/predict")
def predict(data: dict):
    df = pd.DataFrame([data])
    df = pd.get_dummies(df)
    df = df.reindex(columns=columns, fill_value=0)
    prediction = model.predict(df)[0]
    return {"prediction": float(prediction)}