A commited on
Upload folder using huggingface_hub
Browse files
app.py
CHANGED
|
@@ -40,26 +40,26 @@ input_data = pd.DataFrame([{
|
|
| 40 |
'Store_Establishment_Year': store_establishment_year
|
| 41 |
}])
|
| 42 |
|
| 43 |
-
|
| 44 |
-
# if st.button("Predict"):
|
| 45 |
-
# response = requests.post("https://Swetha2031-SuperKartSalesPredictionBackend.hf.space/v1/salestotal", json=input_data.to_dict(orient='records')[0])
|
| 46 |
-
# if response.status_code == 200:
|
| 47 |
-
# prediction = response.json()['Predicted Sales (₹)']
|
| 48 |
-
# st.success(f"Predicted Product Sales: ₹{prediction}")
|
| 49 |
-
# else:
|
| 50 |
-
# st.error("Error making prediction.")
|
| 51 |
if st.button("Predict"):
|
| 52 |
response = requests.post("https://Swetha2031-SuperKartSalesPredictionBackend.hf.space/v1/salestotal", json=input_data.to_dict(orient='records')[0])
|
| 53 |
if response.status_code == 200:
|
| 54 |
-
|
| 55 |
-
|
| 56 |
-
st.write("Raw response:", result) # Optional: for debugging
|
| 57 |
-
prediction = result.get('Predicted Sales (₹)', 'No prediction returned')
|
| 58 |
-
st.success(f"Predicted Product Sales: ₹{prediction}")
|
| 59 |
-
except Exception as e:
|
| 60 |
-
st.error(f"Error parsing prediction: {e}")
|
| 61 |
else:
|
| 62 |
st.error("Error making prediction.")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 63 |
|
| 64 |
|
| 65 |
# Section for batch prediction
|
|
@@ -78,3 +78,26 @@ if uploaded_file is not None:
|
|
| 78 |
st.write(predictions)
|
| 79 |
else:
|
| 80 |
st.error("Error making batch prediction.")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 40 |
'Store_Establishment_Year': store_establishment_year
|
| 41 |
}])
|
| 42 |
|
| 43 |
+
Make prediction when the "Predict" button is clicked
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 44 |
if st.button("Predict"):
|
| 45 |
response = requests.post("https://Swetha2031-SuperKartSalesPredictionBackend.hf.space/v1/salestotal", json=input_data.to_dict(orient='records')[0])
|
| 46 |
if response.status_code == 200:
|
| 47 |
+
prediction = response.json()['Predicted Sales (₹)']
|
| 48 |
+
st.success(f"Predicted Product Sales: ₹{prediction}")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 49 |
else:
|
| 50 |
st.error("Error making prediction.")
|
| 51 |
+
# if st.button("Predict"):
|
| 52 |
+
# response = requests.post("https://Swetha2031-SuperKartSalesPredictionBackend.hf.space/v1/salestotal", json=input_data.to_dict(orient='records')[0])
|
| 53 |
+
# if response.status_code == 200:
|
| 54 |
+
# try:
|
| 55 |
+
# result = response.json()
|
| 56 |
+
# st.write("Raw response:", result) # Optional: for debugging
|
| 57 |
+
# prediction = result.get('Predicted Sales (₹)', 'No prediction returned')
|
| 58 |
+
# st.success(f"Predicted Product Sales: ₹{prediction}")
|
| 59 |
+
# except Exception as e:
|
| 60 |
+
# st.error(f"Error parsing prediction: {e}")
|
| 61 |
+
# else:
|
| 62 |
+
# st.error("Error making prediction.")
|
| 63 |
|
| 64 |
|
| 65 |
# Section for batch prediction
|
|
|
|
| 78 |
st.write(predictions)
|
| 79 |
else:
|
| 80 |
st.error("Error making batch prediction.")
|
| 81 |
+
|
| 82 |
+
# if uploaded_file is not None:
|
| 83 |
+
# if st.button("Predict Batch"):
|
| 84 |
+
# response = requests.post("https://Swetha2031-SuperKartSalesPredictionBackend.hf.space/v1/salesbatch",files={"file": uploaded_file})
|
| 85 |
+
|
| 86 |
+
# if response.status_code == 200:
|
| 87 |
+
# predictions = response.json()
|
| 88 |
+
|
| 89 |
+
# # Convert to DataFrame for inspection
|
| 90 |
+
# df_predictions = pd.DataFrame(predictions)
|
| 91 |
+
|
| 92 |
+
# # Check for overflow or invalid values
|
| 93 |
+
# if df_predictions.isin([float('inf'), float('nan')]).any().any():
|
| 94 |
+
# st.warning("Some predictions returned 'inf' or 'NaN' due to overflow. Please check input values.")
|
| 95 |
+
# elif (df_predictions.select_dtypes(include='number') > 1e10).any().any():
|
| 96 |
+
# st.warning("Some predictions are extremely large. This may indicate overflow or input scaling issues.")
|
| 97 |
+
|
| 98 |
+
# st.success("Batch predictions completed!")
|
| 99 |
+
# st.write(df_predictions)
|
| 100 |
+
|
| 101 |
+
# else:
|
| 102 |
+
# st.error("Error making batch prediction.")
|
| 103 |
+
|