Spaces:
Sleeping
Sleeping
Upload folder using huggingface_hub
Browse files
app.py
CHANGED
|
@@ -45,6 +45,29 @@ if st.button("Predict Sales"):
|
|
| 45 |
|
| 46 |
#Batch Prediction
|
| 47 |
uploaded_file = st.file_uploader("Upload CSV file", type=["csv"])
|
| 48 |
-
st.write("All good")
|
| 49 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 50 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 45 |
|
| 46 |
#Batch Prediction
|
| 47 |
uploaded_file = st.file_uploader("Upload CSV file", type=["csv"])
|
|
|
|
| 48 |
|
| 49 |
+
if st.button("Predict for Batch"):
|
| 50 |
+
if uploaded_file is not None:
|
| 51 |
+
try:
|
| 52 |
+
# Convert uploaded file to a DataFrame
|
| 53 |
+
df = pd.read_csv(uploaded_file)
|
| 54 |
|
| 55 |
+
# Convert DataFrame to CSV bytes like your working script
|
| 56 |
+
csv_bytes = df.to_csv(index=False).encode('utf-8')
|
| 57 |
+
|
| 58 |
+
# Send POST request with raw bytes
|
| 59 |
+
response = requests.post(
|
| 60 |
+
"https://harasar-SuperKartBackend.hf.space/v1/customerbatch",
|
| 61 |
+
files={"file": ("SuperKart.csv", csv_bytes, "text/csv")}
|
| 62 |
+
)
|
| 63 |
+
|
| 64 |
+
if response.status_code == 200:
|
| 65 |
+
st.success("Batch prediction successful!")
|
| 66 |
+
st.write(response.json())
|
| 67 |
+
else:
|
| 68 |
+
st.error(f"Error {response.status_code}: {response.text}")
|
| 69 |
+
|
| 70 |
+
except Exception as e:
|
| 71 |
+
st.error(f"Upload failed: {e}")
|
| 72 |
+
else:
|
| 73 |
+
st.warning("Please upload a CSV file first.")
|