model-temp-api / app.py
nataliegref's picture
Add missing line
e5ee678
Raw
History Blame
571 Bytes
from fastapi import FastAPI
from pydantic import BaseModel
import numpy as np
import pickle
from huggingface_hub import hf_hub_download
app = FastAPI()
# Download your model pickle from the Hub on startup
model_path = hf_hub_download(repo_id="Projects-by-IF/causal-model", filename="trained_causal_model_v2.pkl")
with open(model_path, "rb") as f:
model = pickle.load(f)
class InputData(BaseModel):
X: list
@app.post("/model-effect")
def predict(data: InputData):
X = np.array(data.X)
effect = model.effect(X).tolist()
return {"effect": effect}