anithajk commited on
Commit
3444363
·
verified ·
1 Parent(s): 053337f

Upload folder using huggingface_hub

Browse files
Files changed (1) hide show
  1. app.py +4 -3
app.py CHANGED
@@ -48,12 +48,13 @@ def predict_product_sales():
48
  # Make prediction (get Product_Store_Sales_Total)
49
  predicted_Product_Store_Sales_Total = model.predict(input_data)[0]
50
  print(f"Predicted Product_Store_Sales_Total: {predicted_Product_Store_Sales_Total}")
51
-
52
- # Calculate actual price
53
- predicted_price = np.exp(predicted_Product_Store_Sales_Total)
54
 
55
  # Convert predicted_price to Python float
56
  predicted_price = round(float(predicted_price), 2)
 
57
  # The conversion above is needed as we convert the model prediction (log price) to actual price using np.exp, which returns predictions as NumPy float32 values.
58
  # When we send this value directly within a JSON response, Flask's jsonify function encounters a datatype error
59
 
 
48
  # Make prediction (get Product_Store_Sales_Total)
49
  predicted_Product_Store_Sales_Total = model.predict(input_data)[0]
50
  print(f"Predicted Product_Store_Sales_Total: {predicted_Product_Store_Sales_Total}")
51
+
52
+ # Calculate actual price safely (avoid overflow)
53
+ predicted_price = np.exp(np.clip(predicted_Product_Store_Sales_Total, -100, 100))
54
 
55
  # Convert predicted_price to Python float
56
  predicted_price = round(float(predicted_price), 2)
57
+
58
  # The conversion above is needed as we convert the model prediction (log price) to actual price using np.exp, which returns predictions as NumPy float32 values.
59
  # When we send this value directly within a JSON response, Flask's jsonify function encounters a datatype error
60