File size: 3,128 Bytes
8406c99
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
import gradio as gr
import pandas as pd
import plotly.express as px

# Load the data
def load_data():
    file_path = 'digital_identity_data.xlsx'
    return pd.read_excel(file_path)

data = load_data()

# Function for filtering data
def filter_data(countries, genders, statuses):
    filtered_data = data[
        (data["Country"].isin(countries)) &
        (data["Gender"].isin(genders)) &
        (data["Account Status"].isin(statuses))
    ]
    return filtered_data

# Function to generate visualizations
def generate_dashboard(countries, genders, statuses):
    filtered_data = filter_data(countries, genders, statuses)

    # Logins by country
    logins_by_country = filtered_data.groupby("Country")["Number of Logins"].sum().reset_index()
    fig1 = px.bar(logins_by_country, x="Country", y="Number of Logins", title="Logins by Country", color="Country")

    # Session duration by gender
    session_duration_by_gender = filtered_data.groupby("Gender")["Session Duration (Minutes)"].mean().reset_index()
    fig2 = px.bar(session_duration_by_gender, x="Gender", y="Session Duration (Minutes)", title="Session Duration by Gender", color="Gender")

    # Data breaches by country
    fig3 = px.pie(filtered_data, names="Country", values="Data Breaches Reported", title="Data Breaches by Country")

    # 2FA usage
    two_fa_usage = filtered_data["2FA Enabled"].value_counts().reset_index()
    two_fa_usage.columns = ["2FA Enabled", "Count"]
    fig4 = px.pie(two_fa_usage, names="2FA Enabled", values="Count", title="2FA Usage")

    return filtered_data, fig1, fig2, fig3, fig4

# Gradio Blocks app
with gr.Blocks() as demo:
    gr.Markdown("# Digital Identity Dashboard")

    with gr.Row():
        countries = gr.CheckboxGroup(choices=data["Country"].unique().tolist(), label="Select Countries", value=data["Country"].unique().tolist())
        genders = gr.CheckboxGroup(choices=data["Gender"].unique().tolist(), label="Select Genders", value=data["Gender"].unique().tolist())
        statuses = gr.CheckboxGroup(choices=data["Account Status"].unique().tolist(), label="Select Account Status", value=data["Account Status"].unique().tolist())

    with gr.Row():
        filtered_data_table = gr.Dataframe(label="Filtered Data")

    with gr.Row():
        fig1_display = gr.HTML(label="Logins by Country")
        fig2_display = gr.HTML(label="Session Duration by Gender")

    with gr.Row():
        fig3_display = gr.HTML(label="Data Breaches by Country")
        fig4_display = gr.HTML(label="2FA Usage")

    def update_dashboard(countries, genders, statuses):
        filtered_data, fig1, fig2, fig3, fig4 = generate_dashboard(countries, genders, statuses)
        return (
            filtered_data,
            fig1.to_html(),
            fig2.to_html(),
            fig3.to_html(),
            fig4.to_html()
        )

    update_button = gr.Button("Update Dashboard")
    update_button.click(
        update_dashboard,
        inputs=[countries, genders, statuses],
        outputs=[filtered_data_table, fig1_display, fig2_display, fig3_display, fig4_display]
    )

demo.launch(debug=True, share=False)