Update app.py
Browse files
app.py
CHANGED
|
@@ -0,0 +1,44 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import pandas as pd
|
| 2 |
+
import gradio as gr
|
| 3 |
+
import joblib
|
| 4 |
+
|
| 5 |
+
|
| 6 |
+
le=joblib.load('le_col.pkl')
|
| 7 |
+
std=joblib.load('std_col.pkl')
|
| 8 |
+
lr=joblib.load('model.pkl')
|
| 9 |
+
|
| 10 |
+
|
| 11 |
+
le_col=['Product_Category','Customer_Segment']
|
| 12 |
+
std_col=['Price','Discount','Marketing_Spend','Units_Sold']
|
| 13 |
+
|
| 14 |
+
|
| 15 |
+
def prediction_commerce_price(pc,p,d,cs,ms,us):
|
| 16 |
+
try:
|
| 17 |
+
input_data=pd.DataFrame({
|
| 18 |
+
'Product_Category':[pc],
|
| 19 |
+
'Price':[p],
|
| 20 |
+
'Discount':[d],
|
| 21 |
+
'Customer_Segment':[cs],
|
| 22 |
+
'Marketing_Spend':[ms],
|
| 23 |
+
'Units_Sold':[us]
|
| 24 |
+
})
|
| 25 |
+
for col in le_col:
|
| 26 |
+
input_data[col]=le[col].transform(input_data[col])
|
| 27 |
+
input_data[std_col]=std.transform(input_data[std_col])
|
| 28 |
+
prediction=lr.predict(input_data)
|
| 29 |
+
return prediction[0]
|
| 30 |
+
except Exception as e:
|
| 31 |
+
return str(e)
|
| 32 |
+
gr.Interface(
|
| 33 |
+
inputs=[
|
| 34 |
+
gr.Dropdown(['Electronics','Sports','Toys','Home Decor','Fashion'],label='Product_Category'),
|
| 35 |
+
gr.Number(label='Price'),
|
| 36 |
+
gr.Number(label='Discount'),
|
| 37 |
+
gr.Dropdown(['Regular','Occasional','Premium'],label='Customer_Segment'),
|
| 38 |
+
gr.Number(label='Marketing_Spend'),
|
| 39 |
+
gr.Number(label='Units_Sold')
|
| 40 |
+
],
|
| 41 |
+
fn=prediction_commerce_price,
|
| 42 |
+
outputs=gr.Textbox(label='Prediction'),
|
| 43 |
+
title='Prediction_program'
|
| 44 |
+
).launch()
|