Team Ai
Apppublic

ThirdEyeData/Price_Optimization

sourceHugging Faceupdated 4y agoView on Hugging Face
3likes
app.py54 linesDownload Raw Back to root
1import numpy as np2import math3import matplotlib.pyplot as plt4import seaborn as sns5plt.style.use('seaborn-white')6import pandas as pd7from matplotlib import animation, rc8import torch.nn.functional as F9import torch10import torch.nn as nn11import torch.optim as optim12plt.rcParams.update({'pdf.fonttype': 'truetype'})13import pickle14pc2 = pickle.load(open('price.pkl','rb'))15from PIL import Image 16import streamlit as st17 18st.title("Price Optimization")19 20def to_tensor(x):21    return torch.from_numpy(np.array(x).astype(np.float32))22def prediction(price_max,price_step,policy_net):23    price_grid = np.arange(price_step, price_max, price_step)24    sample_state = [0.,   0.,   0.,   0.,   0.,   0.,   0.,   0.,   0.,   0.,   0.,   0.,   0.,   0.,   0.,   0.,   0.,   0.,   0.,   0., \25                1.,     0.,   0.,   0.,   0.,   0.,   0.,   0.,   0.,   0.,   0.,   0.,   0.,   0.,   0.,   0.,   0.,   0.,   0.,   0.]26    Q_s = policy_net(to_tensor(sample_state))27    a_opt = Q_s.max(0)[1].detach()28    plt.figure(figsize=(16, 5))29    plt.xlabel("Price action ($)")30    plt.ylabel("Q ($)")31    plt.bar(price_grid, Q_s.detach().numpy(), color='crimson',  width=6, alpha=0.8)32    plt.savefig('price.png')    33    return price_grid[a_opt]34    35def fun():36    st.header("Optimal Price Action")37    st.subheader(str(a))38    39    return 40st.header("Enter the Specification")41max_value = st.number_input('Enter the Maximum Value of Price',min_value=50,value = 500,step=1)42step = st.number_input('Enter the Price step',min_value = 10,value = 10,step=1)43a = prediction(max_value,step,pc2)44if st.button('Predict'):45    fun()46    image = Image.open('price.png')47    st.image(image,caption = 'Price Optimization',width =1000)48     49 50 51 52 53    54