Spaces:
No application file
No application file
commit app.py
Browse files
app.py
CHANGED
|
@@ -1,50 +1,26 @@
|
|
| 1 |
-
|
| 2 |
-
import streamlit as st
|
| 3 |
-
import pandas as pd
|
| 4 |
import joblib
|
| 5 |
-
import
|
| 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 |
-
|
| 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 |
-
|
|
|
|
| 19 |
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
| 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 |
-
|
| 34 |
-
|
| 35 |
-
|
| 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 |
-
|
| 48 |
-
|
| 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)))
|
|
|
|
|
|