Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -32,31 +32,43 @@ for _, row in data.iterrows():
|
|
32 |
investor_company_mapping[investor].append(company)
|
33 |
|
34 |
# Gradio app function
|
35 |
-
def generate_graph(selected_investors):
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
-
|
|
|
|
|
|
|
|
|
|
|
40 |
|
41 |
-
#
|
42 |
-
|
43 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
44 |
for company in companies:
|
45 |
G.add_edge(investor, company)
|
46 |
|
47 |
# Node sizes based on valuation
|
48 |
node_sizes = []
|
49 |
for node in G.nodes:
|
50 |
-
if node in
|
51 |
node_sizes.append(2000)
|
52 |
else: # Company size based on valuation
|
53 |
-
valuation =
|
54 |
node_sizes.append(valuation[0] * 100 if len(valuation) > 0 else 100)
|
55 |
|
56 |
# Node colors
|
57 |
node_colors = []
|
58 |
for node in G.nodes:
|
59 |
-
if node in
|
60 |
node_colors.append("#FF5733") # Distinct color for investors
|
61 |
else:
|
62 |
node_colors.append("#33FF57") # Distinct color for companies
|
@@ -90,20 +102,34 @@ def generate_graph(selected_investors):
|
|
90 |
# Gradio Interface
|
91 |
def main():
|
92 |
investor_list = sorted(investor_company_mapping.keys())
|
|
|
|
|
93 |
|
94 |
iface = gr.Interface(
|
95 |
fn=generate_graph,
|
96 |
-
inputs=
|
97 |
-
|
98 |
-
|
99 |
-
|
100 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
101 |
outputs=gr.Image(type="pil", label="Venture Network Graph"),
|
102 |
title="Venture Networks Visualization",
|
103 |
description=(
|
104 |
-
"Select investors
|
105 |
-
"The graph shows connections between
|
106 |
-
"Node sizes represent company valuations."
|
107 |
),
|
108 |
flagging_mode="never"
|
109 |
)
|
|
|
32 |
investor_company_mapping[investor].append(company)
|
33 |
|
34 |
# Gradio app function
|
35 |
+
def generate_graph(selected_investors, selected_country, selected_industry):
|
36 |
+
filtered_data = data
|
37 |
+
|
38 |
+
# Apply country filter
|
39 |
+
if selected_country != "All":
|
40 |
+
filtered_data = filtered_data[filtered_data["Country"] == selected_country]
|
41 |
+
|
42 |
+
# Apply industry filter
|
43 |
+
if selected_industry != "All":
|
44 |
+
filtered_data = filtered_data[filtered_data["Industry"] == selected_industry]
|
45 |
|
46 |
+
# Filter the investor-to-company mapping
|
47 |
+
filtered_mapping = {}
|
48 |
+
for investor, companies in investor_company_mapping.items():
|
49 |
+
filtered_companies = [c for c in companies if c in filtered_data["Company"].values]
|
50 |
+
if filtered_companies:
|
51 |
+
filtered_mapping[investor] = filtered_companies
|
52 |
+
|
53 |
+
# Use the filtered mapping to build the graph
|
54 |
+
G = nx.Graph()
|
55 |
+
for investor, companies in filtered_mapping.items():
|
56 |
for company in companies:
|
57 |
G.add_edge(investor, company)
|
58 |
|
59 |
# Node sizes based on valuation
|
60 |
node_sizes = []
|
61 |
for node in G.nodes:
|
62 |
+
if node in filtered_mapping: # Fixed size for investors
|
63 |
node_sizes.append(2000)
|
64 |
else: # Company size based on valuation
|
65 |
+
valuation = filtered_data.loc[filtered_data["Company"] == node, "Valuation_Billions"].values
|
66 |
node_sizes.append(valuation[0] * 100 if len(valuation) > 0 else 100)
|
67 |
|
68 |
# Node colors
|
69 |
node_colors = []
|
70 |
for node in G.nodes:
|
71 |
+
if node in filtered_mapping:
|
72 |
node_colors.append("#FF5733") # Distinct color for investors
|
73 |
else:
|
74 |
node_colors.append("#33FF57") # Distinct color for companies
|
|
|
102 |
# Gradio Interface
|
103 |
def main():
|
104 |
investor_list = sorted(investor_company_mapping.keys())
|
105 |
+
country_list = ["All"] + sorted(data["Country"].dropna().unique())
|
106 |
+
industry_list = ["All"] + sorted(data["Industry"].dropna().unique())
|
107 |
|
108 |
iface = gr.Interface(
|
109 |
fn=generate_graph,
|
110 |
+
inputs=[
|
111 |
+
gr.CheckboxGroup(
|
112 |
+
choices=investor_list,
|
113 |
+
label="Select Investors",
|
114 |
+
value=investor_list # Default to all selected
|
115 |
+
),
|
116 |
+
gr.Dropdown(
|
117 |
+
choices=country_list,
|
118 |
+
label="Filter by Country",
|
119 |
+
value="All" # Default to no filter
|
120 |
+
),
|
121 |
+
gr.Dropdown(
|
122 |
+
choices=industry_list,
|
123 |
+
label="Filter by Industry",
|
124 |
+
value="All" # Default to no filter
|
125 |
+
)
|
126 |
+
],
|
127 |
outputs=gr.Image(type="pil", label="Venture Network Graph"),
|
128 |
title="Venture Networks Visualization",
|
129 |
description=(
|
130 |
+
"Select investors and apply optional filters by country and industry "
|
131 |
+
"to visualize their investments. The graph shows connections between "
|
132 |
+
"investors and the companies they've invested in. Node sizes represent company valuations."
|
133 |
),
|
134 |
flagging_mode="never"
|
135 |
)
|