A commited on
Upload folder using huggingface_hub
Browse files
app.py
CHANGED
|
@@ -52,11 +52,15 @@ def predict_sales():
|
|
| 52 |
# Make prediction (get log_price)
|
| 53 |
predicted_log_price = model.predict(input_data)[0]
|
| 54 |
|
|
|
|
|
|
|
|
|
|
| 55 |
# Calculate actual price
|
| 56 |
-
predicted_price = np.exp(
|
| 57 |
|
| 58 |
# Convert predicted_price to Python float
|
| 59 |
predicted_price = round(float(predicted_price), 2)
|
|
|
|
| 60 |
# 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.
|
| 61 |
# When we send this value directly within a JSON response, Flask's jsonify function encounters a datatype error
|
| 62 |
|
|
|
|
| 52 |
# Make prediction (get log_price)
|
| 53 |
predicted_log_price = model.predict(input_data)[0]
|
| 54 |
|
| 55 |
+
# Clip log price to avoid overflow
|
| 56 |
+
safe_log_price = np.clip(predicted_log_price, a_min=None, a_max=700)
|
| 57 |
+
|
| 58 |
# Calculate actual price
|
| 59 |
+
predicted_price = np.exp(safe_log_price)
|
| 60 |
|
| 61 |
# Convert predicted_price to Python float
|
| 62 |
predicted_price = round(float(predicted_price), 2)
|
| 63 |
+
|
| 64 |
# 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.
|
| 65 |
# When we send this value directly within a JSON response, Flask's jsonify function encounters a datatype error
|
| 66 |
|