| # import streamlit as st | |
| # import pandas as pd | |
| # import pickle | |
| # # Load your trained model #pickle.load() requires a file object opened in binary read mode ('rb'). | |
| # with open('models/sales_prediction_pipeline.pkl', 'rb') as file: | |
| # model = pickle.load(file) | |
| # # Function to predict sales | |
| # def predict_sales(input_data): | |
| # # Make predictions using the loaded model | |
| # sales_prediction = model.predict(input_data) | |
| # return sales_prediction | |
| # # ///////////////////////////////////////////// Streamlit app ////////////////////////////////////////// | |
| # def main(): | |
| # st.title('Sales Prediction App') | |
| # st.image("images\\r1.jpg", caption="Rossmann") | |
| # # Input widgets | |
| # PromoInterval = st.selectbox("Promo Interval", ['No Promotion', 'Jan,Apr,Jul,Oct', 'Feb,May,Aug,Nov', 'Mar,Jun,Sept,Dec']) | |
| # # ----------------------------------------------------------------------------------------------- | |
| # StoreType = st.radio("StoreType", ["Small Shop", "Medium Store", "Large Store", "Hypermarket"]) | |
| # Assortment = st.radio("Assortment", ["basic", "extra", "extended"]) | |
| # # Encode StateHoliday as 1 for 'Yes' and 0 for 'No' -------------------------------------- | |
| # StateHoliday = st.radio("State Holiday", ["Yes", "No"]) | |
| # StateHoliday = 1 if StateHoliday == "Yes" else 0 | |
| # SchoolHoliday = st.radio("School Holiday", ["Yes", "No"]) | |
| # SchoolHoliday = 1 if SchoolHoliday == "Yes" else 0 | |
| # Promo = st.radio("Promotion", ["store is participating", "store is not participating"]) | |
| # Promo = 1 if Promo == "store is participating" else 0 | |
| # # ---------------------------------------------------------------------------------------- | |
| # Store = st.slider("Store", 1, 1115) | |
| # Customers = st.slider("Customers", 0, 7388) | |
| # CompetitionDistance = st.slider("Competition Distance", 20, 75860) | |
| # CompetitionOpenSinceMonth = st.slider("Competition Open Since Month", 1, 12) | |
| # CompetitionOpenSinceYear = st.slider("Competition Open Since Year", 1998, 2015) | |
| # # ---------------------------------------------------------------------------------------- | |
| # # Store user inputs | |
| # input_data = pd.DataFrame({ | |
| # 'PromoInterval': [PromoInterval], | |
| # 'StoreType': [StoreType], | |
| # 'Assortment': [Assortment], | |
| # 'StateHoliday': [StateHoliday], | |
| # 'Store': [Store], | |
| # 'Customers': [Customers], | |
| # 'Promo': [Promo], | |
| # 'SchoolHoliday': [SchoolHoliday], | |
| # 'CompetitionDistance': [CompetitionDistance], | |
| # 'CompetitionOpenSinceMonth': [CompetitionOpenSinceMonth], | |
| # 'CompetitionOpenSinceYear': [CompetitionOpenSinceYear] | |
| # }) | |
| # # Display input data | |
| # st.subheader('Input Data:') | |
| # st.write(input_data) | |
| # # Predict sales | |
| # if st.button('Predict Sales'): | |
| # prediction = predict_sales(input_data)[0] | |
| # formatted_prediction = "{:.2f}".format(prediction) # Format prediction to display two decimal points | |
| # st.write('Predicted Sales:', formatted_prediction) | |
| # if __name__ == '__main__': | |
| # main() | |
| # # Record at index 795018: | |
| # # PromoInterval Jan,Apr,Jul,Oct | |
| # # StoreType Small Shop | |
| # # Assortment basic | |
| # # StateHoliday 0 | |
| # # SchoolHoliday 0 | |
| # # Promo 1 | |
| # # Store 650 | |
| # # Customers 636 | |
| # # CompetitionDistance 1420 | |
| # # CompetitionOpenSinceMonth 10 | |
| # # CompetitionOpenSinceYear 2012 | |
| # # Sales 6322 | |
| # # Name: 795018, dtype: object | |
| import streamlit as st | |
| import pandas as pd | |
| import pickle | |
| # Load your trained pipeline | |
| with open(r'models/sales_prediction_pipeline.pkl', 'rb') as file: # Use raw string or forward slashes | |
| model = pickle.load(file) | |
| # Function to predict sales | |
| def predict_sales(input_data): | |
| # Make predictions using the loaded model | |
| sales_prediction = model.predict(input_data) | |
| return sales_prediction | |
| # Streamlit app | |
| def main(): | |
| st.title('Sales Prediction App') | |
| st.image("images/r1.jpg", caption="Rossmann") # Use forward slashes for image path | |
| # Input widgets | |
| PromoInterval = st.selectbox("Promo Interval", ['No Promotion', 'Jan,Apr,Jul,Oct', 'Feb,May,Aug,Nov', 'Mar,Jun,Sept,Dec']) | |
| StoreType = st.radio("StoreType", ["Small Shop", "Medium Store", "Large Store", "Hypermarket"]) | |
| Assortment = st.radio("Assortment", ["basic", "extra", "extended"]) | |
| # Encode StateHoliday as 1 for 'Yes' and 0 for 'No' | |
| StateHoliday = st.radio("State Holiday", ["Yes", "No"]) | |
| StateHoliday = 1 if StateHoliday == "Yes" else 0 | |
| SchoolHoliday = st.radio("School Holiday", ["Yes", "No"]) | |
| SchoolHoliday = 1 if SchoolHoliday == "Yes" else 0 | |
| Promo = st.radio("Promotion", ["store is participating", "store is not participating"]) | |
| Promo = 1 if Promo == "store is participating" else 0 | |
| Store = st.slider("Store", 1, 1115) | |
| Customers = st.slider("Customers", 0, 7388) | |
| CompetitionDistance = st.slider("Competition Distance", 20, 75860) | |
| CompetitionOpenSinceMonth = st.slider("Competition Open Since Month", 1, 12) | |
| CompetitionOpenSinceYear = st.slider("Competition Open Since Year", 1998, 2015) | |
| # Store user inputs | |
| input_data = pd.DataFrame({ | |
| 'PromoInterval': [PromoInterval], | |
| 'StoreType': [StoreType], | |
| 'Assortment': [Assortment], | |
| 'StateHoliday': [StateHoliday], | |
| 'Store': [Store], | |
| 'Customers': [Customers], | |
| 'Promo': [Promo], | |
| 'SchoolHoliday': [SchoolHoliday], | |
| 'CompetitionDistance': [CompetitionDistance], | |
| 'CompetitionOpenSinceMonth': [CompetitionOpenSinceMonth], | |
| 'CompetitionOpenSinceYear': [CompetitionOpenSinceYear] | |
| }) | |
| # Display input data | |
| st.subheader('Input Data:') | |
| st.write(input_data) | |
| # Predict sales | |
| if st.button('Predict Sales'): | |
| try: | |
| prediction = predict_sales(input_data)[0] # Get the first prediction | |
| formatted_prediction = "{:.2f}".format(prediction) # Format prediction to two decimal points | |
| st.write('Predicted Sales:', formatted_prediction) | |
| except Exception as e: | |
| st.error(f"An error occurred: {e}") | |
| if __name__ == '__main__': | |
| main() | |