Spaces:
Sleeping
Sleeping
| 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.Plot(label="Logins by Country") | |
| fig2_display = gr.Plot(label="Session Duration by Gender") | |
| with gr.Row(): | |
| fig3_display = gr.Plot(label="Data Breaches by Country") | |
| fig4_display = gr.Plot(label="2FA Usage") | |
| def update_dashboard(countries, genders, statuses): | |
| filtered_data, fig1, fig2, fig3, fig4 = generate_dashboard(countries, genders, statuses) | |
| return ( | |
| filtered_data, | |
| fig1, | |
| fig2, | |
| fig3, | |
| fig4 | |
| ) | |
| 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) |