anxiousAmazon / app.py
ciro-c's picture
Finished lesson 06
5bcca9c
import gradio as gr
import pandas as pd
import joblib
filename = 'anxiousAmazon.sav'
rf = joblib.load(filename)
forest_name = "ciro-c/emobot"
def calc_preds(df):
pred = rf.predict(df)
if pred == 1:
return 'Has anxiety'
else:
return 'Don\'t have anxiety'
def process_inputs(Gender, Age, Major, Year, CGPA, Marriage, Depression, Panic, Treatment):
df = pd.DataFrame(columns=['Marriage', 'Major', 'Depression', 'Panic', 'Treatment', 'Gender', 'CGPA', 'Year', 'Age']);
df.loc[0] = [Marriage, Major, Depression, Panic, Treatment,Gender, CGPA, Year, Age];
df['Marriage'] = df['Marriage'].map({'Yes': 1, 'No': 0})
df['Depression'] = df['Depression'].map({'Yes': 1, 'No': 0})
df['Anxiety'] = df['Anxiety'].map({'Yes': 1, 'No': 0})
df['Panic'] = df['Panic'].map({'Yes': 1, 'No': 0})
df['Treatment'] = df['Treatment'].map({'Yes': 1, 'No': 0})
df['Gender'] = df['Gender'].map({'Female': 0, 'Male': 1})
df['CGPA'] = df['CGPA'].map({'3.00 - 3.49':3,'3.50 - 4.00':4,'2.50 - 2.99':2,'2.00 - 2.49':1,'0 - 1.99':0})
df['Major'] = df['Major'].map({
'ENGINEERING':16,
'ISLAMIC EDUCATION':23,
'ACCOUNTING ':0,
'BCS':3,
'BIT':7,
'LAWS':30,
'MATHEMATHICS':33,
'PENDIDIKAN ISLAM':36,
'HUMAN RESOURCES':20,
'IRKHS':22,
'PSYCHOLOGY':38,
'KENMS':25,
'ENM':17,
'MARINE SCIENCE':32,
'KOE':27,
'BANKING STUDIES':2,
'BUSINESS ADMINISTRATION':8,
'LAW':29,
'KIRKHS':26,
'USULUDDIN ':41,
'TAASL':40,
'ENGINE':15,
'ALA':1,
'BIOMEDICAL SCIENCE':5,
'BENL':4,
'IT':24,
'CTS':10,
'ENGIN':14,
'ECONS':13,
'MHSC':34,
'MALCOM':31,
'KOP':28,
'HUMAN SCIENCES ':21,
'BIOTECHNOLOGY':6,
'COMMUNICATION ':9,
'DIPLOMA NURSING':11,
'PENDIDIKAN ISLAM ':37,
'RADIOGRAPHY':39,
'FIQH FATWA ':19,
'DIPLOMA TESL':12,
'FIQH':18,
'NURSING ':35
})
return calc_preds(df)
gender_input = gr.Radio(choices=["Female", "Male"], label="Gender")
age_input = gr.Number(label="Age")
major_input = gr.Radio(choices=['ENGINEERING', 'ISLAMIC EDUCATION', 'BIT', 'LAWS', 'MATHEMATHICS', 'PENDIDIKAN ISLAM', 'BCS', 'HUMAN RESOURCES', 'IRKHS', 'PSYCHOLOGY', 'KENMS', 'ACCOUNTING ', 'ENM', 'MARINE SCIENCE', 'KOE', 'BANKING STUDIES', 'BUSINESS ADMINISTRATION', 'LAW', 'KIRKHS', 'USULUDDIN ', 'TAASL', 'ENGINE', 'ALA', 'BIOMEDICAL SCIENCE', 'BENL', 'IT', 'CTS', 'ENGIN', 'ECONS', 'MHSC', 'MALCOM', 'KOP', 'HUMAN SCIENCES ', 'BIOTECHNOLOGY', 'COMMUNICATION ', 'DIPLOMA NURSING', 'PENDIDIKAN ISLAM ', 'RADIOGRAPHY', 'FIQH FATWA ', 'DIPLOMA TESL', 'FIQH', 'NURSING '], label="Major")
year_input = gr.Radio(choices=['YEAR 1', 'YEAR 2', 'YEAR 3', 'YEAR 4'], label="Year")
cgpa_input = gr.Radio(choices=['3.00 - 3.49', '3.50 - 4.00', '2.50 - 2.99', '2.00 - 2.49', '0 - 1.99'], label="CGPA")
marriage_input = gr.Radio(choices=["Yes", "No"], label="Marriage")
depression_input = gr.Radio(choices=["Yes", "No"], label="Depression")
panic_input = gr.Radio(choices=["Yes", "No"], label="Panic")
treatment_input = gr.Radio(choices=["Yes", "No"], label="Treatment")
interface = gr.Interface(
fn=process_inputs,
inputs=[gender_input, age_input, major_input, year_input, cgpa_input, marriage_input, depression_input, panic_input, treatment_input],
outputs="text"
)
interface.launch()