themeetjani commited on
Commit
7241c5d
1 Parent(s): 052097d

Upload reg.py

Browse files
Files changed (1) hide show
  1. pages/reg.py +34 -0
pages/reg.py ADDED
@@ -0,0 +1,34 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ from streamlit import session_state
3
+ import joblib
4
+ from io import StringIO
5
+ import json
6
+ import os
7
+ import pandas as pd
8
+ import numpy as np
9
+ import matplotlib.pyplot as plt
10
+
11
+ def find_optimal_price(data, model, buying_price):
12
+ start_price = data.PRICE.min() - 1 # start price
13
+ end_price = data.PRICE.min() + 10 # end price
14
+ test = pd.DataFrame(columns = ["PRICE", "QUANTITY"]) # choose required columns
15
+ test['PRICE'] = np.arange(start_price, end_price,0.01)
16
+ test['QUANTITY'] = model.predict(test['PRICE']) # make predictions
17
+ test['PROFIT'] = (test["PRICE"] - buying_price) * test["QUANTITY"]
18
+ plt.plot(test['PRICE'],test['QUANTITY']) # plot the results
19
+ plt.plot(test['PRICE'],test['PROFIT'])
20
+ plt.show()
21
+ ind = np.where(test['PROFIT'] == test['PROFIT'].max())[0][0]
22
+ values_at_max_profit = test.iloc[[ind]]
23
+ return values_at_max_profit
24
+ model = joblib.load("burger_model.sav")
25
+ uploaded_file = st.file_uploader("Choose a file")
26
+ if uploaded_file:
27
+ # Read data from file
28
+ df = pd.read_csv(uploaded_file)
29
+
30
+ # Clean data
31
+ df = df[df['PRICE'].notna()].reset_index(drop=True)
32
+ buying_price = st.slider("Select buying price", min_value=9, max_value=15, value=1, step=1)
33
+ result = find_optimal_price(df,model,buying_price)
34
+ st.text_area("PRICE Should be to achive maximum profit", value=list(result.to_dict()['PRICE'].values())[0])