Team Ai
Apppublic

chfida/adaptive-auth-engine

sourceHugging Faceupdated 10mo agoView on Hugging Face
0likes
streamlit_app.py84 linesDownload Raw Back to src
1# app.py2import streamlit as st3import requests4import os5st.set_page_config(6    page_title="AI-Driven Adaptive Authentication Policy Engine (ForgeRock AM)",7    layout="wide",8)9 10# --- Header ---11st.title("๐Ÿ” AI-Driven Adaptive Authentication Policy Engine (ForgeRock AM)")12st.markdown(13    "Evaluate login risk and get adaptive authentication decisions with confidence scores."14)15st.markdown("---")16 17# --- Input Form ---18with st.form(key="login_context_form"):19    st.subheader("Login Context Inputs")20 21    col1, col2= st.columns(2)22    23    with col1:24        device_known = st.selectbox("Device Known", [0, 1], format_func=lambda x: "No" if x==0 else "Yes")25        impossible_travel = st.selectbox("Impossible Travel", [0, 1], format_func=lambda x: "No" if x==0 else "Yes")26        geo_distance_km = st.number_input("Geo Distance (km)", min_value=0.0, value=10.0, step=1.0)27        failed_attempts_24h = st.number_input("Failed Attempts in 24h", min_value=0, value=0, step=1)28    29    with col2:30        ip_reputation = st.slider("IP Reputation", 0.0, 1.0, 0.5, 0.01)31        hour_of_day = st.slider("Hour of Day", 0, 23, 12)32        role_sensitivity = st.slider("Role Sensitivity", 0.0, 1.0, 0.5, 0.01)33    34    35    submit_button = st.form_submit_button(label="Evaluate ๐Ÿš€")36 37# --- API Call & Result Display ---38API_URL = os.getenv("API_URL")39API_TOKEN = os.getenv("API_TOKEN")40 41if submit_button:42    payload = {43        "ip_reputation": ip_reputation,44        "geo_distance_km": geo_distance_km,45        "device_known": device_known,46        "hour_of_day": hour_of_day,47        "failed_attempts_24h": failed_attempts_24h,48        "role_sensitivity": role_sensitivity,49        "impossible_travel": impossible_travel50    }51 52    headers = {53        "Authorization": f"Bearer {API_TOKEN}",54        "Content-Type": "application/json"55    }56 57    with st.spinner("Evaluating risk..."):58        try:59            response = requests.post(API_URL, json=payload, headers=headers, timeout=10)60            response.raise_for_status()61            data = response.json()62 63            # --- Display Results ---64            st.markdown("---")65            st.subheader("โœ… Evaluation Result")66 67            # Color coding for decision68            decision = data.get("decision", "UNKNOWN")69            if decision == "ALLOW":70                decision_color = "green"71            elif decision == "MFA":72                decision_color = "orange"73            elif decision == "DENY":74                decision_color = "red"75            else:76                decision_color = "gray"77 78            st.markdown(f"**Decision:** <span style='color:{decision_color}; font-weight:bold'>{decision}</span>", unsafe_allow_html=True)79            st.markdown(f"**Decision Confidence Score:** {data.get('decision_confidence_score', 0):.2f}%")80            st.markdown(f"**Reason:** {data.get('reasons', '')}")81 82        except requests.exceptions.RequestException as e:83            st.error(f"API request failed: {e}")84