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

commit app.py

Browse files
Files changed (1) hide show
  1. app.py +19 -43
app.py CHANGED
@@ -1,50 +1,26 @@
1
-
2
- import streamlit as st
3
- import pandas as pd
4
  import joblib
5
- import numpy as np
6
-
7
- # Load the trained model
8
- @st.cache_resource
9
- def load_model():
10
- return joblib.load("superkart_price_prediction_model_v1_0.joblib")
11
-
12
- model = load_model()
13
 
14
- # Streamlit UI for Price Prediction
15
- st.title("SuperKart Rental Price Prediction App")
16
- st.write("This tool predicts the price of an Superkart total sales based on the property type.")
17
 
18
- st.subheader("Enter the listing details:")
 
19
 
20
- # Collect user input
21
- product_Weight=st.number_input("Product_Weight", min_value=1, value=30.00)
22
- product_Sugar_Content=st.selectbox("Product Sugar Content", ["Low Sugar", "No Sugar", "Regular"])
23
- product_Allocated_Area=st.number_input("Product Allocate Area", min_value=0.001, value=0.09)
24
- 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"])
25
- product_MRP=st.number_input("Product MRP", min_value=1, value=30.00)
26
- store_Id=st.selectbox("Store ID", ["OUT001", "OUT002", "OUT003", "OUT004"])
27
- store_Establishment_Year=st.number_input("Store Establishment year", min_value=1987, value=2009)
28
- store_Size=st.selectbox("Store Size", ["High", "Medium", "Small"])
29
- store_Location_City_Type=st.selectbox("Store location City", ["Tier1", "Tier2", "Tier3"])
30
- store_Type=st.selectbox("Store Type", ["Departmental Store", "Supermarket Type 1", "Supermarket Type 2", "Food Mart"])
31
 
 
 
32
 
33
- # Convert user input into a DataFrame
34
- input_data = pd.DataFrame([{
35
- 'product_Weight': product_Weight,
36
- 'product_Sugar_Content': product_Sugar_Content,
37
- 'product_Allocated_Area': product_Allocated_Area,
38
- 'product_Type': product_Type,
39
- 'product_MRP': product_MRP,
40
- 'store_Id': store_Id,
41
- 'store_Establishment_Year': store_Establishment_Year,
42
- 'store_Size': store_Size,
43
- 'store_Location_City_Type': store_Location_City_Type,
44
- 'store_Type': store_Type
45
- }])
46
 
47
- # Predict button
48
- if st.button("Predict"):
49
- prediction = model.predict(input_data)
50
- st.write(f"The predicted price of the superkart sales is ${np.exp(prediction)[0]:.2f}.")
 
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)))