Spaces:
Sleeping
Sleeping
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,80 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
import pandas as pd
|
3 |
+
import plotly.express as px
|
4 |
+
|
5 |
+
# Load the data
|
6 |
+
def load_data():
|
7 |
+
file_path = 'digital_identity_data.xlsx'
|
8 |
+
return pd.read_excel(file_path)
|
9 |
+
|
10 |
+
data = load_data()
|
11 |
+
|
12 |
+
# Function for filtering data
|
13 |
+
def filter_data(countries, genders, statuses):
|
14 |
+
filtered_data = data[
|
15 |
+
(data["Country"].isin(countries)) &
|
16 |
+
(data["Gender"].isin(genders)) &
|
17 |
+
(data["Account Status"].isin(statuses))
|
18 |
+
]
|
19 |
+
return filtered_data
|
20 |
+
|
21 |
+
# Function to generate visualizations
|
22 |
+
def generate_dashboard(countries, genders, statuses):
|
23 |
+
filtered_data = filter_data(countries, genders, statuses)
|
24 |
+
|
25 |
+
# Logins by country
|
26 |
+
logins_by_country = filtered_data.groupby("Country")["Number of Logins"].sum().reset_index()
|
27 |
+
fig1 = px.bar(logins_by_country, x="Country", y="Number of Logins", title="Logins by Country", color="Country")
|
28 |
+
|
29 |
+
# Session duration by gender
|
30 |
+
session_duration_by_gender = filtered_data.groupby("Gender")["Session Duration (Minutes)"].mean().reset_index()
|
31 |
+
fig2 = px.bar(session_duration_by_gender, x="Gender", y="Session Duration (Minutes)", title="Session Duration by Gender", color="Gender")
|
32 |
+
|
33 |
+
# Data breaches by country
|
34 |
+
fig3 = px.pie(filtered_data, names="Country", values="Data Breaches Reported", title="Data Breaches by Country")
|
35 |
+
|
36 |
+
# 2FA usage
|
37 |
+
two_fa_usage = filtered_data["2FA Enabled"].value_counts().reset_index()
|
38 |
+
two_fa_usage.columns = ["2FA Enabled", "Count"]
|
39 |
+
fig4 = px.pie(two_fa_usage, names="2FA Enabled", values="Count", title="2FA Usage")
|
40 |
+
|
41 |
+
return filtered_data, fig1, fig2, fig3, fig4
|
42 |
+
|
43 |
+
# Gradio Blocks app
|
44 |
+
with gr.Blocks() as demo:
|
45 |
+
gr.Markdown("# Digital Identity Dashboard")
|
46 |
+
|
47 |
+
with gr.Row():
|
48 |
+
countries = gr.CheckboxGroup(choices=data["Country"].unique().tolist(), label="Select Countries", value=data["Country"].unique().tolist())
|
49 |
+
genders = gr.CheckboxGroup(choices=data["Gender"].unique().tolist(), label="Select Genders", value=data["Gender"].unique().tolist())
|
50 |
+
statuses = gr.CheckboxGroup(choices=data["Account Status"].unique().tolist(), label="Select Account Status", value=data["Account Status"].unique().tolist())
|
51 |
+
|
52 |
+
with gr.Row():
|
53 |
+
filtered_data_table = gr.Dataframe(label="Filtered Data")
|
54 |
+
|
55 |
+
with gr.Row():
|
56 |
+
fig1_display = gr.HTML(label="Logins by Country")
|
57 |
+
fig2_display = gr.HTML(label="Session Duration by Gender")
|
58 |
+
|
59 |
+
with gr.Row():
|
60 |
+
fig3_display = gr.HTML(label="Data Breaches by Country")
|
61 |
+
fig4_display = gr.HTML(label="2FA Usage")
|
62 |
+
|
63 |
+
def update_dashboard(countries, genders, statuses):
|
64 |
+
filtered_data, fig1, fig2, fig3, fig4 = generate_dashboard(countries, genders, statuses)
|
65 |
+
return (
|
66 |
+
filtered_data,
|
67 |
+
fig1.to_html(),
|
68 |
+
fig2.to_html(),
|
69 |
+
fig3.to_html(),
|
70 |
+
fig4.to_html()
|
71 |
+
)
|
72 |
+
|
73 |
+
update_button = gr.Button("Update Dashboard")
|
74 |
+
update_button.click(
|
75 |
+
update_dashboard,
|
76 |
+
inputs=[countries, genders, statuses],
|
77 |
+
outputs=[filtered_data_table, fig1_display, fig2_display, fig3_display, fig4_display]
|
78 |
+
)
|
79 |
+
|
80 |
+
demo.launch(debug=True, share=False)
|