romanus-iii commited on
Commit
7c5425e
Β·
verified Β·
1 Parent(s): d646f8d

Upload folder using huggingface_hub

Browse files
Files changed (1) hide show
  1. app.py +33 -20
app.py CHANGED
@@ -1,29 +1,42 @@
1
 
 
 
 
2
  from flask import Flask, request, jsonify
3
 
4
  superkart_api = Flask(__name__)
5
 
6
- @superkart_api.route("/", methods=["GET", "POST", "PUT", "DELETE", "OPTIONS"])
7
- @superkart_api.route("/predict", methods=["GET", "POST", "PUT", "DELETE", "OPTIONS"])
8
- @superkart_api.route("/test", methods=["GET", "POST", "PUT", "DELETE", "OPTIONS"])
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
- print(f"πŸ“‘ {method} request to {path}")
18
- print(f"πŸ“₯ Payload: {json_data}")
19
-
20
- return jsonify({
21
- "status": "received",
22
- "method": method,
23
- "path": path,
24
- "payload": json_data
25
- })
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
26
 
27
  if __name__ == "__main__":
28
- print("πŸš€ Starting universal logger Flask server")
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)