Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -101,18 +101,18 @@ def filter_investors_by_country_and_industry(selected_country, selected_industry
|
|
101 |
investor_valuations = {}
|
102 |
for investor, companies in investor_company_mapping_filtered.items():
|
103 |
total_valuation = filtered_data[filtered_data["Company"].isin(companies)]["Valuation_Billions"].sum()
|
104 |
-
if total_valuation >=
|
105 |
investor_valuations[investor] = total_valuation
|
106 |
|
107 |
logger.info(f"Filtered investors with total valuation >= 20B: {len(investor_valuations)}")
|
108 |
|
109 |
return list(investor_valuations.keys()), filtered_data
|
110 |
|
111 |
-
# Function to generate the graph
|
112 |
-
def
|
113 |
if not selected_investors:
|
114 |
logger.warning("No investors selected. Returning None for graph.")
|
115 |
-
return None
|
116 |
|
117 |
investor_company_mapping_filtered = build_investor_company_mapping(filtered_data)
|
118 |
filtered_mapping = {inv: investor_company_mapping_filtered[inv] for inv in selected_investors if inv in investor_company_mapping_filtered}
|
@@ -169,21 +169,22 @@ def generate_graph(selected_investors, filtered_data):
|
|
169 |
plt.close()
|
170 |
buf.seek(0)
|
171 |
|
172 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
173 |
|
174 |
-
return Image.open(buf)
|
175 |
|
176 |
# Gradio app function
|
177 |
-
def app(selected_country, selected_industry):
|
178 |
investor_list, filtered_data = filter_investors_by_country_and_industry(selected_country, selected_industry)
|
179 |
-
|
180 |
-
|
181 |
-
# Use gr.update() to create an update dictionary for the CheckboxGroup
|
182 |
-
return gr.update(
|
183 |
-
choices=investor_list,
|
184 |
-
value=investor_list,
|
185 |
-
visible=True
|
186 |
-
), filtered_data
|
187 |
|
188 |
# Gradio Interface
|
189 |
def main():
|
@@ -195,30 +196,33 @@ def main():
|
|
195 |
|
196 |
with gr.Blocks() as demo:
|
197 |
with gr.Row():
|
198 |
-
|
199 |
-
country_filter = gr.Dropdown(choices=country_list, label="Filter by Country", value="United States")
|
200 |
industry_filter = gr.Dropdown(choices=industry_list, label="Filter by Industry", value="Enterprise Tech")
|
201 |
|
202 |
-
filtered_investor_list = gr.CheckboxGroup(choices=[], label="Select Investors"
|
|
|
203 |
graph_output = gr.Image(type="pil", label="Venture Network Graph")
|
204 |
-
|
205 |
-
filtered_data_holder = gr.State()
|
206 |
|
207 |
country_filter.change(
|
208 |
app,
|
209 |
-
inputs=[country_filter, industry_filter],
|
210 |
-
outputs=[
|
211 |
)
|
212 |
industry_filter.change(
|
213 |
app,
|
214 |
-
inputs=[country_filter, industry_filter],
|
215 |
-
outputs=[
|
216 |
)
|
217 |
-
|
218 |
filtered_investor_list.change(
|
219 |
-
|
220 |
-
inputs=[filtered_investor_list,
|
221 |
-
outputs=graph_output
|
|
|
|
|
|
|
|
|
|
|
222 |
)
|
223 |
|
224 |
demo.launch()
|
|
|
101 |
investor_valuations = {}
|
102 |
for investor, companies in investor_company_mapping_filtered.items():
|
103 |
total_valuation = filtered_data[filtered_data["Company"].isin(companies)]["Valuation_Billions"].sum()
|
104 |
+
if total_valuation >= 20: # Investors with >= 20B total valuation
|
105 |
investor_valuations[investor] = total_valuation
|
106 |
|
107 |
logger.info(f"Filtered investors with total valuation >= 20B: {len(investor_valuations)}")
|
108 |
|
109 |
return list(investor_valuations.keys()), filtered_data
|
110 |
|
111 |
+
# Function to generate the graph and return node information
|
112 |
+
def generate_graph_and_get_node_info(selected_investors, filtered_data, clicked_node=None):
|
113 |
if not selected_investors:
|
114 |
logger.warning("No investors selected. Returning None for graph.")
|
115 |
+
return None, "No investors selected."
|
116 |
|
117 |
investor_company_mapping_filtered = build_investor_company_mapping(filtered_data)
|
118 |
filtered_mapping = {inv: investor_company_mapping_filtered[inv] for inv in selected_investors if inv in investor_company_mapping_filtered}
|
|
|
169 |
plt.close()
|
170 |
buf.seek(0)
|
171 |
|
172 |
+
# Get node information if clicked
|
173 |
+
node_info = "No node clicked."
|
174 |
+
if clicked_node:
|
175 |
+
if clicked_node in filtered_data["Company"].values:
|
176 |
+
valuation = filtered_data.loc[filtered_data["Company"] == clicked_node, "Valuation_Billions"].iloc[0]
|
177 |
+
node_info = f"Company: {clicked_node}, Valuation: ${valuation}B"
|
178 |
+
elif clicked_node in filtered_mapping:
|
179 |
+
node_info = f"Investor: {clicked_node}"
|
180 |
|
181 |
+
return Image.open(buf), node_info
|
182 |
|
183 |
# Gradio app function
|
184 |
+
def app(selected_country, selected_industry, selected_investors, clicked_node=None):
|
185 |
investor_list, filtered_data = filter_investors_by_country_and_industry(selected_country, selected_industry)
|
186 |
+
graph_image, node_info = generate_graph_and_get_node_info(selected_investors, filtered_data, clicked_node)
|
187 |
+
return graph_image, node_info, gr.update(choices=investor_list, value=selected_investors)
|
|
|
|
|
|
|
|
|
|
|
|
|
188 |
|
189 |
# Gradio Interface
|
190 |
def main():
|
|
|
196 |
|
197 |
with gr.Blocks() as demo:
|
198 |
with gr.Row():
|
199 |
+
country_filter = gr.Dropdown(choices=country_list, label="Filter by Country", value="US")
|
|
|
200 |
industry_filter = gr.Dropdown(choices=industry_list, label="Filter by Industry", value="Enterprise Tech")
|
201 |
|
202 |
+
filtered_investor_list = gr.CheckboxGroup(choices=[], label="Select Investors")
|
203 |
+
clicked_node_input = gr.Textbox(label="Clicked Node (Enter name to simulate a click)", placeholder="Enter a node name")
|
204 |
graph_output = gr.Image(type="pil", label="Venture Network Graph")
|
205 |
+
node_info_output = gr.Textbox(label="Node Information", interactive=False)
|
|
|
206 |
|
207 |
country_filter.change(
|
208 |
app,
|
209 |
+
inputs=[country_filter, industry_filter, filtered_investor_list, clicked_node_input],
|
210 |
+
outputs=[graph_output, node_info_output, filtered_investor_list]
|
211 |
)
|
212 |
industry_filter.change(
|
213 |
app,
|
214 |
+
inputs=[country_filter, industry_filter, filtered_investor_list, clicked_node_input],
|
215 |
+
outputs=[graph_output, node_info_output, filtered_investor_list]
|
216 |
)
|
|
|
217 |
filtered_investor_list.change(
|
218 |
+
app,
|
219 |
+
inputs=[country_filter, industry_filter, filtered_investor_list, clicked_node_input],
|
220 |
+
outputs=[graph_output, node_info_output, filtered_investor_list]
|
221 |
+
)
|
222 |
+
clicked_node_input.change(
|
223 |
+
app,
|
224 |
+
inputs=[country_filter, industry_filter, filtered_investor_list, clicked_node_input],
|
225 |
+
outputs=[graph_output, node_info_output, filtered_investor_list]
|
226 |
)
|
227 |
|
228 |
demo.launch()
|