Spaces:
Runtime error
Runtime error
File size: 1,558 Bytes
a51e3be ea4f501 1535cde ee7ba54 a51e3be f023bc7 ae731d9 306c1b6 ae731d9 480a57f ae731d9 306c1b6 ae731d9 91b1fc9 f023bc7 ae731d9 b140b5b dcf61b5 b140b5b dcf61b5 ae731d9 79b3404 62ffabc |
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 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
import numpy as np
import math
import matplotlib.pyplot as plt
import seaborn as sns
plt.style.use('seaborn-white')
import pandas as pd
from matplotlib import animation, rc
import torch.nn.functional as F
import torch
import torch.nn as nn
import torch.optim as optim
plt.rcParams.update({'pdf.fonttype': 'truetype'})
import pickle
pc2 = pickle.load(open('price.pkl','rb'))
import streamlit as st
st.title("Price Optimization")
def to_tensor(x):
return torch.from_numpy(np.array(x).astype(np.float32))
def prediction(price_max,price_step,policy_net):
price_grid = np.arange(price_step, price_max, price_step)
sample_state = [0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., \
1., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.]
Q_s = policy_net(to_tensor(sample_state))
a_opt = Q_s.max(0)[1].detach()
return price_grid[a_opt],Q_s.detach().numpy()
def fun():
st.header("Optimal Price Action")
st.subheader(str(a))
return
st.header("Enter the Specification")
max_value = st.number_input('Enter the Maximum Value of Price',min_value=50,value = 500,step=1)
step = st.number_input('Enter the Price step',min_value = 10,value = 10,step=1)
a,b = prediction(max_value,step,pc2)
if st.button('Predict'):
fun()
chart_data = pd.DataFrame(a,b,
columns=["a", "b"],x="Price action ($)",y="Q ($)",width=6)
st.bar_chart(chart_data)
|