LeonceNsh commited on
Commit
6450cb6
·
verified ·
1 Parent(s): b954334

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +36 -15
app.py CHANGED
@@ -70,17 +70,31 @@ investor_company_mapping = build_investor_company_mapping(data)
70
  logger.info("Investor to company mapping created.")
71
 
72
  # Filter investors by country, industry, investor selection, and company selection
73
- def filter_investors(selected_country, selected_industry, selected_investors, selected_company):
 
74
  filtered_data = data.copy()
 
 
75
  if selected_country != "All":
76
  filtered_data = filtered_data[filtered_data["Country"] == selected_country]
77
  if selected_industry != "All":
78
  filtered_data = filtered_data[filtered_data["Industry"] == selected_industry]
 
 
79
  if selected_investors:
80
  pattern = '|'.join([re.escape(inv) for inv in selected_investors])
81
  filtered_data = filtered_data[filtered_data["Select_Investors"].str.contains(pattern, na=False)]
82
- if selected_company != "All":
83
- filtered_data = filtered_data[filtered_data["Company"] == selected_company]
 
 
 
 
 
 
 
 
 
84
 
85
  investor_company_mapping_filtered = build_investor_company_mapping(filtered_data)
86
  filtered_investors = list(investor_company_mapping_filtered.keys())
@@ -204,8 +218,10 @@ def generate_graph(investors, filtered_data):
204
  return fig
205
 
206
  # Gradio app
207
- def app(selected_country, selected_industry, selected_company, selected_investors):
208
- investors, filtered_data = filter_investors(selected_country, selected_industry, selected_investors, selected_company)
 
 
209
  if not investors:
210
  return "No investors found with the selected filters.", go.Figure()
211
  graph = generate_graph(investors, filtered_data)
@@ -224,20 +240,25 @@ def main():
224
  industry_filter = gr.Dropdown(choices=industry_list, label="Industry", value="All")
225
  company_filter = gr.Dropdown(choices=company_list, label="Company", value="All")
226
  investor_filter = gr.Dropdown(choices=investor_list, label="Select Investors", value=[], multiselect=True)
 
 
 
 
 
227
  with gr.Row():
228
  investor_output = gr.Textbox(label="Filtered Investors", interactive=False)
229
  graph_output = gr.Plot(label="Network Graph")
230
-
231
- inputs = [country_filter, industry_filter, company_filter, investor_filter]
 
232
  outputs = [investor_output, graph_output]
233
-
234
- country_filter.change(app, inputs, outputs)
235
- industry_filter.change(app, inputs, outputs)
236
- company_filter.change(app, inputs, outputs)
237
- investor_filter.change(app, inputs, outputs)
238
-
239
- gr.Markdown("**Instructions:** Use the dropdowns to filter the network graph.")
240
-
241
  demo.launch()
242
 
243
  if __name__ == "__main__":
 
70
  logger.info("Investor to company mapping created.")
71
 
72
  # Filter investors by country, industry, investor selection, and company selection
73
+ def filter_investors(selected_country, selected_industry, selected_investors, selected_company,
74
+ exclude_countries, exclude_industries, exclude_companies, exclude_investors):
75
  filtered_data = data.copy()
76
+
77
+ # Inclusion filters
78
  if selected_country != "All":
79
  filtered_data = filtered_data[filtered_data["Country"] == selected_country]
80
  if selected_industry != "All":
81
  filtered_data = filtered_data[filtered_data["Industry"] == selected_industry]
82
+ if selected_company != "All":
83
+ filtered_data = filtered_data[filtered_data["Company"] == selected_company]
84
  if selected_investors:
85
  pattern = '|'.join([re.escape(inv) for inv in selected_investors])
86
  filtered_data = filtered_data[filtered_data["Select_Investors"].str.contains(pattern, na=False)]
87
+
88
+ # Exclusion filters
89
+ if exclude_countries:
90
+ filtered_data = filtered_data[~filtered_data["Country"].isin(exclude_countries)]
91
+ if exclude_industries:
92
+ filtered_data = filtered_data[~filtered_data["Industry"].isin(exclude_industries)]
93
+ if exclude_companies:
94
+ filtered_data = filtered_data[~filtered_data["Company"].isin(exclude_companies)]
95
+ if exclude_investors:
96
+ pattern = '|'.join([re.escape(inv) for inv in exclude_investors])
97
+ filtered_data = filtered_data[~filtered_data["Select_Investors"].str.contains(pattern, na=False)]
98
 
99
  investor_company_mapping_filtered = build_investor_company_mapping(filtered_data)
100
  filtered_investors = list(investor_company_mapping_filtered.keys())
 
218
  return fig
219
 
220
  # Gradio app
221
+ def app(selected_country, selected_industry, selected_company, selected_investors,
222
+ exclude_countries, exclude_industries, exclude_companies, exclude_investors):
223
+ investors, filtered_data = filter_investors(selected_country, selected_industry, selected_investors, selected_company,
224
+ exclude_countries, exclude_industries, exclude_companies, exclude_investors)
225
  if not investors:
226
  return "No investors found with the selected filters.", go.Figure()
227
  graph = generate_graph(investors, filtered_data)
 
240
  industry_filter = gr.Dropdown(choices=industry_list, label="Industry", value="All")
241
  company_filter = gr.Dropdown(choices=company_list, label="Company", value="All")
242
  investor_filter = gr.Dropdown(choices=investor_list, label="Select Investors", value=[], multiselect=True)
243
+ with gr.Row():
244
+ exclude_country_filter = gr.Dropdown(choices=country_list[1:], label="Exclude Country", value=[], multiselect=True)
245
+ exclude_industry_filter = gr.Dropdown(choices=industry_list[1:], label="Exclude Industry", value=[], multiselect=True)
246
+ exclude_company_filter = gr.Dropdown(choices=company_list[1:], label="Exclude Company", value=[], multiselect=True)
247
+ exclude_investor_filter = gr.Dropdown(choices=investor_list, label="Exclude Investors", value=[], multiselect=True)
248
  with gr.Row():
249
  investor_output = gr.Textbox(label="Filtered Investors", interactive=False)
250
  graph_output = gr.Plot(label="Network Graph")
251
+
252
+ inputs = [country_filter, industry_filter, company_filter, investor_filter,
253
+ exclude_country_filter, exclude_industry_filter, exclude_company_filter, exclude_investor_filter]
254
  outputs = [investor_output, graph_output]
255
+
256
+ # Set up event triggers for all inputs
257
+ for input_control in inputs:
258
+ input_control.change(app, inputs, outputs)
259
+
260
+ gr.Markdown("**Instructions:** Use the dropdowns to filter the network graph. You can include or exclude specific countries, industries, companies, or investors.")
261
+
 
262
  demo.launch()
263
 
264
  if __name__ == "__main__":