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