File size: 3,401 Bytes
da7758c
 
 
 
 
 
 
 
 
 
 
 
7669e12
da7758c
db9494d
da7758c
 
04bf437
da7758c
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import streamlit as st
import pandas as pd
import requests

# Set the title of the Streamlit app
st.title("Supar Kart Price Prediction")

# Section for online prediction
st.subheader("Online Prediction")

# Collect user input for property features
product_type = st.selectbox("Product Type", ["Perishable", "Non Perishable"])
store_size = st.selectbox("Store Size", ["Small", "Medium", "Large"])
store_location = st.selectbox("Store Location", ["Tier 1", "Tier 2", "Tier 3"])
store_type = st.selectbox("Store Type", ["Supermarket Type1", "Supermarket Type2", "Food Mart"])
allocated_area = st.number_input("Allocated Area", min_value=0, step=1, value=1)
product_mrp = st.number_input("Product MRP", min_value=0, step=1, value=1)
store_year = st.number_input("Store Established Year", min_value=1990, max_value=2024,step=1, value=2020)
product_weight = st.number_input("Product Weight", min_value=0, step=1, value=1)
sugar = st.selectbox("Sugar", ["Regular", "No Sugar", "Low Sugar"])
store_id = st.selectbox("Store ID", ["OUT001", "OUT002", "OUT003", "OUT004"])
                       
# Convert user input into a DataFrame
input_data = pd.DataFrame([{
    'Product_Weight': product_weight,
    'Product_Allocated_Area': allocated_area,
    'Product_MRP': product_mrp,
    'Store_Age': 2025-store_year,
    'Product_Type_P': 0 if product_type=="Perishable" else 1,
    'Store_Id_OUT002': 1 if store_id == "OUT002" else 0,
    'Store_Id_OUT003': 1 if store_id == "OUT003" else 0,
    'Store_Id_OUT004': 1 if store_id == "OUT004" else 0,
    'Store_Size_Medium': 1 if store_size == "Medium" else 0,
    'Store_Size_Small': 1 if store_size == "Small" else 0,
    'Store_Location_City_Type_Tier 2': 1 if store_location == "Tier 2" else 0,
    'Store_Location_City_Type_Tier 3': 1 if store_location == "Tier 3" else 0,
    'Store_Type_Food Mart': 1 if store_type == "Food Mart" else 0,
    'Store_Type_Supermarket Type1': 1 if store_type == "Supermarket Type1" else 0,
    'Store_Type_Supermarket Type2': 1 if store_type == "Supermarket Type2" else 0,
    'Sugar_No': 1 if sugar == "No Sugar" else 0,
    'Sugar_Reg': 1 if sugar == "Regular" else 0
}])

# Make prediction when the "Predict" button is clicked
if st.button("Predict"):
    response = requests.post("https://<username>-<repo_id>.hf.space/v1/superkart", json=input_data.to_dict(orient='records')[0])  # Send data to Flask API
    if response.status_code == 200:
        prediction = response.json()['Predicted Price (in dollars)']
        st.success(f"Predicted Product Price (in dollars): {prediction}")
    else:
        st.error("Error making prediction.")

# # Section for batch prediction
# st.subheader("Batch Prediction")

# # Allow users to upload a CSV file for batch prediction
# uploaded_file = st.file_uploader("Upload CSV file for batch prediction", type=["csv"])

# # Make batch prediction when the "Predict Batch" button is clicked
# if uploaded_file is not None:
#     if st.button("Predict Batch"):
#         response = requests.post("https://<username>-<repo_id>.hf.space/v1/rentalbatch", files={"file": uploaded_file})  # Send file to Flask API
#         if response.status_code == 200:
#             predictions = response.json()
#             st.success("Batch predictions completed!")
#             st.write(predictions)  # Display the predictions
#         else:
#             st.error("Error making batch prediction.")