| import pandas as pd
|
| import joblib
|
| import gradio as gr
|
|
|
| le = joblib.load("le_col.pkl")
|
| scaler = joblib.load("scaler_col.pkl")
|
| rf = joblib.load("model.pkl")
|
|
|
|
|
| le_col = ['Region','Item Type','Order Priority','Sales Channel']
|
| scaler_col = ['Units Sold','Unit Price','Unit Cost','Total Cost','Total Profit']
|
|
|
|
|
| def prediction_sales_Revenue(RE,IT,SC,OP,US,UP,UC,TC,TP):
|
| try:
|
| input_data=pd.DataFrame({
|
| 'Region':[RE],
|
| 'Item Type':[IT],
|
| 'Sales Channel':[SC],
|
| 'Order Priority':[OP],
|
| 'Units Sold':[US],
|
| 'Unit Price':[UP],
|
| 'Unit Cost':[UC],
|
| 'Total Cost':[TC],
|
| 'Total Profit':[TP]
|
| })
|
| for col in le_col:
|
| input_data[col]=le[col].transform(input_data[col])
|
| input_data[scaler_col]=scaler.transform(input_data[scaler_col])
|
| prediction=rf.predict(input_data)
|
| return prediction[0]
|
| except Exception as e:
|
| return str(e)
|
| gr.Interface(
|
| inputs=[
|
| gr.Dropdown(['Europe','Sub-Saharan Africa','Asia','Middle East and North Africa',
|
| 'Central America and the Caribbean','Australia and Oceania','North America'],label='Region'),
|
| gr.Dropdown(['Personal Care','Household','Clothes','Baby Food','Office Supplies','Vegetables',
|
| 'Cosmetics','Cereal','Snacks','Meat','Fruits','Beverages'],label='Item Type'),
|
| gr.Dropdown(['Online','Offline'],label='Sales Channel'),
|
| gr.Dropdown(['C','H','L','M'],label='Order Priority'),
|
| gr.Number(label='Units Sold'),
|
| gr.Number(label='Unit Price'),
|
| gr.Number(label='Unit Cost'),
|
| gr.Number(label='Total Cost'),
|
| gr.Number(label='Total Profit')
|
| ],
|
| fn=prediction_sales_Revenue,
|
| outputs=gr.Textbox(label='Prediction')
|
| ).launch() |