testfrontend / app.py
manjushs's picture
Upload folder using huggingface_hub
1ee43bc verified
import streamlit as st
import pandas as pd
import requests
# Set the title of the Streamlit app
st.title("Revenue Prediction")
# Section for online prediction
st.subheader("Online Prediction")
# Collect user input for property features
product_weight = st.number_input("Product Weight", min_value=1.0, max_value=30.0, value=4.0, step=0.1)
product_sugar_content = st.selectbox("Product Sugar Content",["Low Sugar","Regular","No Sugar"])
product_allocated_area = st.number_input("Product Allocated Area", min_value=0.004, max_value=0.300, step=0.001, value=0.004,format="%.3f") # format ensures three decimal places are displayed
product_type = st.selectbox("Product Type", ["Fruits and Vegetables","Snack Foods","Frozen Foods","Dairy","Household","Baking Goods","Canned",
"Health and Hygiene","Meat","Soft Drinks","Breads","Hard Drinks","Others","Starchy Foods",
"Breakfast","Seafood"])
product_mrp = st.number_input("Product_MRP", min_value=25.0, max_value=300.0, step=1.0, value=31.0)
store_id = st.selectbox("Store_Id", ["OUT001","OUT002","OUT003","OUT004"])
store_establishment_year = st.number_input("Store_Establishment_Year", min_value=1987, max_value=2010, step=1, value=1987)
store_size = st.selectbox("Store Size",["Small","Medium","High"])
store_location_city_type = st.selectbox("Store Location City Type", ["Tier 1","Tier 2","Tier 3"])
store_type = st.selectbox("Store Type", ["Supermarket Type1","Supermarket Type2","Departmental Store","Food Mart"])
# Convert user input into a DataFrame
input_data = pd.DataFrame([{
'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://manjushs-testbackend.hf.space/v1/revenue", json=input_data.to_dict(orient='records')[0]) # Send data to Flask API
if response.status_code == 200:
prediction = response.json()['Predicted Sales Total (in dollars)']
st.success(f"Predicted Sales Total (in dollars): {prediction}")
else:
st.error("Error making prediction.")