Upload folder using huggingface_hub
Browse files
app.py
CHANGED
|
@@ -54,105 +54,46 @@ with tab1:
|
|
| 54 |
"Store_Establishment_Year": est_year
|
| 55 |
}
|
| 56 |
|
| 57 |
-
|
| 58 |
-
|
| 59 |
-
|
| 60 |
-
|
| 61 |
-
|
| 62 |
-
st.
|
| 63 |
-
else:
|
| 64 |
-
st.error(f"β Error: {result.get('error', 'Unknown error')}")
|
| 65 |
-
|
| 66 |
-
except Exception as e:
|
| 67 |
-
st.error(f"β οΈ Request failed: {e}")
|
| 68 |
|
| 69 |
# ----------------- Tab 2: Batch Prediction -----------------
|
|
|
|
| 70 |
with tab2:
|
| 71 |
st.subheader("π Upload CSV for Batch Prediction")
|
| 72 |
uploaded_file = st.file_uploader("Upload your CSV file", type=["csv"])
|
| 73 |
|
| 74 |
-
if uploaded_file
|
| 75 |
try:
|
| 76 |
df = pd.read_csv(uploaded_file)
|
| 77 |
|
| 78 |
if df.empty:
|
| 79 |
-
st.warning("Uploaded file is empty
|
| 80 |
else:
|
| 81 |
st.write("π Uploaded Data Preview:")
|
| 82 |
st.dataframe(df.head())
|
| 83 |
|
| 84 |
-
|
| 85 |
-
|
| 86 |
-
|
| 87 |
-
|
| 88 |
-
|
| 89 |
-
|
| 90 |
-
|
| 91 |
-
|
| 92 |
-
|
| 93 |
-
|
| 94 |
-
|
| 95 |
-
|
| 96 |
-
|
| 97 |
-
|
| 98 |
-
|
| 99 |
-
|
| 100 |
-
|
| 101 |
-
|
| 102 |
-
st.success("β
Batch prediction complete!")
|
| 103 |
-
|
| 104 |
-
# Header + Download button aligned
|
| 105 |
-
col1, col2 = st.columns([6, 1])
|
| 106 |
-
with col1:
|
| 107 |
-
st.subheader("π Prediction Results:")
|
| 108 |
-
with col2:
|
| 109 |
-
csv = df.to_csv(index=False).encode('utf-8')
|
| 110 |
-
st.download_button(
|
| 111 |
-
label="π₯ Download CSV",
|
| 112 |
-
data=csv,
|
| 113 |
-
file_name="batch_predictions.csv",
|
| 114 |
-
mime="text/csv",
|
| 115 |
-
use_container_width=True
|
| 116 |
-
)
|
| 117 |
-
|
| 118 |
-
# Display result table
|
| 119 |
-
st.dataframe(df)
|
| 120 |
-
|
| 121 |
-
# π Altair Line Chart: Actual vs Predicted
|
| 122 |
-
if "Product_Store_Sales_Total" in df.columns:
|
| 123 |
-
plot_df = df[["Product_Store_Sales_Total", "Predicted_Sales"]].dropna()
|
| 124 |
-
|
| 125 |
-
if not plot_df.empty:
|
| 126 |
-
st.subheader("π Actual vs Predicted Sales")
|
| 127 |
-
|
| 128 |
-
# Prepare long-format dataframe for Altair
|
| 129 |
-
plot_df = plot_df.reset_index().rename(columns={
|
| 130 |
-
"Product_Store_Sales_Total": "Actual Sales",
|
| 131 |
-
"Predicted_Sales": "Predicted Sales",
|
| 132 |
-
"index": "Index"
|
| 133 |
-
})
|
| 134 |
-
|
| 135 |
-
plot_df_melted = plot_df.melt(
|
| 136 |
-
id_vars="Index",
|
| 137 |
-
var_name="Type",
|
| 138 |
-
value_name="Sales"
|
| 139 |
-
)
|
| 140 |
-
|
| 141 |
-
line_chart = alt.Chart(plot_df_melted).mark_line(point=True).encode(
|
| 142 |
-
x=alt.X("Index:O", title="Record Index"),
|
| 143 |
-
y=alt.Y("Sales:Q", title="Sales Value"),
|
| 144 |
-
color=alt.Color("Type:N", title="Sales Type"),
|
| 145 |
-
tooltip=["Index", "Type", "Sales"]
|
| 146 |
-
).properties(
|
| 147 |
-
width=700,
|
| 148 |
-
height=400
|
| 149 |
-
)
|
| 150 |
-
|
| 151 |
-
st.altair_chart(line_chart, use_container_width=True)
|
| 152 |
-
else:
|
| 153 |
-
st.info("βΉοΈ Not enough valid rows for plotting.")
|
| 154 |
-
else:
|
| 155 |
-
st.error(f"β API Error {response.status_code}: {response.text}")
|
| 156 |
|
| 157 |
except Exception as e:
|
| 158 |
st.error(f"β οΈ Error while processing the file: {e}")
|
|
|
|
| 54 |
"Store_Establishment_Year": est_year
|
| 55 |
}
|
| 56 |
|
| 57 |
+
try:
|
| 58 |
+
prediction = get_single_prediction(payload)
|
| 59 |
+
st.success(f"β
Predicted Sales: βΉ{prediction:,.2f}")
|
| 60 |
+
st.json({**payload, "Predicted_Sales": prediction})
|
| 61 |
+
except Exception as e:
|
| 62 |
+
st.error(f"β οΈ Error during prediction: {e}")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 63 |
|
| 64 |
# ----------------- Tab 2: Batch Prediction -----------------
|
| 65 |
+
# π TAB 2: Batch Prediction
|
| 66 |
with tab2:
|
| 67 |
st.subheader("π Upload CSV for Batch Prediction")
|
| 68 |
uploaded_file = st.file_uploader("Upload your CSV file", type=["csv"])
|
| 69 |
|
| 70 |
+
if uploaded_file:
|
| 71 |
try:
|
| 72 |
df = pd.read_csv(uploaded_file)
|
| 73 |
|
| 74 |
if df.empty:
|
| 75 |
+
st.warning("Uploaded file is empty.")
|
| 76 |
else:
|
| 77 |
st.write("π Uploaded Data Preview:")
|
| 78 |
st.dataframe(df.head())
|
| 79 |
|
| 80 |
+
df = get_predictions(df)
|
| 81 |
+
df = reorder_columns(df, ["Product_Store_Sales_Total", "Predicted_Sales"])
|
| 82 |
+
|
| 83 |
+
col1, col2 = st.columns([6, 1])
|
| 84 |
+
with col1:
|
| 85 |
+
st.subheader("π Prediction Results:")
|
| 86 |
+
with col2:
|
| 87 |
+
st.download_button(
|
| 88 |
+
label="π₯ Download CSV",
|
| 89 |
+
data=get_csv_download(df),
|
| 90 |
+
file_name="batch_predictions.csv",
|
| 91 |
+
mime="text/csv",
|
| 92 |
+
use_container_width=True
|
| 93 |
+
)
|
| 94 |
+
|
| 95 |
+
st.dataframe(df)
|
| 96 |
+
plot_actual_vs_predicted(df)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 97 |
|
| 98 |
except Exception as e:
|
| 99 |
st.error(f"β οΈ Error while processing the file: {e}")
|