Upload folder using huggingface_hub
Browse files
app.py
CHANGED
|
@@ -4,12 +4,15 @@ import pandas as pd
|
|
| 4 |
import requests
|
| 5 |
import altair as alt
|
| 6 |
|
| 7 |
-
|
|
|
|
|
|
|
| 8 |
|
|
|
|
| 9 |
st.title("π SuperKart Sales Predictor")
|
| 10 |
st.markdown("Use the tabs below to predict sales for a single product or upload a CSV file for batch prediction.")
|
| 11 |
|
| 12 |
-
# Create
|
| 13 |
tab1, tab2 = st.tabs(["π Single Prediction", "π Batch Prediction"])
|
| 14 |
|
| 15 |
# ----------------- Tab 1: Single Prediction -----------------
|
|
@@ -38,31 +41,29 @@ with tab1:
|
|
| 38 |
])
|
| 39 |
est_year = st.slider("Establishment Year", 1987, 2009, 2002)
|
| 40 |
|
| 41 |
-
# Submit
|
| 42 |
if st.button("π― Predict Sales π―"):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 43 |
try:
|
| 44 |
-
|
| 45 |
-
|
| 46 |
-
|
| 47 |
-
|
| 48 |
-
|
| 49 |
-
"Product_Type": product_type,
|
| 50 |
-
"Store_Id": store_id,
|
| 51 |
-
"Store_Size": store_size,
|
| 52 |
-
"Store_Location_City_Type": store_location,
|
| 53 |
-
"Store_Type": store_type,
|
| 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"])
|
|
@@ -95,5 +96,5 @@ with tab2:
|
|
| 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}")
|
|
|
|
| 4 |
import requests
|
| 5 |
import altair as alt
|
| 6 |
|
| 7 |
+
from predictor.batch_handler import get_predictions, get_single_prediction
|
| 8 |
+
from predictor.utils import reorder_columns, get_csv_download
|
| 9 |
+
from predictor.chart_plotter import plot_actual_vs_predicted
|
| 10 |
|
| 11 |
+
st.set_page_config(page_title="SuperKart Sales Predictor", layout="wide")
|
| 12 |
st.title("π SuperKart Sales Predictor")
|
| 13 |
st.markdown("Use the tabs below to predict sales for a single product or upload a CSV file for batch prediction.")
|
| 14 |
|
| 15 |
+
# Create tabs
|
| 16 |
tab1, tab2 = st.tabs(["π Single Prediction", "π Batch Prediction"])
|
| 17 |
|
| 18 |
# ----------------- Tab 1: Single Prediction -----------------
|
|
|
|
| 41 |
])
|
| 42 |
est_year = st.slider("Establishment Year", 1987, 2009, 2002)
|
| 43 |
|
| 44 |
+
# Submit button
|
| 45 |
if st.button("π― Predict Sales π―"):
|
| 46 |
+
payload = {
|
| 47 |
+
"Product_Weight": product_weight,
|
| 48 |
+
"Product_Allocated_Area": product_allocated_area,
|
| 49 |
+
"Product_MRP": product_mrp,
|
| 50 |
+
"Product_Sugar_Content": product_sugar_content,
|
| 51 |
+
"Product_Type": product_type,
|
| 52 |
+
"Store_Id": store_id,
|
| 53 |
+
"Store_Size": store_size,
|
| 54 |
+
"Store_Location_City_Type": store_location,
|
| 55 |
+
"Store_Type": store_type,
|
| 56 |
+
"Store_Establishment_Year": est_year
|
| 57 |
+
}
|
| 58 |
+
|
| 59 |
try:
|
| 60 |
+
prediction = get_single_prediction(payload)
|
| 61 |
+
st.success(f"β
Predicted Sales: βΉ{prediction:,.2f}")
|
| 62 |
+
st.json({**payload, "Predicted_Sales": prediction})
|
| 63 |
+
except Exception as e:
|
| 64 |
+
st.error(f"β οΈ Error during prediction: {e}")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 65 |
|
| 66 |
# ----------------- Tab 2: Batch Prediction -----------------
|
|
|
|
| 67 |
with tab2:
|
| 68 |
st.subheader("π Upload CSV for Batch Prediction")
|
| 69 |
uploaded_file = st.file_uploader("Upload your CSV file", type=["csv"])
|
|
|
|
| 96 |
st.dataframe(df)
|
| 97 |
plot_actual_vs_predicted(df)
|
| 98 |
|
| 99 |
+
except Exception as e:
|
| 100 |
st.error(f"β οΈ Error while processing the file: {e}")
|