nv185001's picture
Upload folder using huggingface_hub
e6fd927 verified
import streamlit as st
import pandas as pd
import requests
# Set the title of the Streamlit app
st.title("Superkart Revenue Forecaster")
# Section for online revenue prediction
st.subheader("Online Revenue Prediction")
# Collect user input for product-store features
product_id = st.text_input("Product ID", max_chars=10, value='FX007')
product_weight = st.number_input("Product Weight", min_value=1.0, max_value=50.0, value=12.6)
product_sugar_content = st.selectbox("Product Sugar Content", ['Low Sugar', 'Regular', 'No Sugar'])
product_allocated_area = st.number_input("Allocated Display Area Ratio", min_value=0.0, max_value=1.0, value=0.1)
product_type = st.selectbox("Product Type", ['Frozen Foods', 'Dairy', 'Canned', 'Baking Goods', 'Health and Hygiene', 'Snack Foods', 'Meat', 'Household', 'Hard Drinks', 'Fruits and Vegetables', 'Breads', 'Soft Drinks', 'Breakfast', 'Others', 'Starchy Foods', 'Seafood'])
product_mrp = st.number_input("Product MRP", min_value=1.0, max_value=500.0, value=100.0)
store_id = st.selectbox("Store ID", ['OUT004', 'OUT003', 'OUT001', 'OUT002'])
store_establishment_year = st.selectbox("Store Establishment Year", ['2009', '1999', '1987', '1998'])
store_size = st.selectbox("Store Size", ["High", "Medium", "Low"])
store_location_city_type = st.selectbox("Store Location City Type", ["Tier 1", "Tier 2", "Tier 3"])
store_type = st.selectbox("Store Type", ["Departmental Store", "Supermarket Type 1", "Supermarket Type 2", "Food Mart"])
# Convert user input into a DataFrame
input_data = pd.DataFrame([{
'Product_Id': product_id,
'Product_Weight': product_weight,
'Product_Sugar_Content': product_sugar_content,
'Product_Allocated_Area': product_allocated_area,
'Product_Type': product_type,
'Product_MRP': product_mrp,
'Store_Id': store_id,
'Store_Establishment_Year': store_establishment_year,
'Store_Size': store_size,
'Store_Location_City_Type': store_location_city_type,
'Store_Type': store_type
}])
# Make prediction when the "Predict" button is clicked
if st.button("Predict"):
response = requests.post(
"https://nv185001-SuperKartBackendSpaceForecast.hf.space/v1/predict", # Hugging Face Space API URL
json=input_data.to_dict(orient='records')[0]
)
if response.status_code == 200:
prediction = response.json()['Predicted_Revenue']
st.success(f"Predicted Revenue : $ {prediction}")
else:
st.error(f"Error making prediction {response.status_code}")
# Section for batch prediction
st.subheader("Batch Prediction")
# Allow users to upload a CSV file for batch prediction
uploaded_file = st.file_uploader("Upload CSV file for batch prediction", type=["csv"])
# Make batch prediction when the "Predict Batch" button is clicked
if uploaded_file is not None:
if st.button("Predict Batch"):
response = requests.post(
"https://nv185001-SuperKartBackendSpaceForecast.hf.space/v1/predictbatch", # Replace with your Hugging Face Space API URL
files={"file": uploaded_file}
)
if response.status_code == 200:
predictions = response.json()
st.success("Batch predictions made successfully!")
st.write(predictions)
else:
st.error(f"Error making batch prediction. {response.status_code}")