Spaces:
Paused
Paused
Upload app.py with huggingface_hub
Browse files
app.py
ADDED
|
@@ -0,0 +1,75 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import streamlit as st
|
| 2 |
+
import requests
|
| 3 |
+
import json
|
| 4 |
+
|
| 5 |
+
# Define the URL of your Flask backend
|
| 6 |
+
# If running locally, it might be http://127.0.0.1:5000
|
| 7 |
+
# If deployed, use the public URL of your deployed Flask app
|
| 8 |
+
# For Colab with ngrok, you would get the public ngrok URL
|
| 9 |
+
# For Hugging Face Spaces with Flask, the URL would be different
|
| 10 |
+
# IMPORTANT: Replace with your actual backend URL when deployed
|
| 11 |
+
BACKEND_URL = 'YOUR_FLASK_BACKEND_URL_HERE' # <-- **UPDATE THIS URL**
|
| 12 |
+
|
| 13 |
+
st.title('SuperKart Sales Forecasting')
|
| 14 |
+
|
| 15 |
+
st.write("""
|
| 16 |
+
This application predicts the sales of a product in a SuperKart store based on its characteristics and store information.
|
| 17 |
+
Enter the details below and click 'Predict Sales'.
|
| 18 |
+
""")
|
| 19 |
+
|
| 20 |
+
# Create input fields for the user to enter data
|
| 21 |
+
st.header('Enter Product and Store Details:')
|
| 22 |
+
|
| 23 |
+
# Example input fields (adjust based on your actual features expected by the Flask backend)
|
| 24 |
+
# Ensure the keys used here match the keys expected by your Flask app's /predict endpoint
|
| 25 |
+
|
| 26 |
+
# Numerical inputs
|
| 27 |
+
product_weight = st.number_input('Product Weight', value=12.0) # Add appropriate min/max/default values
|
| 28 |
+
product_allocated_area = st.number_input('Product Allocated Area', value=0.05) # Add appropriate min/max/default values
|
| 29 |
+
product_mrp = st.number_input('Product MRP', value=150.0) # Add appropriate min/max/default values
|
| 30 |
+
store_establishment_year = st.number_input('Store Establishment Year', value=2000, format="%d") # Add appropriate min/max/default values
|
| 31 |
+
|
| 32 |
+
# Categorical inputs (use the expected categories from your original data)
|
| 33 |
+
product_sugar_content = st.selectbox('Product Sugar Content', ['Low Sugar', 'Regular', 'No Sugar']) # Use actual categories
|
| 34 |
+
product_type = st.selectbox('Product Type', ['Dairy', 'Soft Drinks', 'Meat', 'Fruits and Vegetables', 'Baking Goods', 'Health and Hygiene', 'Frozen Foods', 'Breads', 'Household', 'Snack Foods', 'Canned', 'Starchy Foods', 'Breakfast', 'Seafood', 'Others', 'Hard Drinks']) # Use actual categories
|
| 35 |
+
store_id = st.selectbox('Store ID', ['OUT001', 'OUT002', 'OUT003', 'OUT004']) # Use actual categories
|
| 36 |
+
store_size = st.selectbox('Store Size', ['Small', 'Medium', 'High']) # Use actual categories
|
| 37 |
+
store_location_city_type = st.selectbox('Store Location City Type', ['Tier 1', 'Tier 2', 'Tier 3']) # Use actual categories
|
| 38 |
+
store_type = st.selectbox('Store Type', ['Departmental Store', 'Supermarket Type1', 'Supermarket Type2', 'Food Mart']) # Use actual categories
|
| 39 |
+
|
| 40 |
+
|
| 41 |
+
# Create a dictionary with the input data
|
| 42 |
+
input_data = {
|
| 43 |
+
'Product_Weight': product_weight,
|
| 44 |
+
'Product_Sugar_Content': product_sugar_content,
|
| 45 |
+
'Product_Allocated_Area': product_allocated_area,
|
| 46 |
+
'Product_Type': product_type,
|
| 47 |
+
'Product_MRP': product_mrp,
|
| 48 |
+
'Store_Id': store_id,
|
| 49 |
+
'Store_Establishment_Year': store_establishment_year,
|
| 50 |
+
'Store_Size': store_size,
|
| 51 |
+
'Store_Location_City_Type': store_location_city_type,
|
| 52 |
+
'Store_Type': store_type
|
| 53 |
+
}
|
| 54 |
+
|
| 55 |
+
# Make a prediction when the user clicks a button
|
| 56 |
+
if st.button('Predict Sales'):
|
| 57 |
+
try:
|
| 58 |
+
# Send the input data to the Flask backend for prediction
|
| 59 |
+
response = requests.post(f'{BACKEND_URL}/predict', json=input_data)
|
| 60 |
+
|
| 61 |
+
if response.status_code == 200:
|
| 62 |
+
prediction_result = response.json()
|
| 63 |
+
predicted_sales = prediction_result.get('prediction')
|
| 64 |
+
st.subheader('Predicted Sales:')
|
| 65 |
+
st.write(f'The predicted sales for this product in the specified store is: **{predicted_sales:.2f}**')
|
| 66 |
+
else:
|
| 67 |
+
st.error(f"Error from backend: {response.status_code} - {response.text}")
|
| 68 |
+
|
| 69 |
+
except requests.exceptions.ConnectionError:
|
| 70 |
+
st.error(f"Connection Error: Could not connect to the backend at {BACKEND_URL}. Please ensure the backend is running and the URL is correct.")
|
| 71 |
+
except Exception as e:
|
| 72 |
+
st.error(f"An error occurred: {e}")
|
| 73 |
+
|
| 74 |
+
st.markdown("---")
|
| 75 |
+
st.markdown("Note: This is a basic frontend. You need to update the `BACKEND_URL` with the actual URL of your deployed Flask backend.")
|