import gradio as gr import pandas as pd import joblib # Load the saved model model = joblib.load('amazon_access_model.joblib') # Load minimal data just for dropdowns train_df = pd.read_csv('train.csv.zip') def predict_access(resource, mgr_id, role_title): # Common values for other fields input_data = pd.DataFrame([[ resource, mgr_id, train_df['ROLE_ROLLUP_1'].mode()[0], train_df['ROLE_ROLLUP_2'].mode()[0], train_df['ROLE_DEPTNAME'].mode()[0], role_title, train_df['ROLE_FAMILY_DESC'].mode()[0], train_df['ROLE_FAMILY'].mode()[0], train_df['ROLE_CODE'].mode()[0] ]], columns=train_df.columns[1:]) # Exclude ACTION column prediction = model.predict(input_data)[0] confidence = model.predict_proba(input_data)[0][prediction] result = "✅ Access Granted" if prediction == 1 else "❌ Access Denied" return f"{result} (Confidence: {confidence:.2%})" # Simple interface iface = gr.Interface( fn=predict_access, inputs=[ gr.Dropdown(choices=sorted(train_df['RESOURCE'].unique().tolist())[:100], label="Resource"), gr.Dropdown(choices=sorted(train_df['MGR_ID'].unique().tolist())[:100], label="Manager"), gr.Dropdown(choices=sorted(train_df['ROLE_TITLE'].unique().tolist()), label="Role Title") ], outputs=gr.Text(label="Access Decision"), title="Amazon Access Control", theme="soft" ) iface.launch()