Spaces:
Sleeping
Sleeping
File size: 1,690 Bytes
37fdc49 7c5425e 37fdc49 3b42acf 37fdc49 7c5425e 37fdc49 7c5425e 37fdc49 7c5425e 3b42acf |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
import joblib
import numpy as np
import pandas as pd
from flask import Flask, request, jsonify
superkart_api = Flask(__name__)
print("π Loading model...")
model = joblib.load("superkart_model.joblib")
print("β
Model loaded.")
@superkart_api.route("/", methods=["GET", "POST"])
def index():
print(f"π‘ Incoming {request.method} request to /")
if request.method == "POST":
try:
data = request.get_json(force=True)
print(f"π₯ Received JSON: {data}")
input_dict = {
"Product_Weight": data.get("Product_Weight", 0.0),
"Product_Sugar_Content": data.get("Product_Sugar_Content", "Regular"),
"Product_Allocated_Area": data.get("Product_Allocated_Area", 0.0),
"Product_Type": data.get("Product_Type", "Other"),
"Product_MRP": data.get("Product_MRP", 0.0),
"Store_Establishment_Year": data.get("Store_Establishment_Year", 2000),
"Store_Size": data.get("Store_Size", "Medium"),
"Store_Location_City_Type": data.get("Store_Location_City_Type", "Tier 2"),
"Store_Type": data.get("Store_Type", "Supermarket Type1")
}
input_df = pd.DataFrame([input_dict])
prediction = model.predict(input_df)
return jsonify({"prediction": float(prediction[0])})
except Exception as e:
print(f"β Error: {str(e)}")
return jsonify({"error": str(e)}), 400
else:
return "β
SuperKart API root: ready."
if __name__ == "__main__":
print("π Starting Flask server...")
superkart_api.run(host="0.0.0.0", port=7860)
|