Spaces:
Runtime error
Runtime error
Download app.py from danialsiddiqui/nexus-task6-api: direct link, hf CLI and curl.
- Browser
- Download file 646 Bytes
-
https://huggingface.co/spaces/danialsiddiqui/nexus-task6-api/resolve/main/app.py
- Command line
-
hf download hf://spaces/danialsiddiqui/nexus-task6-api/app.py
-
curl -L -o app.py https://huggingface.co/spaces/danialsiddiqui/nexus-task6-api/resolve/main/app.py
646 Bytes
| 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"] | |
| def home(): | |
| return {"status": "API is running"} | |
| 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)} | |