Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -31,24 +31,40 @@ for _, row in data.iterrows():
|
|
31 |
investor_company_mapping[investor] = []
|
32 |
investor_company_mapping[investor].append(company)
|
33 |
|
34 |
-
# Gradio app
|
35 |
-
def
|
36 |
filtered_data = data
|
37 |
|
38 |
-
# Apply
|
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 |
-
|
50 |
-
|
51 |
-
|
|
|
52 |
|
53 |
# Use the filtered mapping to build the graph
|
54 |
G = nx.Graph()
|
@@ -99,42 +115,52 @@ def generate_graph(selected_investors, selected_country, selected_industry):
|
|
99 |
image = Image.open(buf)
|
100 |
return image
|
101 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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 |
-
|
109 |
-
|
110 |
-
|
111 |
-
gr.
|
112 |
-
|
113 |
-
|
114 |
-
|
115 |
-
|
116 |
-
|
117 |
-
|
118 |
-
|
119 |
-
|
120 |
-
|
121 |
-
|
122 |
-
|
123 |
-
|
124 |
-
|
125 |
-
|
126 |
-
|
127 |
-
|
128 |
-
|
129 |
-
|
130 |
-
|
131 |
-
|
132 |
-
|
133 |
-
|
134 |
-
|
135 |
-
|
136 |
-
|
137 |
-
|
|
|
|
|
138 |
|
139 |
if __name__ == "__main__":
|
140 |
main()
|
|
|
31 |
investor_company_mapping[investor] = []
|
32 |
investor_company_mapping[investor].append(company)
|
33 |
|
34 |
+
# Gradio app functions
|
35 |
+
def filter_investors_by_country_and_industry(selected_country, selected_industry):
|
36 |
filtered_data = data
|
37 |
|
38 |
+
# Apply filters
|
39 |
if selected_country != "All":
|
40 |
filtered_data = filtered_data[filtered_data["Country"] == selected_country]
|
|
|
|
|
41 |
if selected_industry != "All":
|
42 |
filtered_data = filtered_data[filtered_data["Industry"] == selected_industry]
|
43 |
|
44 |
+
# Calculate total valuation per investor
|
45 |
+
investor_valuations = {}
|
46 |
+
for investor, companies in investor_company_mapping.items():
|
47 |
+
total_valuation = 0
|
48 |
+
for company in companies:
|
49 |
+
if company in filtered_data["Company"].values:
|
50 |
+
valuation = filtered_data.loc[filtered_data["Company"] == company, "Valuation_Billions"].values
|
51 |
+
total_valuation += valuation[0] if len(valuation) > 0 else 0
|
52 |
+
if total_valuation >= 20: # Filter by total valuation
|
53 |
+
investor_valuations[investor] = total_valuation
|
54 |
+
|
55 |
+
return list(investor_valuations.keys()), filtered_data
|
56 |
+
|
57 |
+
def generate_graph(selected_investors, filtered_data):
|
58 |
+
if not selected_investors:
|
59 |
+
return None
|
60 |
+
|
61 |
# Filter the investor-to-company mapping
|
62 |
filtered_mapping = {}
|
63 |
for investor, companies in investor_company_mapping.items():
|
64 |
+
if investor in selected_investors:
|
65 |
+
filtered_companies = [c for c in companies if c in filtered_data["Company"].values]
|
66 |
+
if filtered_companies:
|
67 |
+
filtered_mapping[investor] = filtered_companies
|
68 |
|
69 |
# Use the filtered mapping to build the graph
|
70 |
G = nx.Graph()
|
|
|
115 |
image = Image.open(buf)
|
116 |
return image
|
117 |
|
118 |
+
def app(selected_country, selected_industry):
|
119 |
+
investor_list, filtered_data = filter_investors_by_country_and_industry(selected_country, selected_industry)
|
120 |
+
|
121 |
+
return gr.update(
|
122 |
+
choices=investor_list,
|
123 |
+
value=investor_list,
|
124 |
+
visible=True
|
125 |
+
), filtered_data
|
126 |
+
|
127 |
# Gradio Interface
|
128 |
def main():
|
|
|
129 |
country_list = ["All"] + sorted(data["Country"].dropna().unique())
|
130 |
industry_list = ["All"] + sorted(data["Industry"].dropna().unique())
|
131 |
|
132 |
+
with gr.Blocks() as demo:
|
133 |
+
with gr.Row():
|
134 |
+
country_filter = gr.Dropdown(choices=country_list, label="Filter by Country", value="All")
|
135 |
+
industry_filter = gr.Dropdown(choices=industry_list, label="Filter by Industry", value="All")
|
136 |
+
|
137 |
+
filtered_investor_list = gr.CheckboxGroup(
|
138 |
+
choices=[],
|
139 |
+
label="Select Investors",
|
140 |
+
visible=False
|
141 |
+
)
|
142 |
+
graph_output = gr.Image(type="pil", label="Venture Network Graph")
|
143 |
+
|
144 |
+
filtered_data_holder = gr.State()
|
145 |
+
|
146 |
+
country_filter.change(
|
147 |
+
app,
|
148 |
+
inputs=[country_filter, industry_filter],
|
149 |
+
outputs=[filtered_investor_list, filtered_data_holder]
|
150 |
+
)
|
151 |
+
industry_filter.change(
|
152 |
+
app,
|
153 |
+
inputs=[country_filter, industry_filter],
|
154 |
+
outputs=[filtered_investor_list, filtered_data_holder]
|
155 |
+
)
|
156 |
+
|
157 |
+
filtered_investor_list.change(
|
158 |
+
generate_graph,
|
159 |
+
inputs=[filtered_investor_list, filtered_data_holder],
|
160 |
+
outputs=graph_output
|
161 |
+
)
|
162 |
+
|
163 |
+
demo.launch()
|
164 |
|
165 |
if __name__ == "__main__":
|
166 |
main()
|