Kopec-B/pricing-optimization
0
1import gradio as gr
2import pandas as pd
3import numpy as np
4import joblib
5
6# Load the pre-trained model
7model = joblib.load('pricing_optimization_model.pkl')
8
9
10# Function to predict order demand
11def predict_order_demand(year, month, day, demand_elasticity, warehouse_whse_j, warehouse_whse_s, category_003,
12 category_004, category_005, category_006, category_007, category_008, category_009,
13 category_011, category_013, category_015, category_017, category_018, category_019,
14 category_020, category_021, category_022, category_023, category_024, category_025,
15 category_026, category_028, category_030, category_031, category_032, category_033):
16 # Prepare the input data as a pandas DataFrame
17 input_data = pd.DataFrame({
18 'Year': [year],
19 'Month': [month],
20 'Day': [day],
21 'Demand_Elasticity': [demand_elasticity],
22 'Warehouse_Whse_J': [warehouse_whse_j],
23 'Warehouse_Whse_S': [warehouse_whse_s],
24 'Product_Category_Category_003': [category_003],
25 'Product_Category_Category_004': [category_004],
26 'Product_Category_Category_005': [category_005],
27 'Product_Category_Category_006': [category_006],
28 'Product_Category_Category_007': [category_007],
29 'Product_Category_Category_008': [category_008],
30 'Product_Category_Category_009': [category_009],
31 'Product_Category_Category_011': [category_011],
32 'Product_Category_Category_013': [category_013],
33 'Product_Category_Category_015': [category_015],
34 'Product_Category_Category_017': [category_017],
35 'Product_Category_Category_018': [category_018],
36 'Product_Category_Category_019': [category_019],
37 'Product_Category_Category_020': [category_020],
38 'Product_Category_Category_021': [category_021],
39 'Product_Category_Category_022': [category_022],
40 'Product_Category_Category_023': [category_023],
41 'Product_Category_Category_024': [category_024],
42 'Product_Category_Category_025': [category_025],
43 'Product_Category_Category_026': [category_026],
44 'Product_Category_Category_028': [category_028],
45 'Product_Category_Category_030': [category_030],
46 'Product_Category_Category_031': [category_031],
47 'Product_Category_Category_032': [category_032],
48 'Product_Category_Category_033': [category_033]
49 })
50
51 # Use the model to predict the order demand
52 prediction = model.predict(input_data)
53
54 return prediction[0]
55
56
57# Define the Gradio interface
58iface = gr.Interface(
59 fn=predict_order_demand,
60 inputs=[
61 gr.Slider(minimum=2012, maximum=2025, step=1, label="Year", value=2022),
62 gr.Slider(minimum=1, maximum=12, step=1, label="Month", value=6),
63 gr.Slider(minimum=1, maximum=31, step=1, label="Day", value=15),
64 gr.Slider(minimum=-1.0, maximum=1.0, step=0.1, label="Demand Elasticity", value=0.05),
65 gr.Slider(minimum=0, maximum=1, step=1, label="Warehouse Whse_J", value=0),
66 gr.Slider(minimum=0, maximum=1, step=1, label="Warehouse Whse_S", value=0),
67 gr.Slider(minimum=0, maximum=1, step=1, label="Category 003", value=0),
68 gr.Slider(minimum=0, maximum=1, step=1, label="Category 004", value=0),
69 gr.Slider(minimum=0, maximum=1, step=1, label="Category 005", value=0),
70 gr.Slider(minimum=0, maximum=1, step=1, label="Category 006", value=0),
71 gr.Slider(minimum=0, maximum=1, step=1, label="Category 007", value=0),
72 gr.Slider(minimum=0, maximum=1, step=1, label="Category 008", value=0),
73 gr.Slider(minimum=0, maximum=1, step=1, label="Category 009", value=0),
74 gr.Slider(minimum=0, maximum=1, step=1, label="Category 011", value=0),
75 gr.Slider(minimum=0, maximum=1, step=1, label="Category 013", value=0),
76 gr.Slider(minimum=0, maximum=1, step=1, label="Category 015", value=0),
77 gr.Slider(minimum=0, maximum=1, step=1, label="Category 017", value=0),
78 gr.Slider(minimum=0, maximum=1, step=1, label="Category 018", value=0),
79 gr.Slider(minimum=0, maximum=1, step=1, label="Category 019", value=0),
80 gr.Slider(minimum=0, maximum=1, step=1, label="Category 020", value=0),
81 gr.Slider(minimum=0, maximum=1, step=1, label="Category 021", value=0),
82 gr.Slider(minimum=0, maximum=1, step=1, label="Category 022", value=0),
83 gr.Slider(minimum=0, maximum=1, step=1, label="Category 023", value=0),
84 gr.Slider(minimum=0, maximum=1, step=1, label="Category 024", value=0),
85 gr.Slider(minimum=0, maximum=1, step=1, label="Category 025", value=0),
86 gr.Slider(minimum=0, maximum=1, step=1, label="Category 026", value=0),
87 gr.Slider(minimum=0, maximum=1, step=1, label="Category 028", value=0),
88 gr.Slider(minimum=0, maximum=1, step=1, label="Category 030", value=0),
89 gr.Slider(minimum=0, maximum=1, step=1, label="Category 031", value=0),
90 gr.Slider(minimum=0, maximum=1, step=1, label="Category 032", value=0),
91 gr.Slider(minimum=0, maximum=1, step=1, label="Category 033", value=0)
92 ],
93 outputs=gr.Number(label="Predicted Order Demand")
94)
95
96# Launch the Gradio app with sharing enabled
97iface.launch(share=True)
98 