Spaces:
Runtime error
Runtime error
Download app.py from farooqdaniyal/backend-api: direct link, hf CLI and curl.
- Browser
- Download file 783 Bytes
-
https://huggingface.co/spaces/farooqdaniyal/backend-api/resolve/main/app.py
- Command line
-
hf download hf://spaces/farooqdaniyal/backend-api/app.py
-
curl -L -o app.py https://huggingface.co/spaces/farooqdaniyal/backend-api/resolve/main/app.py
783 Bytes
| from fastapi import FastAPI | |
| from pydantic import BaseModel | |
| import pickle | |
| import pandas as pd | |
| # load model | |
| with open('model.pkl', 'rb') as file: | |
| model = pickle.load(file) | |
| app = FastAPI() | |
| # define input schema | |
| class InputData(BaseModel): | |
| age: int | |
| workclass: str | |
| education: str | |
| marital_status: str | |
| occupation: str | |
| relationship: str | |
| race: str | |
| gender: str | |
| capital_gain: int | |
| capital_loss: int | |
| hours_per_week: int | |
| native_country: str | |
| def welcome_message(): | |
| return {"message": "Welcome to Model API"} | |
| def prediction(data: InputData): | |
| input_data = pd.DataFrame([data.dict()]) | |
| pred = model.predict(input_data) | |
| return {"prediction": pred[0]} |