Spaces:
Sleeping
Sleeping
| import pandas as pd | |
| import gradio as gr | |
| import joblib as jp | |
| model=jp.load('model.pkl') | |
| std = jp.load("std_col.pkl") | |
| le = jp.load("le_col.pkl") | |
| le_col=['gender','education','region','purchase_frequency','product_category'] | |
| std_col=['age','income','purchase_amount'] | |
| def Customer_Predction_Model(ag,gender,income,edu,reg,loy,pr,pu,prod,prom,sts): | |
| try: | |
| input_data=pd.DataFrame({ | |
| 'age':[ag], | |
| 'gender':[gender], | |
| 'income':[income], | |
| 'education':[edu], | |
| 'region':[reg], | |
| 'loyalty_status':[loy], | |
| 'purchase_frequency':[pr], | |
| 'purchase_amount':[pu], | |
| 'product_category':[prod], | |
| 'promotion_usage':[prom], | |
| 'satisfaction_score':[sts] | |
| }) | |
| for col in le_col: | |
| input_data[col]=le[col].transform(input_data[col]) | |
| input_data[std_col]=std.transform(input_data[std_col]) | |
| prediction=model.predict(input_data) | |
| if prediction[0]==0: | |
| return 'No' | |
| else: | |
| return 'Yes' | |
| except Exception as e: | |
| return str(e) | |
| gr.Interface( | |
| fn=Customer_Predction_Model, | |
| inputs=[ | |
| gr.Number(label='age'), | |
| gr.Dropdown(['Male','Female'],label='gender'), | |
| gr.Number(label='income'), | |
| gr.Dropdown(['College','Bachelor','HighSchool','Masters'],label='education'), | |
| gr.Dropdown(['East','West','South','North'],label='region'), | |
| gr.Number(label='loyalty_status'), | |
| gr.Dropdown(['rare','occasional','frequent'],label='purchase_frequency'), | |
| gr.Number(label='purchase_amount'), | |
| gr.Dropdown(['Electronics','Clothing','Books','Food','Health','Home','Beauty'],label='product_category'), | |
| gr.Number(label='promotion_usage'), | |
| gr.Number(label='satisfaction_score') | |
| ], | |
| outputs=gr.Textbox(label='Prediction'), | |
| title='Customer Purchase Anticipation Prediction Model' | |
| ).launch() | |