Spaces:
Runtime error
Runtime error
File size: 3,309 Bytes
d655941 |
1 2 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 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 |
import streamlit as st
import requests
import json
# Define the URL of your Flask API (replace with your Hugging Face Space URL)
API_URL = "https://pkulkar-salesforcastbackend.hf.space/v1/sales" # Replace with your Hugging Face Space URL
st.title("SuperKart Sales Forecaster")
st.write("Enter the details of the product and store to get a sales forecast.")
# Create input fields for the user
product_weight = st.number_input("Product Weight", min_value=0.0, format="%f")
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.0, format="%f")
product_type = st.selectbox("Product Type", ['Dairy', 'Soft Drinks', 'Meat', 'Fruits and Vegetables', 'Household', 'Baking Goods', 'Snack Foods', 'Frozen Foods', 'Breakfast', 'Health and Hygiene', 'Hard Drinks', 'Canned', 'Bread', 'Starchy Foods', 'Others', 'Seafood'])
product_mrp = st.number_input("Product MRP", min_value=0.0, format="%f")
store_id = st.selectbox("Store ID", [f"Store_{i}" for i in range(1, 11)])
store_establishment_year = st.number_input("Store Establishment Year", min_value=1900, max_value=2024, step=1)
store_size = st.selectbox("Store Size", ['Medium', 'High', 'Low'])
store_location_city_type = st.selectbox("Store Location City Type", ['Tier 1', 'Tier 3', 'Tier 2'])
store_type = st.selectbox("Store Type", ['Supermarket Type 1', 'Supermarket Type 2', 'Departmental Store', 'Food Mart'])
if st.button("Predict Sales"):
# Prepare the data to be sent to the API
input_data = {
'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,
}
# Send the data to the Flask API
try:
response = requests.post(API_URL, json=input_data)
if response.status_code == 200:
prediction = response.json()
st.success(f"Predicted Sales: {prediction['Predicted Price (in dollars)']:.2f}")
else:
st.error(f"Error predicting sales: {response.status_code} - {response.text}")
except requests.exceptions.RequestException as e:
st.error(f"Error connecting to the API: {e}")
# Create a requirements.txt file for the Streamlit app
%%writefile /content/drive/MyDrive/deployment_files/requirements_streamlit.txt
streamlit==1.43.2
requests==2.32.3
# Upload the Streamlit app file and requirements file to Hugging Face Space
from huggingface_hub import upload_file
repo_id_frontend = "pkulkar/SalesForcasterFrontend" # Replace with your Hugging Face Space ID for the frontend
upload_file(
path_or_fileobj="/content/drive/MyDrive/deployment_files/app_streamlit.py",
path_in_repo="app.py",
repo_id=repo_id_frontend,
repo_type="space",
)
upload_file(
path_or_fileobj="/content/drive/MyDrive/deployment_files/requirements_streamlit.txt",
path_in_repo="requirements.txt",
repo_id=repo_id_frontend,
repo_type="space",
)
```
|