Spaces:
Running
Running
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,140 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# venture_networks_gradio.py
|
2 |
+
|
3 |
+
import networkx as nx
|
4 |
+
import matplotlib.pyplot as plt
|
5 |
+
import gradio as gr
|
6 |
+
from io import BytesIO
|
7 |
+
|
8 |
+
# Define investors and their companies
|
9 |
+
investors = {
|
10 |
+
"Accel": ["Meta", "Dropbox", "Spotify", "Adroll", "PackLink", "Zoom", "Slack"],
|
11 |
+
"Andreessen Horowitz": [
|
12 |
+
"Airbnb", "Lyft", "Pinterest", "Accolade", "Actifio", "Affirm", "Amify",
|
13 |
+
"Apptio", "Arimo", "Asana", "Asserts", "Authy", "Automatic", "Barefoot Networks",
|
14 |
+
"Bebop", "BeReal", "Blockspring", "Boku", "Box", "Bracket Computing", "Bump",
|
15 |
+
"BuzzFeed", "Capital", "Cardiogram", "Caviar", "Citiizen", "CipherCloud",
|
16 |
+
"ClearStory", "Coinbase", "Cumulus", "DeepMap", "Delphix", "DigitalOcean",
|
17 |
+
"Dollar Shave Club", "Earn", "EQRx", "Erasca", "Meta", "FiftyThree", "Flutter",
|
18 |
+
"Fusion-io", "Gainspeed", "Genius", "GitHub", "Gobble", "Golden", "Greenlight",
|
19 |
+
"Granular", "Greplify", "Groupon", "Hatch", "iCracked", "Imgur", "Instacart",
|
20 |
+
"Instagram", "Intrinsic", "Isovalent", "Jopwell", "Julep", "Jungla", "Keybase",
|
21 |
+
"Kno", "Knowable", "Knowmia", "Loom", "Lowkey", "Luma", "Lyrebird", "Lytro",
|
22 |
+
"Massive", "Morta Security", "Nautilus Biotechnology", "Nicira", "Oculus", "Okta",
|
23 |
+
"Onshape", "Opendoor", "OpenInvest", "Optimizely", "Optimyze", "PagerDuty",
|
24 |
+
"Parsec", "Patch Biosciences", "PatientPing", "PicCloud", "Pinterest", "Pixate",
|
25 |
+
"Platfora", "Product Hunt", "Quantopian", "RHL Ventures", "Reddit", "Reflektive",
|
26 |
+
"Rigetti", "Rival", "Robinhood", "Roblox", "Rockmelt", "RTFKT", "Samsara", "Seed",
|
27 |
+
"Shapeways", "ShoeDazzle", "SignalFx", "SigOpt", "Silver Tail Systems", "Skout",
|
28 |
+
"Skype", "Slack", "Socialcam", "Soylent", "Stack Overflow", "Standard Treasury",
|
29 |
+
"Swell", "Swiftype", "Tabular", "Talaria", "Tasty Labs", "Teleport", "Tenfold",
|
30 |
+
"Tidemark", "Tilt", "TinyCo", "Tmunity", "Tomfoolery", "Wise", "TXN", "Urban Engines",
|
31 |
+
"Usermind", "Viki", "Walker and Company", "Wit.ai", "Within", "Zynga", "Altitude Learning",
|
32 |
+
"Bromium", "Factual", "Instart", "Proven", "Rabbit", "UnifyID"
|
33 |
+
],
|
34 |
+
"Google Ventures": ["Uber", "LendingClub"],
|
35 |
+
"Greylock": ["Workday", "Palo Alto Networks"],
|
36 |
+
"Lightspeed Venture Partners": ["Snap", "Grubhub", "AppDynamics"],
|
37 |
+
"Benchmark": ["Snap", "Uber", "WeWork"],
|
38 |
+
"Norwest Venture Partners": ["LendingClub", "Opendoor"],
|
39 |
+
"Emergence Capital Partners": ["Zoom", "Box", "Salesforce"],
|
40 |
+
"Trinity Ventures": ["New Relic", "Care.com", "TubeMogul"],
|
41 |
+
"Citi Ventures": ["Square", "Nutanix"],
|
42 |
+
"Sequoia": [
|
43 |
+
"Alphabet (Google)", "NVIDIA", "Dropbox", "Airbnb", "Affirm",
|
44 |
+
"Airbnb", "Eventbrite", "Meta", "Lyft", "Opendoor", "Palantir", "Reddit", "Uber",
|
45 |
+
"23ANDME", "AMPLITUDE", "APPLE", "ATARI", "AURORA", "BARRACUDA", "BIRD", "BLOCK",
|
46 |
+
"BRIDGEBIO", "CISCO", "CONFLUENT", "DOORDASH", "ELECTRONIC ARTS", "FIREEYE", "GOOGLE",
|
47 |
+
"GREEN DOT", "GUARDANT HEALTH", "HUBSPOT", "INSTACART", "LINKEDIN", "MEDALLIA", "MONGODB",
|
48 |
+
"NATERA", "NETAPP", "NIMBLE STORAGE", "NUBANK", "OKTA", "ORACLE", "PALO ALTO NETWORKS",
|
49 |
+
"PAYPAL", "QUALTRICS", "QUANTENNA", "RINGCENTRAL", "ROBINHOOD", "RUCKUS NETWORKS",
|
50 |
+
"SERVICENOW", "SNOWFLAKE", "SUMO LOGIC", "SUNRUN", "TRULIA", "UIPATH", "UNITY", "YAHOO"
|
51 |
+
],
|
52 |
+
"Y Combinator": ["Dropbox", "Airbnb", "Coinbase", "DoorDash", "Reddit", "Ginkgo Bioworks", "GitLab", "Instacart"]
|
53 |
+
}
|
54 |
+
|
55 |
+
# Define a color map for the investors
|
56 |
+
investor_colors = {
|
57 |
+
"Accel": "blue",
|
58 |
+
"Andreessen Horowitz": "green",
|
59 |
+
"Google Ventures": "red",
|
60 |
+
"Greylock": "purple",
|
61 |
+
"Lightspeed Venture Partners": "orange",
|
62 |
+
"Benchmark": "brown",
|
63 |
+
"Norwest Venture Partners": "pink",
|
64 |
+
"Emergence Capital Partners": "yellow",
|
65 |
+
"Trinity Ventures": "cyan",
|
66 |
+
"Citi Ventures": "magenta",
|
67 |
+
"Sequoia": "lime",
|
68 |
+
"Y Combinator": "black"
|
69 |
+
}
|
70 |
+
|
71 |
+
# Function to generate the graph image
|
72 |
+
def generate_graph(selected_investors):
|
73 |
+
if not selected_investors:
|
74 |
+
selected_investors = list(investors.keys())
|
75 |
+
|
76 |
+
G = nx.Graph()
|
77 |
+
|
78 |
+
# Add edges based on selected investors
|
79 |
+
for investor in selected_investors:
|
80 |
+
companies = investors[investor]
|
81 |
+
for company in companies:
|
82 |
+
G.add_edge(investor, company, color=investor_colors[investor])
|
83 |
+
|
84 |
+
# Get edge colors
|
85 |
+
edge_colors = [G[u][v]['color'] for u, v in G.edges]
|
86 |
+
|
87 |
+
# Set node colors: investors have their specific color, companies have a default color
|
88 |
+
node_colors = []
|
89 |
+
for node in G.nodes:
|
90 |
+
if node in investor_colors:
|
91 |
+
node_colors.append(investor_colors[node])
|
92 |
+
else:
|
93 |
+
node_colors.append("#F0E68C") # Khaki for companies
|
94 |
+
|
95 |
+
# Create plot
|
96 |
+
plt.figure(figsize=(18, 18))
|
97 |
+
pos = nx.spring_layout(G, k=0.2, seed=42) # Fixed seed for consistency
|
98 |
+
nx.draw(
|
99 |
+
G, pos,
|
100 |
+
with_labels=True,
|
101 |
+
node_size=3000,
|
102 |
+
node_color=node_colors,
|
103 |
+
font_size=7,
|
104 |
+
font_weight="bold",
|
105 |
+
edge_color=edge_colors,
|
106 |
+
width=2
|
107 |
+
)
|
108 |
+
plt.title("Venture Funded Companies as a Densely Connected Subgraph", fontsize=20)
|
109 |
+
plt.axis('off')
|
110 |
+
|
111 |
+
# Save plot to a BytesIO object
|
112 |
+
buf = BytesIO()
|
113 |
+
plt.savefig(buf, format="png", bbox_inches="tight")
|
114 |
+
plt.close()
|
115 |
+
buf.seek(0)
|
116 |
+
return buf
|
117 |
+
|
118 |
+
# Define Gradio interface
|
119 |
+
def main():
|
120 |
+
# Create a sorted list of investors for better UX
|
121 |
+
investor_list = sorted(investors.keys())
|
122 |
+
|
123 |
+
iface = gr.Interface(
|
124 |
+
fn=generate_graph,
|
125 |
+
inputs=gr.CheckboxGroup(
|
126 |
+
choices=investor_list,
|
127 |
+
label="Select Investors",
|
128 |
+
value=investor_list # Default to all selected
|
129 |
+
),
|
130 |
+
outputs=gr.Image(type="pil", label="Venture Network Graph"),
|
131 |
+
title="Venture Networks Visualization",
|
132 |
+
description="Select investors to visualize their investments in various companies. The graph shows connections between investors and the companies they've invested in.",
|
133 |
+
layout="vertical",
|
134 |
+
allow_flagging="never"
|
135 |
+
)
|
136 |
+
|
137 |
+
iface.launch()
|
138 |
+
|
139 |
+
if __name__ == "__main__":
|
140 |
+
main()
|