Upload folder using huggingface_hub
Browse files
app.py
CHANGED
|
@@ -112,62 +112,30 @@ st.subheader("Batch Prediction")
|
|
| 112 |
|
| 113 |
st.write("Upload a CSV file with columns: Product_Weight, Product_Sugar_Content, Product_Allocated_Area, Product_Type, Product_MRP, Store_Establishment_Year, Store_Size, Store_Location_City_Type, Store_Type")
|
| 114 |
|
| 115 |
-
|
| 116 |
-
|
| 117 |
-
uploaded_file = st.file_uploader("Choose a CSV file", type=["csv"])
|
| 118 |
-
except Exception as e:
|
| 119 |
-
st.error("An unexpected error occurred during prediction.")
|
| 120 |
-
st.exception(e)
|
| 121 |
|
| 122 |
if uploaded_file is not None:
|
| 123 |
-
st.
|
| 124 |
-
|
| 125 |
-
|
| 126 |
-
|
| 127 |
-
input_df = pd.read_csv(uploaded_file)
|
| 128 |
-
st.write("Uploaded Data Preview:")
|
| 129 |
-
st.dataframe(input_df.head())
|
| 130 |
|
| 131 |
-
|
| 132 |
-
|
| 133 |
-
|
| 134 |
-
|
|
|
|
| 135 |
|
| 136 |
-
|
| 137 |
-
|
| 138 |
-
|
| 139 |
-
|
| 140 |
-
|
| 141 |
-
result = response.json()
|
| 142 |
-
predictions = result.get("predictions", None)
|
| 143 |
-
|
| 144 |
-
if predictions:
|
| 145 |
-
# Create DataFrame with predictions
|
| 146 |
-
output_df = input_df.copy()
|
| 147 |
-
output_df["Predicted_Sales"] = [float(p) for p in predictions]
|
| 148 |
-
|
| 149 |
-
# Display predictions
|
| 150 |
-
st.write("Batch Prediction Results:")
|
| 151 |
-
st.dataframe(output_df)
|
| 152 |
-
|
| 153 |
-
# Provide download button for results
|
| 154 |
-
csv_buffer = StringIO()
|
| 155 |
-
output_df.to_csv(csv_buffer, index=False)
|
| 156 |
-
st.download_button(
|
| 157 |
-
label="Download Predictions",
|
| 158 |
-
data=csv_buffer.getvalue(),
|
| 159 |
-
file_name="batch_predictions.csv",
|
| 160 |
-
mime="text/csv"
|
| 161 |
-
)
|
| 162 |
else:
|
| 163 |
-
st.error("
|
| 164 |
-
|
| 165 |
-
|
| 166 |
-
except ValueError:
|
| 167 |
-
st.error("Invalid response format from batch API")
|
| 168 |
-
except pd.errors.EmptyDataError:
|
| 169 |
-
st.error("Uploaded CSV is empty")
|
| 170 |
except Exception as e:
|
| 171 |
-
st.error(
|
| 172 |
-
|
| 173 |
-
st.error(f"Error reading CSV: {e}")
|
|
|
|
| 112 |
|
| 113 |
st.write("Upload a CSV file with columns: Product_Weight, Product_Sugar_Content, Product_Allocated_Area, Product_Type, Product_MRP, Store_Establishment_Year, Store_Size, Store_Location_City_Type, Store_Type")
|
| 114 |
|
| 115 |
+
# Allow users to upload a CSV file
|
| 116 |
+
uploaded_file = st.file_uploader("Upload CSV file for batch prediction", type=["csv"])
|
|
|
|
|
|
|
|
|
|
|
|
|
| 117 |
|
| 118 |
if uploaded_file is not None:
|
| 119 |
+
if st.button("Predict Batch"):
|
| 120 |
+
try:
|
| 121 |
+
# Prepare file payload correctly
|
| 122 |
+
files = {"file": (uploaded_file.name, uploaded_file, "text/csv")}
|
|
|
|
|
|
|
|
|
|
| 123 |
|
| 124 |
+
# Send the POST request to the Flask API
|
| 125 |
+
response = requests.post(
|
| 126 |
+
"https://sahilsingla-SuperKartPredictionBackend.hf.space/v1/salesbatch",
|
| 127 |
+
files=files
|
| 128 |
+
)
|
| 129 |
|
| 130 |
+
# Check response status
|
| 131 |
+
if response.status_code == 200:
|
| 132 |
+
predictions = response.json()
|
| 133 |
+
st.success("Batch predictions completed!")
|
| 134 |
+
st.write(predictions)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 135 |
else:
|
| 136 |
+
st.error(f"Error: {response.status_code}")
|
| 137 |
+
st.error(response.text)
|
| 138 |
+
|
|
|
|
|
|
|
|
|
|
|
|
|
| 139 |
except Exception as e:
|
| 140 |
+
st.error("An unexpected error occurred during prediction.")
|
| 141 |
+
st.exception(e)
|
|
|