Spaces:
Build error
Build error
Upload folder using huggingface_hub
Browse files- app.py +55 -0
- requirements.txt +5 -0
app.py
ADDED
|
@@ -0,0 +1,55 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import streamlit as st
|
| 2 |
+
import pandas as pd
|
| 3 |
+
import requests
|
| 4 |
+
|
| 5 |
+
# Set the title of the Streamlit app
|
| 6 |
+
st.title("Sales Prediction")
|
| 7 |
+
|
| 8 |
+
# Section for online prediction
|
| 9 |
+
st.subheader("Online Prediction")
|
| 10 |
+
|
| 11 |
+
sample = {
|
| 12 |
+
'Product_Weight': property_data['Product_Weight'],
|
| 13 |
+
'Product_Allocated_Area': property_data['Product_Allocated_Area'],
|
| 14 |
+
'Product_MRP': property_data['Product_MRP'],
|
| 15 |
+
'Store_Establishment_Year': property_data['Store_Establishment_Year'],
|
| 16 |
+
'Product_Sugar_Content': property_data['Product_Sugar_Content'],
|
| 17 |
+
'Product_Type': property_data['Product_Type'],
|
| 18 |
+
'Store_Id': property_data['Store_Id'],
|
| 19 |
+
'Store_Size': property_data['Store_Size'],
|
| 20 |
+
'Store_Location_City_Type': property_data['Store_Location_City_Type'],
|
| 21 |
+
'Store_Type': property_data['Store_Type']
|
| 22 |
+
}
|
| 23 |
+
|
| 24 |
+
# Collect user input for property features
|
| 25 |
+
product_weight = st.number_input("Weight of the product", min_value=0, value=2)
|
| 26 |
+
Product_Allocated_Area = st.number_input("Product Allocated Area", min_value=1, value=2)
|
| 27 |
+
Product_MRP = st.number_input("Product_MRP", min_value=1, step=1, value=2)
|
| 28 |
+
Store_Establishment_Year = st.selectbox("Store_Establishment_Year", ["strict", "flexible", "moderate"])
|
| 29 |
+
Product_Sugar_Content = st.selectbox("Product_Sugar_Content", ["True", "False"])
|
| 30 |
+
Product_Type = st.selectbox("Product_Type", ["False", "True"])
|
| 31 |
+
Store_Size = st.number_input("Store_Size", min_value=0.0, max_value=100.0, step=1.0, value=90.0)
|
| 32 |
+
Store_Location_City_Type = st.number_input("Store_Location_City_Type", min_value=0, step=1, value=1)
|
| 33 |
+
Store_Type = st.number_input("Store_Type", min_value=0, step=1, value=1)
|
| 34 |
+
|
| 35 |
+
# Convert user input into a DataFrame
|
| 36 |
+
input_data = pd.DataFrame([{
|
| 37 |
+
'Product_Weight': product_weight,
|
| 38 |
+
'Product_Allocated_Area': Product_Allocated_Area,
|
| 39 |
+
'Product_MRP': Product_MRP,
|
| 40 |
+
'Store_Establishment_Year': Store_Establishment_Year,
|
| 41 |
+
'Product_Sugar_Content': Product_Sugar_Content,
|
| 42 |
+
'Product_Type': Product_Type, # Convert to 't' or 'f'
|
| 43 |
+
'Store_Size': Store_Size,
|
| 44 |
+
'Store_Location_City_Type': Store_Location_City_Type,
|
| 45 |
+
'Store_Type': Store_Type
|
| 46 |
+
}])
|
| 47 |
+
|
| 48 |
+
# Make prediction when the "Predict" button is clicked
|
| 49 |
+
if st.button("Predict"):
|
| 50 |
+
response = requests.post("https://maddykan101-SalesPredictionBackend.hf.space/v1/rental", json=input_data.to_dict(orient='records')[0]) # Send data to Flask API
|
| 51 |
+
if response.status_code == 200:
|
| 52 |
+
prediction = response.json()['Predicted Sakes']
|
| 53 |
+
st.success(f"Predicted Sales: {prediction}")
|
| 54 |
+
else:
|
| 55 |
+
st.error("Error making prediction.")
|
requirements.txt
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
pandas==2.2.2
|
| 2 |
+
requests==2.28.1
|
| 3 |
+
streamlit
|
| 4 |
+
numpy
|
| 5 |
+
flask
|