Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: #2443 circular logos added #2458

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -144,3 +144,5 @@ YahooFinance/STOCK_CLUSTERS.csv

# template outputs
YahooFinance/STOCK_CLUSTERS.png
Pyvis/templates.json
Pyvis/pyvis_example.html
112 changes: 71 additions & 41 deletions Pyvis/Pyvis_Create_a_network_visualization.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -109,16 +109,19 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 1,
"id": "6b708479-188a-41ca-9180-46b6328b6621",
"metadata": {
"papermill": {},
"tags": []
},
"outputs": [],
"source": [
"# Uncomment the following lines to install the required packages\n",
"\n",
"#%pip install --upgrade pip\n",
"%pip install pyvis"
"#%pip install pyvis\n",
"#%pip install naas"
]
},
{
Expand All @@ -134,15 +137,15 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 1,
"id": "potential-surfing",
"metadata": {
"papermill": {},
"tags": []
},
"outputs": [],
"source": [
"import naas\n",
"#import naas # comment this line if you are outside of naas environment\n",
"from pyvis.network import Network\n",
"import pandas as pd"
]
Expand All @@ -158,9 +161,14 @@
"### Setup the global variables"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": []
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 2,
"id": "continuous-melbourne",
"metadata": {
"papermill": {},
Expand All @@ -171,17 +179,8 @@
"# Data file in the same working directory in .json or .csv format.\n",
"file = \"templates.json\"\n",
"\n",
"# The gravity model used in the visualization (choose and test your favourite)\n",
"solver = 'force_atlas_2based'\n",
"\n",
"# Name output file\n",
"network_name = \"pyvis_example\"\n",
"\n",
"# Initializing the Pyvis network\n",
"net=Network(height='1400px', width='100%', bgcolor='#222222', font_color='white')\n",
"\n",
"# Pick your favourite physics model\n",
"solver ='force_atlas_2based'"
"network_name = \"pyvis_example\""
]
},
{
Expand All @@ -203,19 +202,22 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 3,
"id": "b4890390-d5ac-4706-b172-e2bb9ed327fe",
"metadata": {
"tags": []
},
"outputs": [],
"source": [
"# Sanity check for your datafile is recommended here before proceeding.\n",
"\n",
"if file.endswith('.json'):\n",
" df_temp = pd.read_json(file)\n",
"elif file.endswith('.csv'):\n",
" df_temp = pd.read_csv(file)\n",
"else:\n",
" print(f\"File {file} is not a JSON or CSV file.\")"
" print(f\"File {file} is not a JSON or CSV file.\")\n",
"\n"
]
},
{
Expand All @@ -231,42 +233,47 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 4,
"id": "c11aae54-33b4-4f21-889a-988ddf28a079",
"metadata": {
"papermill": {},
"tags": []
},
"outputs": [],
"source": [
"# Initializing Pyvis network\n",
"net = Network(height='1400px', width='100%', bgcolor='#222222', font_color='white')\n",
"\n",
"# Physics solver. Choose one from Pyvis documentation \n",
"net.force_atlas_2based()\n",
"\n",
"# Pull data\n",
"tools = list(df_temp['tool'])\n",
"images = list(df_temp['image_url'])\n",
"notebooks = list(df_temp['notebook'])\n",
"tools = df_temp['tool'].tolist()\n",
"images = df_temp['image_url'].tolist()\n",
"notebooks = df_temp['notebook'].tolist()\n",
"\n",
"# Create a dictionary of tools and images\n",
"tool_img = dict(zip(tools, images))\n",
"\n",
"# Add tool nodes\n",
"for tool in tools:\n",
"for tool in set(tools):\n",
" if tool == 'Naas':\n",
" net.add_node(tool, title=tool, image=tool_img[tool], shape='image', mass=30, size=150, level=1, fixed=True, x=0, y=0,physics=False)\n",
" if tool == 'OpenAI':\n",
" #this large node was bouncing around very fast, so I fixed it\n",
" net.add_node(tool, title=tool, image=tool_img[tool], shape='image', size=60, level=1, fixed=True, x=-1000, y=2000, physics=False)\n",
" # We set Naas as the center node\n",
" net.add_node(tool, title=tool, image=tool_img[tool], shape='circularImage', mass=30, size=150, level=1, fixed=True, x=0, y=0, physics=False)\n",
" elif tool == 'OpenAI':\n",
" # OpenAI is a large node bouncing around very fast, so we let it be fixed\n",
" net.add_node(tool, title=tool, image=tool_img[tool], shape='circularImage', size=60, level=1, fixed=True, x=-1000, y=2000, physics=False)\n",
" else:\n",
" net.add_node(tool, title=tool, image=tool_img[tool], shape='image',size=60,level=1, physics=False)\n",
" # All other tool nodes are of the same size and freely moving\n",
" net.add_node(tool, title=tool, image=tool_img[tool], shape='circularImage',size=60,level=1)\n",
"\n",
"# Add notebook nodes\n",
"for notebook in notebooks:\n",
" net.add_node(notebook, title=notebook, size=30,level=2,color='#4d94db')\n",
"for notebook in set(notebooks):\n",
" net.add_node(notebook, title=notebook, size=30, level=2, color='#4d94db')\n",
"\n",
"# Add edges\n",
"for _, node_e in df_temp.iterrows():\n",
" net.add_edge(node_e['tool'], node_e['notebook'], title=node_e['action'])"
" net.add_edge(node_e['tool'], node_e['notebook'], title=node_e['notebook_url'])"
]
},
{
Expand All @@ -282,13 +289,24 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 5,
"id": "ede1c7f7-cd29-49e2-be8a-db9484848959",
"metadata": {
"papermill": {},
"tags": []
},
"outputs": [],
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Number of tool nodes: 175\n",
"Number of notebook nodes: 1228\n",
"Total number of nodes: 1403\n",
"Total number of edges: 1272\n"
]
}
],
"source": [
"level_1_count = 0\n",
"level_2_count = 0\n",
Expand All @@ -300,8 +318,8 @@
"\n",
"print(\"Number of tool nodes: \", level_1_count)\n",
"print(\"Number of notebook nodes: \", level_2_count)\n",
"print(\"Total number of nodes: \", len(net.nodes) , \"\\n\")\n",
"print(\"Total number of edges: \", len(net.edges), \"\\n\")\n"
"print(\"Total number of nodes: \", len(net.nodes))\n",
"print(\"Total number of edges: \", len(net.edges))\n"
]
},
{
Expand Down Expand Up @@ -346,7 +364,7 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 6,
"id": "9c4e3b7b-6440-4844-8054-265f1aec65eb",
"metadata": {
"papermill": {},
Expand All @@ -355,10 +373,10 @@
"outputs": [],
"source": [
"# Saving the network to a HTML file in your workdir (optional)\n",
"#net.write_html(f\"{network_name}.html\")\n",
"net.write_html(f\"{network_name}.html\")\n",
"\n",
"network = net.show(f\"{network_name}.html\")\n",
"network"
"#network = net.show(f\"{network_name}.html\")\n",
"#network"
]
},
{
Expand All @@ -374,12 +392,24 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 8,
"id": "39bcdd24-a9f7-4522-acc8-cbe22dfad9d8",
"metadata": {
"tags": []
},
"outputs": [],
"outputs": [
{
"ename": "NameError",
"evalue": "name 'naas' is not defined",
"output_type": "error",
"traceback": [
"\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
"\u001b[0;31mNameError\u001b[0m Traceback (most recent call last)",
"Cell \u001b[0;32mIn[8], line 1\u001b[0m\n\u001b[0;32m----> 1\u001b[0m \u001b[43mnaas\u001b[49m\u001b[38;5;241m.\u001b[39masset\u001b[38;5;241m.\u001b[39madd(\u001b[38;5;124mf\u001b[39m\u001b[38;5;124m\"\u001b[39m\u001b[38;5;132;01m{\u001b[39;00mnetwork_name\u001b[38;5;132;01m}\u001b[39;00m\u001b[38;5;124m.html\u001b[39m\u001b[38;5;124m\"\u001b[39m, {\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124minline\u001b[39m\u001b[38;5;124m\"\u001b[39m: \u001b[38;5;28;01mTrue\u001b[39;00m})\n\u001b[1;32m 3\u001b[0m \u001b[38;5;66;03m# -> Uncomment the line below to remove your asset\u001b[39;00m\n\u001b[1;32m 4\u001b[0m \u001b[38;5;66;03m# naas.asset.delete()\u001b[39;00m\n",
"\u001b[0;31mNameError\u001b[0m: name 'naas' is not defined"
]
}
],
"source": [
"naas.asset.add(f\"{network_name}.html\", {\"inline\": True})\n",
"\n",
Expand All @@ -404,7 +434,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.9.6"
"version": "3.12.0"
},
"naas": {
"notebook_id": "2df55afca82f21837a817a57c842dcf4460d0908883b76b3c64576ef8f09f864",
Expand Down