abhishek-kumar's picture
Add app.py
25b5f91 verified
raw
history blame
845 Bytes
from fastapi import FastAPI, File, UploadFile
from fastapi.middleware.cors import CORSMiddleware
import joblib
import pandas as pd
import numpy as np
app = FastAPI()
# Add CORS middleware
app.add_middleware(
CORSMiddleware,
allow_origins=["*"],
allow_credentials=True,
allow_methods=["*"],
allow_headers=["*"],
)
# Load the model
model = joblib.load('superkart_sales_model.joblib')
@app.get("/")
async def root():
return {"message": "SuperKart Sales Prediction API"}
@app.post("/predict")
async def predict(file: UploadFile = File(...)):
# Read the uploaded CSV file
df = pd.read_csv(file.file)
# Make predictions
predictions = model.predict(df)
return {"predictions": predictions.tolist()}
if __name__ == "__main__":
import uvicorn
uvicorn.run(app, host="0.0.0.0", port=8000)