Spaces:
Sleeping
Sleeping
Upload folder using huggingface_hub
Browse files
app.py
CHANGED
|
@@ -1,7 +1,7 @@
|
|
| 1 |
import joblib
|
| 2 |
import numpy as np
|
| 3 |
import pandas as pd
|
| 4 |
-
from fastapi import FastAPI
|
| 5 |
|
| 6 |
superkart_api = FastAPI(title="Superkart Sales Prediction",
|
| 7 |
description="API for predicting Superkart sales",
|
|
@@ -14,20 +14,20 @@ def home():
|
|
| 14 |
return "Welcome to SuperKart Sales Prediction API!"
|
| 15 |
|
| 16 |
@superkart_api.post('/v1/superkart_single')
|
| 17 |
-
def salepred_single():
|
| 18 |
-
sales_data = request.
|
| 19 |
|
| 20 |
# Read input data
|
| 21 |
sample = {
|
| 22 |
-
'Product_Weight':
|
| 23 |
-
'Product_Sugar_Content':
|
| 24 |
-
'Product_Allocated_Area':
|
| 25 |
-
'Product_Type':
|
| 26 |
-
'Product_MRP':
|
| 27 |
-
'Store_Id':
|
| 28 |
-
'Store_Size':
|
| 29 |
-
'Store_Location_City_Type':
|
| 30 |
-
'Store_Type':
|
| 31 |
|
| 32 |
}
|
| 33 |
input_data = pd.DataFrame([sample])
|
|
@@ -37,15 +37,13 @@ def salepred_single():
|
|
| 37 |
|
| 38 |
# Create response
|
| 39 |
response = {'Store_Outlet':sample['Store_Id'],"Sale":round(float(predicted_sale), 2)}
|
| 40 |
-
return
|
| 41 |
|
| 42 |
@superkart_api.post('/v1/superkart_batch')
|
| 43 |
-
def salepred_batch():
|
| 44 |
-
file = request.files['file']
|
| 45 |
-
print("File Received:", file.filename)
|
| 46 |
|
| 47 |
# Read input data
|
| 48 |
-
input_data = pd.read_csv(file)
|
| 49 |
|
| 50 |
# Make predictions
|
| 51 |
predicted_sale = model.predict(input_data).tolist()
|
|
@@ -62,10 +60,4 @@ def salepred_batch():
|
|
| 62 |
}
|
| 63 |
print("Final Response:", response)
|
| 64 |
|
| 65 |
-
return
|
| 66 |
-
|
| 67 |
-
|
| 68 |
-
|
| 69 |
-
|
| 70 |
-
if __name__=='__main__':
|
| 71 |
-
superkart_api.run()
|
|
|
|
| 1 |
import joblib
|
| 2 |
import numpy as np
|
| 3 |
import pandas as pd
|
| 4 |
+
from fastapi import FastAPI, Request, UploadFile, File
|
| 5 |
|
| 6 |
superkart_api = FastAPI(title="Superkart Sales Prediction",
|
| 7 |
description="API for predicting Superkart sales",
|
|
|
|
| 14 |
return "Welcome to SuperKart Sales Prediction API!"
|
| 15 |
|
| 16 |
@superkart_api.post('/v1/superkart_single')
|
| 17 |
+
async def salepred_single(request: Request):
|
| 18 |
+
sales_data = await request.json()
|
| 19 |
|
| 20 |
# Read input data
|
| 21 |
sample = {
|
| 22 |
+
'Product_Weight':sales_data['Product_Weight'],
|
| 23 |
+
'Product_Sugar_Content':sales_data['Product_Sugar_Content'],
|
| 24 |
+
'Product_Allocated_Area':sales_data['Product_Allocated_Area'],
|
| 25 |
+
'Product_Type':sales_data['Product_Type'],
|
| 26 |
+
'Product_MRP':sales_data['Product_MRP'],
|
| 27 |
+
'Store_Id':sales_data['Store_Id'],
|
| 28 |
+
'Store_Size':sales_data['Store_Size'],
|
| 29 |
+
'Store_Location_City_Type':sales_data['Store_Location_City_Type'],
|
| 30 |
+
'Store_Type':sales_data['Store_Type'],
|
| 31 |
|
| 32 |
}
|
| 33 |
input_data = pd.DataFrame([sample])
|
|
|
|
| 37 |
|
| 38 |
# Create response
|
| 39 |
response = {'Store_Outlet':sample['Store_Id'],"Sale":round(float(predicted_sale), 2)}
|
| 40 |
+
return response
|
| 41 |
|
| 42 |
@superkart_api.post('/v1/superkart_batch')
|
| 43 |
+
async def salepred_batch(file: UploadFile = File(...)):
|
|
|
|
|
|
|
| 44 |
|
| 45 |
# Read input data
|
| 46 |
+
input_data = pd.read_csv(file.file)
|
| 47 |
|
| 48 |
# Make predictions
|
| 49 |
predicted_sale = model.predict(input_data).tolist()
|
|
|
|
| 60 |
}
|
| 61 |
print("Final Response:", response)
|
| 62 |
|
| 63 |
+
return response
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|