File size: 1,461 Bytes
35277f6
 
 
 
1845b66
 
35277f6
1845b66
51c22a4
35277f6
 
1845b66
35277f6
 
 
1845b66
 
 
35277f6
1845b66
 
 
 
35277f6
 
 
 
 
 
 
1845b66
35277f6
 
 
1845b66
 
 
35277f6
 
 
1845b66
35277f6
 
1845b66
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
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()