Spaces:
Runtime error
Runtime error
| import streamlit as st | |
| import pandas as pd | |
| import requests | |
| import numpy as np | |
| # Set the title of the Streamlit app | |
| st.title("Superkart Sales Prediction") | |
| # Section for online prediction | |
| st.subheader("Online Prediction") | |
| # Collect user input for sales features | |
| Product_Weight = st.number_input("Product_Weight", min_value=1.0, max_value=100.0, value=12.66) | |
| Product_Sugar_Content = st.selectbox("Product_Sugar_Content", ["Low Sugar", "Regular", "No Sugar"], index=0) # Corrected available options | |
| Product_Allocated_Area = st.number_input("Product_Allocated_Area", min_value=0.0, max_value=1.0, value=0.027) | |
| Product_Type = st.selectbox("Product_Type", ["Frozen Foods", "Dairy", "Canned", "Baking Goods", "Health and Hygiene", "Household", "Meat", "Others", "Seafood", "Snack Foods", "Soft Drinks", "Starchy Foods", "Fruits and Vegetables", "Hard Drinks", "Breakfast"], index=0) | |
| Product_MRP = st.number_input("Product_MRP", min_value=1.0, max_value=1000.0, value=117.08) | |
| Store_Age = st.number_input("Store_Age", min_value=1, max_value=100, value=16) | |
| Store_Type = st.selectbox("Store_Type", ["Supermarket Type1", "Supermarket Type2", "Food Mart", 'Departmental Store'], index=1) | |
| Store_Location_City_Type = st.selectbox("Store_Location_City_Type", ["Tier 1", "Tier 2", "Tier 3"], index=1) | |
| Store_Size = st.selectbox("Store_Size", ["Small", "Medium", "High"], index=1) | |
| # Convert user input into a DataFrame | |
| input_data = pd.DataFrame([{ | |
| 'Product_Weight': Product_Weight, | |
| 'Product_Sugar_Content': Product_Sugar_Content, | |
| 'Product_Type': Product_Type, | |
| 'Product_Allocated_Area': Product_Allocated_Area, | |
| 'Product_MRP': Product_MRP, | |
| 'Store_Age': Store_Age, | |
| 'Store_Type': Store_Type, | |
| 'Store_Location_City_Type': Store_Location_City_Type, | |
| 'Store_Size': Store_Size | |
| }]) | |
| # Make prediction when the "Predict" button is clicked | |
| if st.button("Predict", type="primary"): | |
| # Correct the endpoint URL to match the Flask API | |
| # The Flask API is running on port 7860 inside the Docker container | |
| # and exposed externally. | |
| response = requests.post("https://rajoria007-backendsales.hf.space/v1/sales", json=input_data.to_dict(orient='records')[0]) | |
| if response.status_code == 200: | |
| # The API now returns the actual sales prediction | |
| prediction = response.json()['predicted_sales'] | |
| st.success(f"Predicted Sales: {prediction:.2f}") # Display prediction with 2 decimal places | |
| else: | |
| st.error(f"Error making prediction. Status Code: {response.status_code}") | |
| try: | |
| st.error(f"Error Details: {response.json()}") | |
| except: | |
| st.error(f"Error Details: {response.text}") | |