LalithaShiva commited on
Commit
eede90e
·
verified ·
1 Parent(s): 129284f

commit app.py

Browse files
Files changed (1) hide show
  1. app.py +42 -19
app.py CHANGED
@@ -1,26 +1,49 @@
1
- from flask import Flask, request, jsonify
2
- import joblib
3
  import pandas as pd
4
-
5
- app = Flask(__name__)
6
 
7
  # Load the trained model
8
- model = joblib.load("deployment_files/superkart_price_prediction_model_v1_0.joblib")
 
 
 
 
 
 
 
 
 
 
9
 
10
- @app.route('/predict', methods=['POST'])
11
- def predict():
12
- try:
13
- data = request.get_json()
14
- # Assuming the input data is in a JSON format similar to the training data.
15
- # You might need to adjust this part based on your actual input format.
16
- input_df = pd.DataFrame([data]) # Convert input JSON to DataFrame
 
 
 
 
17
 
18
- # Make predictions
19
- prediction = model.predict(input_df)
20
 
21
- return jsonify({'prediction': prediction.tolist()})
22
- except Exception as e:
23
- return jsonify({'error': str(e)}), 500
 
 
 
 
 
 
 
 
 
 
24
 
25
- if __name__ == '__main__':
26
- app.run(debug=True, host='0.0.0.0', port=int(os.environ.get('PORT', 8082)))
 
 
 
1
+ import streamlit as st
 
2
  import pandas as pd
3
+ import joblib
4
+ import numpy as np
5
 
6
  # Load the trained model
7
+ @st.cache_resource
8
+ def load_model():
9
+ return joblib.load("superkart_price_prediction_model_v1_0.joblib")
10
+
11
+ model = load_model()
12
+
13
+ # Streamlit UI for Price Prediction
14
+ st.title("SuperKart Rental Price Prediction App")
15
+ st.write("This tool predicts the price of an Superkart total sales based on the property type.")
16
+
17
+ st.subheader("Enter the listing details:")
18
 
19
+ # Collect user input
20
+ product_Weight=st.number_input("Product_Weight", min_value=1, value=30.00)
21
+ product_Sugar_Content=st.selectbox("Product Sugar Content", ["Low Sugar", "No Sugar", "Regular"])
22
+ product_Allocated_Area=st.number_input("Product Allocate Area", min_value=0.001, value=0.09)
23
+ product_Type=st.selectbox("Product Type", ["meat", "snack foods", "hard drinks", "dairy", "canned", "soft drinks", "health and hygiene", "baking goods", "bread", "breakfast", "frozen foods", "fruits and vegetables", "household", "seafood", "starchy foods", "others"])
24
+ product_MRP=st.number_input("Product MRP", min_value=1, value=30.00)
25
+ store_Id=st.selectbox("Store ID", ["OUT001", "OUT002", "OUT003", "OUT004"])
26
+ store_Establishment_Year=st.number_input("Store Establishment year", min_value=1987, value=2009)
27
+ store_Size=st.selectbox("Store Size", ["High", "Medium", "Small"])
28
+ store_Location_City_Type=st.selectbox("Store location City", ["Tier1", "Tier2", "Tier3"])
29
+ store_Type=st.selectbox("Store Type", ["Departmental Store", "Supermarket Type 1", "Supermarket Type 2", "Food Mart"])
30
 
 
 
31
 
32
+ # Convert user input into a DataFrame
33
+ input_data = pd.DataFrame([{
34
+ 'product_Weight': product_Weight,
35
+ 'product_Sugar_Content': product_Sugar_Content,
36
+ 'product_Allocated_Area': product_Allocated_Area,
37
+ 'product_Type': product_Type,
38
+ 'product_MRP': product_MRP,
39
+ 'store_Id': store_Id,
40
+ 'store_Establishment_Year': store_Establishment_Year,
41
+ 'store_Size': store_Size,
42
+ 'store_Location_City_Type': store_Location_City_Type,
43
+ 'store_Type': store_Type
44
+ }])
45
 
46
+ # Predict button
47
+ if st.button("Predict"):
48
+ prediction = model.predict(input_data)
49
+ st.write(f"The predicted price of the superkart sales is ${np.exp(prediction)[0]:.2f}.")