Spaces:
Runtime error
Runtime error
Deploy Streamlit frontend with model and CSV
Browse files- Dockerfile +5 -3
- app.py +51 -61
- requirements.txt +2 -7
Dockerfile
CHANGED
|
@@ -1,3 +1,5 @@
|
|
| 1 |
-
|
| 2 |
-
#docker build -t superkart-
|
| 3 |
-
#docker run -p 7860:7860 superkart-
|
|
|
|
|
|
|
|
|
| 1 |
+
|
| 2 |
+
#docker build -t superkart-frontend .
|
| 3 |
+
#docker run -p 7860:7860 superkart-frontend
|
| 4 |
+
|
| 5 |
+
|
app.py
CHANGED
|
@@ -1,62 +1,52 @@
|
|
| 1 |
-
import
|
| 2 |
import pandas as pd
|
| 3 |
-
|
| 4 |
-
|
| 5 |
-
|
| 6 |
-
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
|
| 36 |
-
|
| 37 |
-
|
| 38 |
-
|
| 39 |
-
|
| 40 |
-
|
| 41 |
-
|
| 42 |
-
|
| 43 |
-
|
| 44 |
-
|
| 45 |
-
|
| 46 |
-
|
| 47 |
-
|
| 48 |
-
|
| 49 |
-
|
| 50 |
-
|
| 51 |
-
|
| 52 |
-
|
| 53 |
-
.reset_index()
|
| 54 |
-
.rename(columns={'Predicted_Sales': 'Total_Sales'})
|
| 55 |
-
)
|
| 56 |
-
|
| 57 |
-
return summary.to_dict(orient="records")
|
| 58 |
-
except Exception as e:
|
| 59 |
-
return jsonify({'error': str(e)}), 500
|
| 60 |
-
|
| 61 |
-
if __name__ == '__main__':
|
| 62 |
-
serve(app, host="0.0.0.0", port=7860)
|
|
|
|
| 1 |
+
import streamlit as st
|
| 2 |
import pandas as pd
|
| 3 |
+
import requests
|
| 4 |
+
|
| 5 |
+
st.title("π SuperKart Quarterly Sales Predictor")
|
| 6 |
+
|
| 7 |
+
# Input form
|
| 8 |
+
st.subheader("π Predict Store's Quarterly Sales")
|
| 9 |
+
|
| 10 |
+
store_id = st.selectbox("Store ID", ["OUT001", "OUT002", "OUT003", "OUT004"])
|
| 11 |
+
product_type = st.selectbox("Product Type", ["Dairy", "Soft Drinks", "Meat", "Canned", "Frozen Foods"])
|
| 12 |
+
sugar_content = st.selectbox("Product Sugar Content", ["Low", "Medium", "High", "No Added Sugar"])
|
| 13 |
+
store_type = st.selectbox("Store Type", ["Supermarket Type1", "Supermarket Type2", "Grocery Store", "Food Mart"])
|
| 14 |
+
city_type = st.selectbox("City Type", ["Urban", "Semi-Urban", "Rural"])
|
| 15 |
+
store_size = st.selectbox("Store Size", ["Small", "Medium", "High"])
|
| 16 |
+
|
| 17 |
+
est_year = st.number_input("Store Establishment Year", min_value=1980, max_value=2025, value=2005)
|
| 18 |
+
weight = st.number_input("Product Weight", min_value=0.0, value=12.0)
|
| 19 |
+
area = st.number_input("Product Allocated Area", min_value=0.0, value=125.0)
|
| 20 |
+
mrp = st.number_input("Product MRP", min_value=0.0, value=120.0)
|
| 21 |
+
|
| 22 |
+
input_data = pd.DataFrame([{
|
| 23 |
+
'Store_Id': store_id,
|
| 24 |
+
'Product_Type': product_type,
|
| 25 |
+
'Product_Sugar_Content': sugar_content,
|
| 26 |
+
'Store_Type': store_type,
|
| 27 |
+
'Store_Location_City_Type': city_type,
|
| 28 |
+
'Store_Size': store_size,
|
| 29 |
+
'Store_Establishment_Year': est_year,
|
| 30 |
+
'Product_Weight': weight,
|
| 31 |
+
'Product_Allocated_Area': area,
|
| 32 |
+
'Product_MRP': mrp
|
| 33 |
+
}])
|
| 34 |
+
|
| 35 |
+
if st.button("Predict Sales"):
|
| 36 |
+
api_url = "https://<your-backend-space>.hf.space/v1/storesales"
|
| 37 |
+
response = requests.post(api_url, json=input_data.to_dict(orient='records'))
|
| 38 |
+
if response.status_code == 200:
|
| 39 |
+
result = response.json()
|
| 40 |
+
st.success(f"π¦ Predicted Total Sales: βΉ{result['Total_Store_Sales']:,.2f}")
|
| 41 |
+
else:
|
| 42 |
+
st.error(f"β API Error: {response.text}")
|
| 43 |
+
|
| 44 |
+
st.subheader("π Batch Prediction via CSV")
|
| 45 |
+
file = st.file_uploader("Upload CSV", type=["csv"])
|
| 46 |
+
|
| 47 |
+
if file and st.button("Predict Batch"):
|
| 48 |
+
response = requests.post("https://<your-backend-space>.hf.space/v1/storesalesbatch", files={"file": file})
|
| 49 |
+
if response.status_code == 200:
|
| 50 |
+
st.write(pd.DataFrame(response.json()))
|
| 51 |
+
else:
|
| 52 |
+
st.error(f"β Batch API Error: {response.text}")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
requirements.txt
CHANGED
|
@@ -1,8 +1,3 @@
|
|
| 1 |
-
|
| 2 |
-
waitress==2.1.2
|
| 3 |
pandas==2.2.2
|
| 4 |
-
|
| 5 |
-
joblib==1.4.2
|
| 6 |
-
scikit-learn==1.6.1
|
| 7 |
-
xgboost==2.1.4
|
| 8 |
-
|
|
|
|
| 1 |
+
streamlit==1.34.0
|
|
|
|
| 2 |
pandas==2.2.2
|
| 3 |
+
requests==2.31.0
|
|
|
|
|
|
|
|
|
|
|
|