LeonceNsh commited on
Commit
ec8154b
·
verified ·
1 Parent(s): ca2055e

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +77 -58
app.py CHANGED
@@ -43,82 +43,101 @@ def filter_data(fiscal_year, employer, job_title, country_of_birth, country_of_n
43
  # Function to generate insights and visualizations
44
  def generate_visuals(filtered_data):
45
  # Gender Distribution Bar Chart
46
- plt.figure(figsize=(10, 6))
47
- sns.countplot(data=filtered_data, x='gender', order=filtered_data['gender'].value_counts().index)
48
- plt.title("Gender Distribution")
49
- plt.xlabel("Gender")
50
- plt.ylabel("Count")
 
 
51
  gender_chart = gr.Plot(plt.gcf())
52
  plt.close()
53
-
54
- # Pie Chart for Top Employers
55
  employer_counts = filtered_data['employer_name'].value_counts().head(10)
56
- plt.figure(figsize=(10, 6))
57
- employer_counts.plot(kind='pie', autopct='%1.1f%%')
58
- plt.title("Top 10 Employers")
 
59
  employer_chart = gr.Plot(plt.gcf())
60
  plt.close()
61
-
62
- # Bar Chart for Worksite States
63
- plt.figure(figsize=(10, 6))
64
- sns.countplot(data=filtered_data, y='worksite_state', order=filtered_data['worksite_state'].value_counts().index)
65
- plt.title("Worksite States Distribution")
66
- plt.xlabel("Count")
67
- plt.ylabel("Worksite State")
68
- state_chart = gr.Plot(plt.gcf())
 
 
69
  plt.close()
70
-
71
- return gender_chart, employer_chart, state_chart
72
 
73
  # Gradio interface
74
  def gradio_app(fiscal_year, employer, job_title, country_of_birth, country_of_nationality, min_salary, max_salary, worksite_city, worksite_state):
75
  filtered_data = filter_data(fiscal_year, employer, job_title, country_of_birth, country_of_nationality, min_salary, max_salary, worksite_city, worksite_state)
76
- gender_chart, employer_chart, state_chart = generate_visuals(filtered_data)
77
- return filtered_data.head(10), gender_chart, employer_chart, state_chart
78
-
79
- # Dropdown options
80
- fiscal_year_options = ["All"] + sorted(data['fiscal_year'].dropna().astype(int).unique().astype(str))
81
- employer_options = ["All"] + sorted(data['employer_name'].unique())
82
- job_title_options = ["All"] + sorted(data['job_title'].unique())
83
- country_of_birth_options = ["All"] + sorted(data['country_of_birth'].unique())
84
- country_of_nationality_options = ["All"] + sorted(data['country_of_nationality'].unique())
85
- worksite_city_options = ["All"] + sorted(data['worksite_city'].unique())
86
- worksite_state_options = ["All"] + sorted(data['worksite_state'].unique())
87
-
88
- # Build Gradio Interface
 
 
 
 
 
89
  with gr.Blocks() as app:
90
- gr.Markdown("# Workforce Data Explorer")
91
-
92
  with gr.Row():
93
- fiscal_year = gr.Dropdown(label="Fiscal Year", choices=fiscal_year_options)
94
- employer = gr.Dropdown(label="Employer Name", choices=employer_options)
95
 
96
  with gr.Row():
97
- job_title = gr.Dropdown(label="Job Title", choices=job_title_options)
98
- country_of_birth = gr.Dropdown(label="Country of Birth", choices=country_of_birth_options)
99
- country_of_nationality = gr.Dropdown(label="Country of Nationality", choices=country_of_nationality_options)
100
-
 
 
 
 
 
 
 
 
 
101
  with gr.Row():
102
- min_salary = gr.Number(label="Minimum Salary")
103
- max_salary = gr.Number(label="Maximum Salary")
104
-
105
  with gr.Row():
106
- worksite_city = gr.Dropdown(label="Worksite City", choices=worksite_city_options)
107
- worksite_state = gr.Dropdown(label="Worksite State", choices=worksite_state_options)
108
-
109
- apply_filters = gr.Button("Apply Filters")
110
-
111
  with gr.Row():
112
- data_output = gr.Dataframe(label="Filtered Data")
113
- gender_chart = gr.Plot(label="Gender Distribution")
114
- employer_chart = gr.Plot(label="Top Employers")
115
- state_chart = gr.Plot(label="Worksite States")
116
-
 
 
117
  apply_filters.click(
118
- fn=gradio_app,
119
- inputs=[fiscal_year, employer, job_title, country_of_birth, country_of_nationality, min_salary, max_salary, worksite_city, worksite_state],
120
- outputs=[data_output, gender_chart, employer_chart, state_chart],
 
 
 
121
  )
122
 
123
- # Launch the app
124
  app.launch()
 
43
  # Function to generate insights and visualizations
44
  def generate_visuals(filtered_data):
45
  # Gender Distribution Bar Chart
46
+ plt.figure(figsize=(12, 8))
47
+ sns.countplot(data=filtered_data, x='gender', order=filtered_data['gender'].value_counts().index, palette='viridis')
48
+ plt.title("Gender Distribution", fontsize=16)
49
+ plt.xlabel("Gender", fontsize=14)
50
+ plt.ylabel("Count", fontsize=14)
51
+ plt.xticks(fontsize=12)
52
+ plt.yticks(fontsize=12)
53
  gender_chart = gr.Plot(plt.gcf())
54
  plt.close()
55
+
56
+ # Pie chart for top 10 employers
57
  employer_counts = filtered_data['employer_name'].value_counts().head(10)
58
+ plt.figure(figsize=(12, 8))
59
+ employer_counts.plot(kind='pie', autopct='%1.1f%%', colors=sns.color_palette('Set3'))
60
+ plt.title("Top 10 Employers", fontsize=16)
61
+ plt.ylabel("") # Hide the default ylabel
62
  employer_chart = gr.Plot(plt.gcf())
63
  plt.close()
64
+
65
+ # Salary Distribution
66
+ plt.figure(figsize=(12, 8))
67
+ sns.histplot(filtered_data['wage_amt'], kde=True, color="blue", bins=30)
68
+ plt.title("Salary Distribution", fontsize=16)
69
+ plt.xlabel("Salary (wage_amt)", fontsize=14)
70
+ plt.ylabel("Frequency", fontsize=14)
71
+ plt.xticks(fontsize=12)
72
+ plt.yticks(fontsize=12)
73
+ salary_chart = gr.Plot(plt.gcf())
74
  plt.close()
75
+
76
+ return gender_chart, employer_chart, salary_chart
77
 
78
  # Gradio interface
79
  def gradio_app(fiscal_year, employer, job_title, country_of_birth, country_of_nationality, min_salary, max_salary, worksite_city, worksite_state):
80
  filtered_data = filter_data(fiscal_year, employer, job_title, country_of_birth, country_of_nationality, min_salary, max_salary, worksite_city, worksite_state)
81
+ gender_chart, employer_chart, salary_chart = generate_visuals(filtered_data)
82
+ return (
83
+ filtered_data.head(10), # Display first 10 rows of filtered data
84
+ gender_chart,
85
+ employer_chart,
86
+ salary_chart,
87
+ )
88
+
89
+ # Define dropdown options
90
+ fiscal_year_options = ["All"] + sorted(data['fiscal_year'].dropna().unique().astype(str).tolist())
91
+ employer_options = ["All"] + sorted(data['employer_name'].dropna().unique())
92
+ job_title_options = ["All"] + sorted(data['job_title'].dropna().unique())
93
+ country_birth_options = ["All"] + sorted(data['country_of_birth'].dropna().unique())
94
+ country_nationality_options = ["All"] + sorted(data['country_of_nationality'].dropna().unique())
95
+ worksite_city_options = ["All"] + sorted(data['worksite_city'].dropna().unique())
96
+ worksite_state_options = ["All"] + sorted(data['worksite_state'].dropna().unique())
97
+
98
+ # Gradio app interface
99
  with gr.Blocks() as app:
 
 
100
  with gr.Row():
101
+ gr.Markdown("<h1 style='color: #4CAF50;'>Visa Application Insights Dashboard</h1>")
 
102
 
103
  with gr.Row():
104
+ with gr.Column():
105
+ fiscal_year = gr.Dropdown(label="Fiscal Year", choices=fiscal_year_options, value="All")
106
+ employer = gr.Dropdown(label="Employer Name", choices=employer_options, value="All")
107
+ job_title = gr.Dropdown(label="Job Title", choices=job_title_options, value="All")
108
+ country_of_birth = gr.Dropdown(label="Country of Birth", choices=country_birth_options, value="All")
109
+ country_of_nationality = gr.Dropdown(label="Country of Nationality", choices=country_nationality_options, value="All")
110
+ min_salary = gr.Number(label="Minimum Salary (USD)", value=0)
111
+ max_salary = gr.Number(label="Maximum Salary (USD)", value=1000000)
112
+ worksite_city = gr.Dropdown(label="Worksite City", choices=worksite_city_options, value="All")
113
+ worksite_state = gr.Dropdown(label="Worksite State", choices=worksite_state_options, value="All")
114
+
115
+ apply_filters = gr.Button("Apply Filters", elem_id="apply-filters-btn", style={"background-color": "#007BFF", "color": "white", "padding": "10px", "font-size": "16px"})
116
+
117
  with gr.Row():
118
+ gr.Markdown("<h2>Filtered Data</h2>")
119
+ data_table = gr.Dataframe(label="Filtered Data")
120
+
121
  with gr.Row():
122
+ gr.Markdown("<h2>Gender Distribution</h2>")
123
+ gender_chart = gr.Plot()
124
+
 
 
125
  with gr.Row():
126
+ gr.Markdown("<h2>Top 10 Employers</h2>")
127
+ employer_chart = gr.Plot()
128
+
129
+ with gr.Row():
130
+ gr.Markdown("<h2>Salary Distribution</h2>")
131
+ salary_chart = gr.Plot()
132
+
133
  apply_filters.click(
134
+ gradio_app,
135
+ inputs=[
136
+ fiscal_year, employer, job_title, country_of_birth, country_of_nationality,
137
+ min_salary, max_salary, worksite_city, worksite_state
138
+ ],
139
+ outputs=[data_table, gender_chart, employer_chart, salary_chart]
140
  )
141
 
142
+ # Run the app
143
  app.launch()