Fair3 commited on
Commit
7e8684a
·
verified ·
1 Parent(s): 011848c

Upload folder using huggingface_hub

Browse files
Files changed (3) hide show
  1. app.py +5 -5
  2. model.joblib +2 -2
  3. preprocessor.joblib +2 -2
app.py CHANGED
@@ -14,7 +14,7 @@ superkart_api = Flask("superkart_predictor")
14
  try:
15
  preprocessor_path = os.path.join(APP_DIR, "preprocessor.joblib")
16
  model_path = os.path.join(APP_DIR, "model.joblib")
17
-
18
  preprocessor = joblib.load(preprocessor_path)
19
  model = joblib.load(model_path)
20
  print("✅ Preprocessor and model loaded successfully.")
@@ -31,7 +31,7 @@ def home():
31
  # Define an endpoint to predict sales
32
  @superkart_api.post('/v1/predict')
33
  def predict_sales():
34
-
35
  if preprocessor is None or model is None:
36
  return jsonify({"error": "Model or preprocessor not loaded"}), 500
37
 
@@ -55,7 +55,7 @@ def predict_sales():
55
  'Store_Type': data['Store_Type'],
56
  'Store_Age': data['Store_Age']
57
  }
58
-
59
  # Check if any mapping failed (resulted in None)
60
  if any(v is None for v in [sample['Product_Sugar_Content'], sample['Store_Size'], sample['Store_Location_City_Type']]):
61
  return jsonify({"error": "Invalid value for ordinal feature (e.g., 'Store_Size', 'Product_Sugar_Content')"}), 400
@@ -72,12 +72,12 @@ def predict_sales():
72
  try:
73
  # 1. Transform the now-mapped input data
74
  processed_data = preprocessor.transform(input_data)
75
-
76
  # 2. Make a prediction
77
  prediction = model.predict(processed_data).tolist()[0]
78
 
79
  return jsonify({'predicted_sales': round(prediction, 2)})
80
-
81
  except Exception as e:
82
  return jsonify({"error": f"Error during prediction: {str(e)}"}), 500
83
 
 
14
  try:
15
  preprocessor_path = os.path.join(APP_DIR, "preprocessor.joblib")
16
  model_path = os.path.join(APP_DIR, "model.joblib")
17
+
18
  preprocessor = joblib.load(preprocessor_path)
19
  model = joblib.load(model_path)
20
  print("✅ Preprocessor and model loaded successfully.")
 
31
  # Define an endpoint to predict sales
32
  @superkart_api.post('/v1/predict')
33
  def predict_sales():
34
+
35
  if preprocessor is None or model is None:
36
  return jsonify({"error": "Model or preprocessor not loaded"}), 500
37
 
 
55
  'Store_Type': data['Store_Type'],
56
  'Store_Age': data['Store_Age']
57
  }
58
+
59
  # Check if any mapping failed (resulted in None)
60
  if any(v is None for v in [sample['Product_Sugar_Content'], sample['Store_Size'], sample['Store_Location_City_Type']]):
61
  return jsonify({"error": "Invalid value for ordinal feature (e.g., 'Store_Size', 'Product_Sugar_Content')"}), 400
 
72
  try:
73
  # 1. Transform the now-mapped input data
74
  processed_data = preprocessor.transform(input_data)
75
+
76
  # 2. Make a prediction
77
  prediction = model.predict(processed_data).tolist()[0]
78
 
79
  return jsonify({'predicted_sales': round(prediction, 2)})
80
+
81
  except Exception as e:
82
  return jsonify({"error": f"Error during prediction: {str(e)}"}), 500
83
 
model.joblib CHANGED
@@ -1,3 +1,3 @@
1
  version https://git-lfs.github.com/spec/v1
2
- oid sha256:54aeda2ba7d11b49c070bf6e15f0a4dfdd1c4dace2a4a1a1c6805edab5a2bcf4
3
- size 472809
 
1
  version https://git-lfs.github.com/spec/v1
2
+ oid sha256:382f42f8024c4bc00bf800c5237fc8dfb4137d05a97d58d16af23bbf6727a32a
3
+ size 635913
preprocessor.joblib CHANGED
@@ -1,3 +1,3 @@
1
  version https://git-lfs.github.com/spec/v1
2
- oid sha256:6cc6ae7565037569fd6c94e73a4f64b865e0a29d078fb06f17603aed40112b2d
3
- size 3583
 
1
  version https://git-lfs.github.com/spec/v1
2
+ oid sha256:4a9c086d1e65f02274bf06abdf71d30e6635a57cb3e85451841878278861eda5
3
+ size 3969