Add app.py
Browse files
app.py
ADDED
@@ -0,0 +1,37 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from fastapi import FastAPI, File, UploadFile
|
2 |
+
from fastapi.middleware.cors import CORSMiddleware
|
3 |
+
import joblib
|
4 |
+
import pandas as pd
|
5 |
+
import numpy as np
|
6 |
+
|
7 |
+
app = FastAPI()
|
8 |
+
|
9 |
+
# Add CORS middleware
|
10 |
+
app.add_middleware(
|
11 |
+
CORSMiddleware,
|
12 |
+
allow_origins=["*"],
|
13 |
+
allow_credentials=True,
|
14 |
+
allow_methods=["*"],
|
15 |
+
allow_headers=["*"],
|
16 |
+
)
|
17 |
+
|
18 |
+
# Load the model
|
19 |
+
model = joblib.load('superkart_sales_model.joblib')
|
20 |
+
|
21 |
+
@app.get("/")
|
22 |
+
async def root():
|
23 |
+
return {"message": "SuperKart Sales Prediction API"}
|
24 |
+
|
25 |
+
@app.post("/predict")
|
26 |
+
async def predict(file: UploadFile = File(...)):
|
27 |
+
# Read the uploaded CSV file
|
28 |
+
df = pd.read_csv(file.file)
|
29 |
+
|
30 |
+
# Make predictions
|
31 |
+
predictions = model.predict(df)
|
32 |
+
|
33 |
+
return {"predictions": predictions.tolist()}
|
34 |
+
|
35 |
+
if __name__ == "__main__":
|
36 |
+
import uvicorn
|
37 |
+
uvicorn.run(app, host="0.0.0.0", port=8000)
|