Spaces:
Runtime error
Runtime error
| import streamlit as st | |
| import pandas as pd | |
| import numpy as np | |
| from sklearn.ensemble import RandomForestRegressor | |
| import joblib | |
| st.title('Restaurant Revenue Predictor') | |
| # Create input form | |
| st.write('Enter restaurant details:') | |
| # City selection | |
| city = st.selectbox('City', ['Istanbul', 'Ankara', 'Izmir', 'Other Cities']) | |
| # Adding description for Type | |
| st.write(""" | |
| **Type**: Type of the restaurant | |
| - FC: Food Court | |
| - IL: Inline | |
| - DT: Drive Thru | |
| - MB: Mobile | |
| """) | |
| type = st.selectbox('Type', ['FC', 'IL', 'DT', 'MB']) | |
| # Create a simple model for demonstration | |
| def create_model(): | |
| model = RandomForestRegressor( | |
| n_estimators=100, | |
| max_depth=10, | |
| random_state=42 | |
| ) | |
| # Create some sample training data | |
| X_train = pd.DataFrame({ | |
| 'City Group_Big Cities': [1, 0, 1, 0], | |
| 'City Group_Other': [0, 1, 0, 1], | |
| 'Type_DT': [1, 0, 0, 0], | |
| 'Type_FC': [0, 1, 0, 0], | |
| 'Type_IL': [0, 0, 1, 0], | |
| 'Type_MB': [0, 0, 0, 1], | |
| 'days': [1000, 800, 600, 400] | |
| }) | |
| y_train = np.array([1500000, 1000000, 800000, 500000]) | |
| model.fit(X_train, y_train) | |
| return model | |
| if st.button('Predict Revenue'): | |
| # Map city to City Group | |
| city_group = 'Big Cities' if city in ['Istanbul', 'Ankara', 'Izmir'] else 'Other' | |
| # Create input dataframe | |
| input_data = pd.DataFrame({ | |
| 'City Group_Big Cities': [1 if city_group == 'Big Cities' else 0], | |
| 'City Group_Other': [1 if city_group == 'Other' else 0], | |
| 'Type_DT': [1 if type == 'DT' else 0], | |
| 'Type_FC': [1 if type == 'FC' else 0], | |
| 'Type_IL': [1 if type == 'IL' else 0], | |
| 'Type_MB': [1 if type == 'MB' else 0], | |
| 'days': [500] # default value | |
| }) | |
| try: | |
| # Get model | |
| model = create_model() | |
| # Make prediction | |
| prediction = model.predict(input_data)[0] | |
| # Format prediction | |
| formatted_prediction = f"${prediction:,.2f}" | |
| # Display prediction with additional context | |
| st.success(f'Predicted Revenue: {formatted_prediction}') | |
| # Add some context about the prediction | |
| st.info(""" | |
| Note: This is a simplified model for demonstration purposes. | |
| The prediction is based on limited training data and should be used as a rough estimate only. | |
| """) | |
| except Exception as e: | |
| st.error(f"Error making prediction: {str(e)}") |