File size: 1,446 Bytes
7241c5d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
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])