Spaces:
Sleeping
Sleeping
| import streamlit as st | |
| from streamlit import session_state | |
| import joblib | |
| from io import StringIO | |
| import json | |
| import os | |
| import pandas as pd | |
| import numpy as np | |
| import matplotlib.pyplot as plt | |
| def find_optimal_price(data, model, buying_price): | |
| start_price = data.PRICE.min() - 1 # start price | |
| end_price = data.PRICE.min() + 10 # end price | |
| test = pd.DataFrame(columns = ["PRICE", "QUANTITY"]) # choose required columns | |
| test['PRICE'] = np.arange(start_price, end_price,0.01) | |
| test['QUANTITY'] = model.predict(test['PRICE']) # make predictions | |
| test['PROFIT'] = (test["PRICE"] - buying_price) * test["QUANTITY"] | |
| plt.plot(test['PRICE'],test['QUANTITY']) # plot the results | |
| plt.plot(test['PRICE'],test['PROFIT']) | |
| plt.show() | |
| ind = np.where(test['PROFIT'] == test['PROFIT'].max())[0][0] | |
| values_at_max_profit = test.iloc[[ind]] | |
| return values_at_max_profit | |
| model = joblib.load("burger_model.sav") | |
| uploaded_file = st.file_uploader("Choose a file") | |
| if uploaded_file: | |
| # Read data from file | |
| df = pd.read_csv(uploaded_file) | |
| # Clean data | |
| df = df[df['PRICE'].notna()].reset_index(drop=True) | |
| buying_price = st.slider("Select buying price", min_value=9, max_value=15, value=1, step=1) | |
| result = find_optimal_price(df,model,buying_price) | |
| st.text_area("PRICE Should be to achive maximum profit", value=list(result.to_dict()['PRICE'].values())[0]) |