import pandas as pd import pickle import gradio as gr import sklearn # Load the preprocessor and model from the pickle files with open('preprocesor.pkl', 'rb') as file: preprocessor = pickle.load(file) with open('model.pkl', 'rb') as file: model = pickle.load(file) # Import the necessary library import gradio as gr from datetime import datetime # Get the current timestamp now = datetime.now() # Define the input components inputs = [ gr.Textbox(label="Timestamp", value=str(now.strftime("%Y-%m-%d %H:%M:%S"))), gr.Slider(1, 100,step=1, value=15, label="Age", info="Choose Age"), gr.Radio(["Male", "Female"], label="Gender", info="Please Enter you Gender"), gr.Dropdown(['United States', 'Canada', 'United Kingdom', 'Bulgaria', 'France', 'Portugal', 'Netherlands', 'Switzerland', 'Poland', 'Australia', 'Germany', 'Russia', 'Mexico', 'Brazil', 'Slovenia', 'Costa Rica', 'Austria', 'Ireland', 'India', 'South Africa', 'Italy', 'Sweden', 'Colombia', 'Latvia', 'Romania', 'Belgium', 'New Zealand', 'Zimbabwe', 'Spain', 'Finland', 'Uruguay', 'Israel', 'Bosnia and Herzegovina', 'Hungary', 'Singapore', 'Japan', 'Nigeria', 'Croatia', 'Norway', 'Thailand', 'Denmark', 'Bahamas, The', 'Greece', 'Moldova', 'Georgia', 'China', 'Czech Republic', 'Philippines'], label="Country", info="Select Country"), gr.Textbox(label="state", info="Enter state if applicable"), gr.Radio(["Yes", "No"], label="self_employed", info="Select Yes or No"), gr.Radio(["Yes", "No"], label="family_history", info="Select Yes or No"), gr.Dropdown(["Often", "Rarely", "Never"], label="work_interfere", info="Select how often work interferes with mental health"), gr.Dropdown(["1-5","6-25","26-100","100-500","500-1000","More than 1000"], label="no_employees", info="Select number of employees"), gr.Radio(["Yes", "No"], label="remote_work", info="Select Yes or No"), gr.Radio(["Yes", "No"], label="tech_company", info="Select Yes or No"), gr.Dropdown(["Yes", "No", "Don't know"], label="benefits", info="Select if the employer provides mental health benefits"), gr.Dropdown(["Yes", "No", "Not sure"], label="care_options", info="Select if the employer provides care options for mental health issues"), gr.Dropdown(["Yes", "No", "Don't know"], label="wellness_program", info="Select if the employer offers a wellness program"), gr.Dropdown(["Yes", "No", "Don't know"], label="seek_help", info="Select if the employer provides resources to seek help for mental health issues"), gr.Dropdown(["Yes", "No", "Don't know"], label="anonymity", info="Select if the employer protects anonymity when seeking help for mental health issues"), gr.Dropdown(["Very easy","Somewhat easy","Somewhat difficult","Very difficult"], label="leave", info="Select how easy it is to take leave for mental health issues"), gr.Dropdown(["Yes","Maybe","No"], label="mental_health_consequence", info="Select if there are consequences for discussing mental health issues with the employer"), gr.Dropdown(["Yes","Maybe","No"], label="phys_health_consequence", info="Select if there are consequences for discussing physical health issues with the employer"), gr.Dropdown(["Yes","Some of them","No"], label="coworkers", info="Select if you are willing to discuss mental health issues with your coworkers"), gr.Dropdown(["Yes","Some of them","No"], label="supervisor", info="Select if you are willing to discuss mental health issues with your supervisor"), gr.Dropdown(["Yes","Maybe","No"], label="mental_health_interview", info="Select if you would bring up mental health issues in a job interview"), gr.Dropdown(["Yes","Maybe","No"], label="phys_health_interview", info="Select if you would bring up physical health issues in a job interview"), gr.Dropdown(["Yes","Maybe","No"], label="mental_vs_physical", info= "Select if you think that your employer takes mental health as seriously as physical health"), gr.Radio(["Yes","No"], label="obs_consequence", info= "Select Yes or No") ] def predict(Timestamp, Age, Gender, Country, state, self_employed, family_history, work_interfere, no_employees, remote_work, tech_company, benefits, care_options, wellness_program, seek_help, anonymity, leave, mental_health_consequence, phys_health_consequence, coworkers, supervisor, mental_health_interview, phys_health_interview, mental_vs_physical, obs_consequence): # Create a new data point new_data = pd.DataFrame({ "Timestamp": [Timestamp], "Age": [Age], "Gender": [Gender], "Country": [Country], "state": [state], "self_employed": [self_employed], "family_history": [family_history], "work_interfere": [work_interfere], "no_employees": [no_employees], "remote_work": [remote_work], "tech_company": [tech_company], "benefits": [benefits], "care_options": [care_options], "wellness_program": [wellness_program], "seek_help": [seek_help], "anonymity": [anonymity], "leave": [leave], "mental_health_consequence": [mental_health_consequence], "phys_health_consequence": [phys_health_consequence], "coworkers": [coworkers], "supervisor": [supervisor], "mental_health_interview": [mental_health_interview], "phys_health_interview": [phys_health_interview], "mental_vs_physical": [mental_vs_physical], "obs_consequence": [obs_consequence] }) # Preprocess the new data new_data_transformed = preprocessor.transform(new_data) # Make a prediction prediction = model.predict(new_data_transformed)[0] if prediction == 1: result ='Yes' else: result ='No' return result # Create the interface iface = gr.Interface( fn=predict, inputs=inputs, outputs="text" ) # Launch the interface iface.launch()