import gradio as gr import pandas as pd import joblib age_input = gr.Number(label="Age") duration_input = gr.Number(label='Duration(Sec)') cc_contact_freq_input = gr.Number(label='CC Contact Freq') days_since_pc_input = gr.Number(label='Days Since PC') pc_contact_freq_input = gr.Number(label='Pc Contact Freq') job_input = gr.Dropdown(['admin.', 'blue-collar', 'technician', 'services', 'management', 'retired', 'entrepreneur', 'self-employed', 'housemaid', 'unemployed', 'student', 'unknown'],label="Job") marital_input = gr.Dropdown(['married', 'single', 'divorced', 'unknown'],label='Marital Status') education_input = gr.Dropdown(['experience', 'university degree', 'high school', 'professional.course', 'Others', 'illiterate'],label='Education') defaulter_input = gr.Dropdown(['no', 'unknown', 'yes'],label='Defaulter') home_loan_input = gr.Dropdown(['yes', 'no', 'unknown'],label='Home Loan') personal_loan_input = gr.Dropdown(['yes', 'no', 'unknown'],label='Personal Loan') communication_type_input = gr.Dropdown(['cellular', 'telephone'],label='Communication Type') last_contacted_input = gr.Dropdown(['may', 'jul', 'aug', 'jun', 'nov', 'apr', 'oct', 'mar', 'sep', 'dec'],label='Last Contacted') day_of_week_input = gr.Dropdown(['thu', 'mon', 'wed', 'tue', 'fri'],label='Day of Week') pc_outcome_input = gr.Dropdown(['nonexistent', 'failure', 'success'], label='PC Outcome') o = gr.Textbox() # load the model model = joblib.load('model.joblib') i2l = ['Not subscribed', 'Subscribed'] def fn(age, duration, cc_contact_freq, days_since_pc, pc_contact_freq, job, marital_status, education, defaulter, home_loan, personal_loan, communication_type, last_contacted, day_of_week, pc_outcome): sample = { 'Age': age, 'Duration(Sec)': duration, 'CC Contact Freq': cc_contact_freq, 'Days Since PC': days_since_pc, 'PC Contact Freq': pc_contact_freq, 'Job': job, 'Marital Status': marital_status, 'Education': education, 'Defaulter': defaulter, 'Home Loan': home_loan, 'Personal Loan': personal_loan, 'Communication Type': communication_type, 'Last Contacted': last_contacted, 'Day of Week': day_of_week, 'PC Outcome': pc_outcome, } print(f'sample: {sample}') data_point = pd.DataFrame([sample]) print(f'{data_point}') result = model.predict(data_point) result = result[0] print(result) return i2l[result] interface = gr.Interface(fn, inputs = [age_input, duration_input, cc_contact_freq_input, days_since_pc_input, pc_contact_freq_input, job_input, marital_input, education_input, defaulter_input, home_loan_input, personal_loan_input, communication_type_input, last_contacted_input, day_of_week_input, pc_outcome_input], outputs = o) interface.launch(share=True)