Upload folder using huggingface_hub
Browse files- app.py +48 -61
- requirements.txt +0 -8
app.py
CHANGED
|
@@ -1,61 +1,48 @@
|
|
| 1 |
-
|
| 2 |
-
import
|
| 3 |
-
import
|
| 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 |
-
# Make prediction
|
| 50 |
-
predicted_sales = model.predict(input_data)[0]
|
| 51 |
-
|
| 52 |
-
# Convert predicted_sales to Python float
|
| 53 |
-
predicted_sales = round(float(predicted_sales), 2)
|
| 54 |
-
|
| 55 |
-
|
| 56 |
-
# Return the predicted sales
|
| 57 |
-
return jsonify({'Predicted Sales Total (in dollars)': predicted_sales})
|
| 58 |
-
|
| 59 |
-
# Run the Flask application in debug mode if this script is executed directly
|
| 60 |
-
if __name__ == '__main__':
|
| 61 |
-
sales_predictor_api.run(debug=True)
|
|
|
|
| 1 |
+
import streamlit as st
|
| 2 |
+
import pandas as pd
|
| 3 |
+
import requests
|
| 4 |
+
|
| 5 |
+
# Set the title of the Streamlit app
|
| 6 |
+
st.title("SuperKart Sales Prediction")
|
| 7 |
+
|
| 8 |
+
# Section for online prediction
|
| 9 |
+
st.subheader("Predict Single Product Sales")
|
| 10 |
+
|
| 11 |
+
# Collect user input for product and store features
|
| 12 |
+
product_weight = st.number_input("Product Weight", min_value=0.0, value=10.0)
|
| 13 |
+
product_sugar_content = st.selectbox("Product Sugar Content", ["Low Sugar", "Regular", "No Sugar", "reg"]) # Include 'reg' based on EDA
|
| 14 |
+
product_allocated_area = st.number_input("Product Allocated Area", min_value=0.0, value=0.05)
|
| 15 |
+
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']) # Based on EDA
|
| 16 |
+
product_mrp = st.number_input("Product MRP", min_value=0.0, value=100.0)
|
| 17 |
+
store_establishment_year_before_2005 = st.selectbox("Store Established Before 2005?", ["True", "False"])
|
| 18 |
+
store_size = st.selectbox("Store Size", ["Small", "Medium", "High"])
|
| 19 |
+
store_location_city_type = st.selectbox("Store Location City Type", ["Tier 1", "Tier 2", "Tier 3"])
|
| 20 |
+
store_type = st.selectbox("Store Type", ['Supermarket Type2', 'Departmental Store', 'Supermarket Type1', 'Food Mart']) # Based on EDA
|
| 21 |
+
|
| 22 |
+
|
| 23 |
+
# Convert user input into a dictionary
|
| 24 |
+
input_data = {
|
| 25 |
+
'Product_Weight': product_weight,
|
| 26 |
+
'Product_Sugar_Content': product_sugar_content,
|
| 27 |
+
'Product_Allocated_Area': product_allocated_area,
|
| 28 |
+
'Product_Type': product_type,
|
| 29 |
+
'Product_MRP': product_mrp,
|
| 30 |
+
'Store_Establishment_Year_Before_2005': store_establishment_year_before_2005 == "True", # Convert string to boolean
|
| 31 |
+
'Store_Size': store_size,
|
| 32 |
+
'Store_Location_City_Type': store_location_city_type,
|
| 33 |
+
'Store_Type': store_type
|
| 34 |
+
}
|
| 35 |
+
|
| 36 |
+
# Make prediction when the "Predict" button is clicked
|
| 37 |
+
if st.button("Predict Sales"):
|
| 38 |
+
# Replace <username>-<repo_id> with your actual Hugging Face username and backend space repo ID
|
| 39 |
+
backend_url = "https://<username>-<repo_id>.hf.space/v1/predict" # Update endpoint
|
| 40 |
+
response = requests.post(backend_url, json=input_data) # Send data as JSON
|
| 41 |
+
if response.status_code == 200:
|
| 42 |
+
prediction = response.json()['Predicted Sales Total (in dollars)']
|
| 43 |
+
st.success(f"Predicted Sales Total (in dollars): {prediction}")
|
| 44 |
+
else:
|
| 45 |
+
st.error(f"Error making prediction. Status code: {response.status_code}")
|
| 46 |
+
st.error(f"Response: {response.text}")
|
| 47 |
+
|
| 48 |
+
# Removed batch prediction section as it's commented out in the backend Flask app
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
requirements.txt
CHANGED
|
@@ -1,11 +1,3 @@
|
|
| 1 |
pandas==2.2.2
|
| 2 |
-
numpy==2.0.2
|
| 3 |
-
scikit-learn==1.6.1
|
| 4 |
-
xgboost==2.1.4
|
| 5 |
-
joblib==1.4.2
|
| 6 |
-
Werkzeug==2.2.2
|
| 7 |
-
flask==2.2.2
|
| 8 |
-
gunicorn==20.1.0
|
| 9 |
requests==2.28.1
|
| 10 |
-
uvicorn[standard]
|
| 11 |
streamlit==1.43.2
|
|
|
|
| 1 |
pandas==2.2.2
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2 |
requests==2.28.1
|
|
|
|
| 3 |
streamlit==1.43.2
|