From 306f8c4865e363db9753f98f154dc9531e55584d Mon Sep 17 00:00:00 2001 From: Tekopp Date: Tue, 28 Nov 2023 11:36:16 +0100 Subject: [PATCH 1/4] feat: creating Pyvis network graph --- ...Pyvis_Create_a_network_visualization.ipynb | 239 ++++++++---------- 1 file changed, 101 insertions(+), 138 deletions(-) diff --git a/Pyvis/Pyvis_Create_a_network_visualization.ipynb b/Pyvis/Pyvis_Create_a_network_visualization.ipynb index d5fc61bc02..be02a7dce4 100644 --- a/Pyvis/Pyvis_Create_a_network_visualization.ipynb +++ b/Pyvis/Pyvis_Create_a_network_visualization.ipynb @@ -49,7 +49,7 @@ "tags": [] }, "source": [ - "**Author:** [Jeremy Ravenel](https://www.linkedin.com/in/jeremyravenel/)" + "**Author:** [Jaime Dols Duxans](https://www.linkedin.com/in/duxans/)" ] }, { @@ -60,7 +60,7 @@ "tags": [] }, "source": [ - "**Last update:** 2023-04-12 (Created: 2022-07-27)" + "**Last update:** 2023-11-25 (Created: 2022-07-27)" ] }, { @@ -71,7 +71,7 @@ "tags": [] }, "source": [ - "**Description:** With this notebook, you can create a network graph to visualize the relations between different elements." + "**Description:** With this notebook you can visualize all the awesome-notebooks templates as a graph network." ] }, { @@ -109,18 +109,16 @@ }, { "cell_type": "code", - "execution_count": 1, + "execution_count": null, "id": "6b708479-188a-41ca-9180-46b6328b6621", "metadata": { - "jupyter": { - "source_hidden": true - }, "papermill": {}, "tags": [] }, "outputs": [], "source": [ - "pip install pyvis" + "#%pip install --upgrade pip\n", + "%pip install pyvis" ] }, { @@ -136,19 +134,17 @@ }, { "cell_type": "code", - "execution_count": 2, + "execution_count": null, "id": "potential-surfing", "metadata": { - "jupyter": { - "source_hidden": true - }, "papermill": {}, "tags": [] }, "outputs": [], "source": [ "import naas\n", - "from pyvis.network import Network" + "from pyvis.network import Network\n", + "import pandas as pd" ] }, { @@ -159,12 +155,12 @@ "tags": [] }, "source": [ - "### Setup the global variables for the network" + "### Setup the global variables" ] }, { "cell_type": "code", - "execution_count": 3, + "execution_count": null, "id": "continuous-melbourne", "metadata": { "papermill": {}, @@ -172,189 +168,151 @@ }, "outputs": [], "source": [ + "# 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", - "net = Network(\n", - " notebook=True, height=\"750px\", width=\"100%\", bgcolor=\"#222222\", font_color=\"white\"\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'" ] }, { "cell_type": "markdown", - "id": "25015cf0-4ee4-418a-8371-a163d179d9e8", + "id": "5e33617b-66be-4d01-bf9b-239c54e1700f", "metadata": { - "papermill": {}, + "execution": { + "iopub.execute_input": "2023-11-27T21:52:46.664462Z", + "iopub.status.busy": "2023-11-27T21:52:46.664234Z", + "iopub.status.idle": "2023-11-27T21:52:46.667548Z", + "shell.execute_reply": "2023-11-27T21:52:46.666892Z", + "shell.execute_reply.started": "2023-11-27T21:52:46.664439Z" + }, "tags": [] }, "source": [ - "### Create master nodes with images and specific properties" + "### Read data from a JSON or CSV file" ] }, { "cell_type": "code", - "execution_count": 4, - "id": "c11aae54-33b4-4f21-889a-988ddf28a079", + "execution_count": null, + "id": "b4890390-d5ac-4706-b172-e2bb9ed327fe", "metadata": { - "papermill": {}, "tags": [] }, "outputs": [], "source": [ - "# Create master nodes with images and specific properties\n", - "net.add_node(\n", - " 3,\n", - " shape=\"image\",\n", - " image=\"https://upload.wikimedia.org/wikipedia/commons/thumb/c/ca/LinkedIn_logo_initials.png/768px-LinkedIn_logo_initials.png\",\n", - ")\n", - "net.add_node(\n", - " 4,\n", - " shape=\"image\",\n", - " image=\"https://www.stemmarine.it/wp-content/uploads/2018/08/youtube-logo.png\",\n", - " color=\"#FF0000\",\n", - ")\n", - "net.add_node(\n", - " 5,\n", - " shape=\"image\",\n", - " image=\"https://pnggrid.com/wp-content/uploads/2021/07/Twitter-Logo-Square.png\",\n", - " color=\"#1DA1F2\",\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.\")" ] }, { "cell_type": "markdown", - "id": "50809dc0-e80e-4c71-8be5-fbbdf620c3b8", + "id": "25015cf0-4ee4-418a-8371-a163d179d9e8", "metadata": { "papermill": {}, "tags": [] }, "source": [ - "### Create other simple nodes" + "### Model" ] }, { "cell_type": "code", - "execution_count": 5, - "id": "ede1c7f7-cd29-49e2-be8a-db9484848959", + "execution_count": null, + "id": "c11aae54-33b4-4f21-889a-988ddf28a079", "metadata": { "papermill": {}, "tags": [] }, "outputs": [], "source": [ - "net.add_nodes(\n", - " [1, 2, 6, 7, 8, 9, 10, 11, 12, 13, 14],\n", - " label=[\n", - " \"Setup\",\n", - " \"Common\",\n", - " \"Get post\",\n", - " \"Get followers\",\n", - " \"Get views\",\n", - " \"Get post\",\n", - " \"Get followers\",\n", - " \"Get views\",\n", - " \"Get post\",\n", - " \"Get followers\",\n", - " \"Get views\",\n", - " ],\n", - " color=[\n", - " \"#26cc67\",\n", - " \"black\",\n", - " \"#0072b1\",\n", - " \"#0072b1\",\n", - " \"#0072b1\",\n", - " \"#1DA1F2\",\n", - " \"#1DA1F2\",\n", - " \"#1DA1F2\",\n", - " \"#FF0000\",\n", - " \"#FF0000\",\n", - " \"#FF0000\",\n", - " ],\n", - ")" - ] - }, - { - "cell_type": "markdown", - "id": "registered-showcase", - "metadata": { - "papermill": {}, - "tags": [] - }, - "source": [ - "## Model" + "# 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", + "\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", + " 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", + " else:\n", + " net.add_node(tool, title=tool, image=tool_img[tool], shape='image',size=60,level=1, physics=False)\n", + "\n", + "# Add notebook nodes\n", + "for notebook in 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'])" ] }, { "cell_type": "markdown", - "id": "tested-astrology", + "id": "50809dc0-e80e-4c71-8be5-fbbdf620c3b8", "metadata": { "papermill": {}, "tags": [] }, "source": [ - "### Create simple edge" + "### Output" ] }, { "cell_type": "code", - "execution_count": 6, - "id": "crude-louisville", + "execution_count": null, + "id": "ede1c7f7-cd29-49e2-be8a-db9484848959", "metadata": { "papermill": {}, "tags": [] }, "outputs": [], "source": [ - "net.add_edge(1, 5)" + "level_1_count = 0\n", + "level_2_count = 0\n", + "for node in net.nodes:\n", + " if node['level'] == 1:\n", + " level_1_count += 1\n", + " else:\n", + " level_2_count += 1\n", + "\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" ] }, { "cell_type": "markdown", - "id": "f7dbb2e1-d578-4be9-b9e5-16872a4d472d", - "metadata": { - "papermill": {}, - "tags": [] - }, - "source": [ - "### Create multiple edges" - ] - }, - { - "cell_type": "code", - "execution_count": 7, - "id": "9cca845f-3a67-4e5f-9721-903970bee206", + "id": "registered-showcase", "metadata": { "papermill": {}, "tags": [] }, - "outputs": [], "source": [ - "net.add_edges(\n", - " [\n", - " (1, 2),\n", - " (1, 3),\n", - " (1, 4),\n", - " (3, 2),\n", - " (4, 2),\n", - " (5, 2),\n", - " (3, 6),\n", - " (3, 7),\n", - " (3, 8),\n", - " (6, 2),\n", - " (7, 2),\n", - " (8, 2),\n", - " (5, 9),\n", - " (5, 10),\n", - " (5, 11),\n", - " (9, 2),\n", - " (10, 2),\n", - " (11, 2),\n", - " (4, 12),\n", - " (4, 13),\n", - " (4, 14),\n", - " (14, 2),\n", - " (13, 2),\n", - " (12, 2),\n", - " ]\n", - ")" + "## Model" ] }, { @@ -388,7 +346,7 @@ }, { "cell_type": "code", - "execution_count": 8, + "execution_count": null, "id": "9c4e3b7b-6440-4844-8054-265f1aec65eb", "metadata": { "papermill": {}, @@ -396,6 +354,9 @@ }, "outputs": [], "source": [ + "# Saving the network to a HTML file in your workdir (optional)\n", + "#net.write_html(f\"{network_name}.html\")\n", + "\n", "network = net.show(f\"{network_name}.html\")\n", "network" ] @@ -413,10 +374,9 @@ }, { "cell_type": "code", - "execution_count": 9, - "id": "db205965-a2dc-4541-ba8e-db3250d1cff0", + "execution_count": null, + "id": "39bcdd24-a9f7-4522-acc8-cbe22dfad9d8", "metadata": { - "papermill": {}, "tags": [] }, "outputs": [], @@ -456,6 +416,9 @@ "parameters": {}, "version": "2.3.3" }, + "toc-autonumbering": false, + "toc-showmarkdowntxt": false, + "toc-showtags": false, "widgets": { "application/vnd.jupyter.widget-state+json": { "state": {}, @@ -466,4 +429,4 @@ }, "nbformat": 4, "nbformat_minor": 5 -} \ No newline at end of file +} From 3b0a01076e4075449a6a588bdded20048e2f7a0c Mon Sep 17 00:00:00 2001 From: Florent Ravenel Date: Fri, 1 Dec 2023 11:43:20 +0100 Subject: [PATCH 2/4] feat: update template init on pyvis --- ...Pyvis_Create_a_network_visualization.ipynb | 258 ++++++++++-------- 1 file changed, 150 insertions(+), 108 deletions(-) diff --git a/Pyvis/Pyvis_Create_a_network_visualization.ipynb b/Pyvis/Pyvis_Create_a_network_visualization.ipynb index be02a7dce4..405fe1adfb 100644 --- a/Pyvis/Pyvis_Create_a_network_visualization.ipynb +++ b/Pyvis/Pyvis_Create_a_network_visualization.ipynb @@ -38,7 +38,7 @@ "tags": [] }, "source": [ - "**Tags:** #python #naas #scheduler #network #snippet #analytics" + "**Tags:** #python #naas #asset #network #analytics" ] }, { @@ -49,7 +49,7 @@ "tags": [] }, "source": [ - "**Author:** [Jaime Dols Duxans](https://www.linkedin.com/in/duxans/)" + "**Author:** [Jeremy Ravenel](https://www.linkedin.com/in/jeremyravenel/)" ] }, { @@ -60,7 +60,7 @@ "tags": [] }, "source": [ - "**Last update:** 2023-11-25 (Created: 2022-07-27)" + "**Last update:** 2023-12-01 (Created: 2022-07-27)" ] }, { @@ -71,7 +71,7 @@ "tags": [] }, "source": [ - "**Description:** With this notebook you can visualize all the awesome-notebooks templates as a graph network." + "**Description:** With this notebook, you can create a network graph to visualize the relations between different elements." ] }, { @@ -82,7 +82,8 @@ "tags": [] }, "source": [ - "**References:** https://pyvis.readthedocs.io/en/latest/tutorial.html" + "**References:** \n", + "- [Pyvis documentation](https://pyvis.readthedocs.io/en/latest/tutorial.html)" ] }, { @@ -98,221 +99,267 @@ }, { "cell_type": "markdown", - "id": "87f5d344-ecdd-4054-8696-34ed7f96548c", + "id": "numeric-mediterranean", "metadata": { "papermill": {}, "tags": [] }, "source": [ - "### Import packages" + "### Import libraries" ] }, { "cell_type": "code", "execution_count": null, - "id": "6b708479-188a-41ca-9180-46b6328b6621", + "id": "potential-surfing", "metadata": { "papermill": {}, "tags": [] }, "outputs": [], "source": [ - "#%pip install --upgrade pip\n", - "%pip install pyvis" + "import naas\n", + "try:\n", + " from pyvis.network import Network\n", + "except:\n", + " !pip install pyvis --upgrade\n", + " from pyvis.network import Network" ] }, { "cell_type": "markdown", - "id": "numeric-mediterranean", + "id": "aggressive-trustee", "metadata": { "papermill": {}, "tags": [] }, "source": [ - "### Import library" + "### Setup variables\n", + "- `network_name`: Network name\n", + "- `height`: Network height\n", + "- `width`: Network width\n", + "- `bgcolor`: Network background color\n", + "- `font_color`: Network font color" ] }, { "cell_type": "code", "execution_count": null, - "id": "potential-surfing", + "id": "continuous-melbourne", "metadata": { "papermill": {}, "tags": [] }, "outputs": [], "source": [ - "import naas\n", - "from pyvis.network import Network\n", - "import pandas as pd" + "network_name = \"pyvis_example\"\n", + "height = \"750px\"\n", + "width = \"100%\"\n", + "bgcolor = \"#222222\"\n", + "font_color = \"white\"" ] }, { "cell_type": "markdown", - "id": "aggressive-trustee", + "id": "registered-showcase", "metadata": { "papermill": {}, "tags": [] }, "source": [ - "### Setup the global variables" + "## Model" + ] + }, + { + "cell_type": "markdown", + "id": "ed90822e-8456-47c8-937a-7d207d96993d", + "metadata": {}, + "source": [ + "### Initializing the Pyvis network" ] }, { "cell_type": "code", "execution_count": null, - "id": "continuous-melbourne", - "metadata": { - "papermill": {}, - "tags": [] - }, + "id": "14656059-6704-41fb-b8c4-315881efca42", + "metadata": {}, "outputs": [], "source": [ - "# 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'" + "net = Network(\n", + " notebook=True,\n", + " height=height,\n", + " width=width,\n", + " bgcolor=bgcolor,\n", + " font_color=font_color\n", + ")" ] }, { "cell_type": "markdown", - "id": "5e33617b-66be-4d01-bf9b-239c54e1700f", + "id": "25015cf0-4ee4-418a-8371-a163d179d9e8", "metadata": { - "execution": { - "iopub.execute_input": "2023-11-27T21:52:46.664462Z", - "iopub.status.busy": "2023-11-27T21:52:46.664234Z", - "iopub.status.idle": "2023-11-27T21:52:46.667548Z", - "shell.execute_reply": "2023-11-27T21:52:46.666892Z", - "shell.execute_reply.started": "2023-11-27T21:52:46.664439Z" - }, + "papermill": {}, "tags": [] }, "source": [ - "### Read data from a JSON or CSV file" + "### Create master nodes with images and specific properties" ] }, { "cell_type": "code", "execution_count": null, - "id": "b4890390-d5ac-4706-b172-e2bb9ed327fe", + "id": "c11aae54-33b4-4f21-889a-988ddf28a079", "metadata": { + "papermill": {}, "tags": [] }, "outputs": [], "source": [ - "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.\")" + "# Create master nodes with images and specific properties\n", + "net.add_node(\n", + " 3,\n", + " shape=\"image\",\n", + " image=\"https://upload.wikimedia.org/wikipedia/commons/thumb/c/ca/LinkedIn_logo_initials.png/768px-LinkedIn_logo_initials.png\",\n", + ")\n", + "net.add_node(\n", + " 4,\n", + " shape=\"image\",\n", + " image=\"https://www.stemmarine.it/wp-content/uploads/2018/08/youtube-logo.png\",\n", + " color=\"#FF0000\",\n", + ")\n", + "net.add_node(\n", + " 5,\n", + " shape=\"image\",\n", + " image=\"https://pnggrid.com/wp-content/uploads/2021/07/Twitter-Logo-Square.png\",\n", + " color=\"#1DA1F2\",\n", + ")" ] }, { "cell_type": "markdown", - "id": "25015cf0-4ee4-418a-8371-a163d179d9e8", + "id": "50809dc0-e80e-4c71-8be5-fbbdf620c3b8", "metadata": { "papermill": {}, "tags": [] }, "source": [ - "### Model" + "### Create other simple nodes" ] }, { "cell_type": "code", "execution_count": null, - "id": "c11aae54-33b4-4f21-889a-988ddf28a079", + "id": "ede1c7f7-cd29-49e2-be8a-db9484848959", "metadata": { "papermill": {}, "tags": [] }, "outputs": [], "source": [ - "# 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", - "\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", - " 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", - " else:\n", - " net.add_node(tool, title=tool, image=tool_img[tool], shape='image',size=60,level=1, physics=False)\n", - "\n", - "# Add notebook nodes\n", - "for notebook in 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_nodes(\n", + " [1, 2, 6, 7, 8, 9, 10, 11, 12, 13, 14],\n", + " label=[\n", + " \"Setup\",\n", + " \"Common\",\n", + " \"Get post\",\n", + " \"Get followers\",\n", + " \"Get views\",\n", + " \"Get post\",\n", + " \"Get followers\",\n", + " \"Get views\",\n", + " \"Get post\",\n", + " \"Get followers\",\n", + " \"Get views\",\n", + " ],\n", + " color=[\n", + " \"#26cc67\",\n", + " \"black\",\n", + " \"#0072b1\",\n", + " \"#0072b1\",\n", + " \"#0072b1\",\n", + " \"#1DA1F2\",\n", + " \"#1DA1F2\",\n", + " \"#1DA1F2\",\n", + " \"#FF0000\",\n", + " \"#FF0000\",\n", + " \"#FF0000\",\n", + " ],\n", + ")" ] }, { "cell_type": "markdown", - "id": "50809dc0-e80e-4c71-8be5-fbbdf620c3b8", + "id": "tested-astrology", "metadata": { "papermill": {}, "tags": [] }, "source": [ - "### Output" + "### Create simple edge" ] }, { "cell_type": "code", "execution_count": null, - "id": "ede1c7f7-cd29-49e2-be8a-db9484848959", + "id": "crude-louisville", "metadata": { "papermill": {}, "tags": [] }, "outputs": [], "source": [ - "level_1_count = 0\n", - "level_2_count = 0\n", - "for node in net.nodes:\n", - " if node['level'] == 1:\n", - " level_1_count += 1\n", - " else:\n", - " level_2_count += 1\n", - "\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" + "net.add_edge(1, 5)" ] }, { "cell_type": "markdown", - "id": "registered-showcase", + "id": "f7dbb2e1-d578-4be9-b9e5-16872a4d472d", "metadata": { "papermill": {}, "tags": [] }, "source": [ - "## Model" + "### Create multiple edges" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "9cca845f-3a67-4e5f-9721-903970bee206", + "metadata": { + "papermill": {}, + "tags": [] + }, + "outputs": [], + "source": [ + "net.add_edges(\n", + " [\n", + " (1, 2),\n", + " (1, 3),\n", + " (1, 4),\n", + " (3, 2),\n", + " (4, 2),\n", + " (5, 2),\n", + " (3, 6),\n", + " (3, 7),\n", + " (3, 8),\n", + " (6, 2),\n", + " (7, 2),\n", + " (8, 2),\n", + " (5, 9),\n", + " (5, 10),\n", + " (5, 11),\n", + " (9, 2),\n", + " (10, 2),\n", + " (11, 2),\n", + " (4, 12),\n", + " (4, 13),\n", + " (4, 14),\n", + " (14, 2),\n", + " (13, 2),\n", + " (12, 2),\n", + " ]\n", + ")" ] }, { @@ -354,9 +401,6 @@ }, "outputs": [], "source": [ - "# Saving the network to a HTML file in your workdir (optional)\n", - "#net.write_html(f\"{network_name}.html\")\n", - "\n", "network = net.show(f\"{network_name}.html\")\n", "network" ] @@ -375,8 +419,9 @@ { "cell_type": "code", "execution_count": null, - "id": "39bcdd24-a9f7-4522-acc8-cbe22dfad9d8", + "id": "db205965-a2dc-4541-ba8e-db3250d1cff0", "metadata": { + "papermill": {}, "tags": [] }, "outputs": [], @@ -416,9 +461,6 @@ "parameters": {}, "version": "2.3.3" }, - "toc-autonumbering": false, - "toc-showmarkdowntxt": false, - "toc-showtags": false, "widgets": { "application/vnd.jupyter.widget-state+json": { "state": {}, From 2414b1ce5452d127440442a0de7436c74ffec65c Mon Sep 17 00:00:00 2001 From: Florent Ravenel Date: Fri, 1 Dec 2023 11:43:55 +0100 Subject: [PATCH 3/4] feat: connect source to github + rework strucutre --- ..._Visualize_awesome_notebooks_network.ipynb | 407 ++++++++++++++++++ 1 file changed, 407 insertions(+) create mode 100644 Pyvis/Pyvis_Visualize_awesome_notebooks_network.ipynb diff --git a/Pyvis/Pyvis_Visualize_awesome_notebooks_network.ipynb b/Pyvis/Pyvis_Visualize_awesome_notebooks_network.ipynb new file mode 100644 index 0000000000..fe249c844b --- /dev/null +++ b/Pyvis/Pyvis_Visualize_awesome_notebooks_network.ipynb @@ -0,0 +1,407 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "id": "latin-packing", + "metadata": { + "execution": { + "iopub.execute_input": "2021-02-23T14:22:16.610471Z", + "iopub.status.busy": "2021-02-23T14:22:16.610129Z", + "iopub.status.idle": "2021-02-23T14:22:16.627784Z", + "shell.execute_reply": "2021-02-23T14:22:16.626866Z", + "shell.execute_reply.started": "2021-02-23T14:22:16.610384Z" + }, + "papermill": {}, + "tags": [] + }, + "source": [ + "\"Pyvis.png\"" + ] + }, + { + "cell_type": "markdown", + "id": "compressed-wilson", + "metadata": { + "papermill": {}, + "tags": [] + }, + "source": [ + "# Pyvis - Visualize awesome notebooks graph network\n", + "

Give Feedback | Bug report" + ] + }, + { + "cell_type": "markdown", + "id": "religious-programmer", + "metadata": { + "papermill": {}, + "tags": [] + }, + "source": [ + "**Tags:** #python #naas #scheduler #network #snippet #analytics" + ] + }, + { + "cell_type": "markdown", + "id": "1fe9f56e-561c-4f52-aef8-b861c9462107", + "metadata": { + "papermill": {}, + "tags": [] + }, + "source": [ + "**Author:** [Jaime Dols Duxans](https://www.linkedin.com/in/duxans/)" + ] + }, + { + "cell_type": "markdown", + "id": "9f4457c5-1377-4167-8528-fdb7449f2d2d", + "metadata": { + "papermill": {}, + "tags": [] + }, + "source": [ + "**Last update:** 2023-12-01 (Created: 2023-11-30)" + ] + }, + { + "cell_type": "markdown", + "id": "31ea7cdb-e10d-43fc-b026-f69249a59736", + "metadata": { + "papermill": {}, + "tags": [] + }, + "source": [ + "**Description:** With this notebook you can visualize all the awesome-notebooks templates as a graph network." + ] + }, + { + "cell_type": "markdown", + "id": "162268ac-ed10-4f32-af82-ab5bd5b2bb9e", + "metadata": { + "papermill": {}, + "tags": [] + }, + "source": [ + "**References:** \n", + "- [Pyvis documentation](https://pyvis.readthedocs.io/en/latest/tutorial.html)" + ] + }, + { + "cell_type": "markdown", + "id": "distinguished-truth", + "metadata": { + "papermill": {}, + "tags": [] + }, + "source": [ + "## Input" + ] + }, + { + "cell_type": "markdown", + "id": "numeric-mediterranean", + "metadata": { + "papermill": {}, + "tags": [] + }, + "source": [ + "### Import libraries" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "potential-surfing", + "metadata": { + "papermill": {}, + "tags": [] + }, + "outputs": [], + "source": [ + "import naas\n", + "try:\n", + " from pyvis.network import Network\n", + "except:\n", + " !pip install pyvis --upgrade\n", + " from pyvis.network import Network\n", + "import pandas as pd\n", + "import requests" + ] + }, + { + "cell_type": "markdown", + "id": "09c7ee40-504b-4661-a7c6-013eee0e71af", + "metadata": { + "papermill": {}, + "tags": [] + }, + "source": [ + "### Setup variables\n", + "- `github_url`: Stores the URL to a JSON file hosted on GitHub.\n", + "- `solver`: The gravity model used in the visualization (choose and test your favourite)\n", + "- `network_name`: Network name\n", + "- `height`: Network height\n", + "- `width`: Network width\n", + "- `bgcolor`: Network background color\n", + "- `font_color`: Network font color" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "e346d915-94dc-45a8-b9c2-6929dd4d998d", + "metadata": { + "papermill": {}, + "tags": [] + }, + "outputs": [], + "source": [ + "github_url = \"https://raw.githubusercontent.com/jupyter-naas/awesome-notebooks/master/templates.json\"\n", + "solver = 'force_atlas_2based'\n", + "network_name = \"pyvis_awesome-notebooks\"\n", + "height = \"1400px\"\n", + "width = \"100%\"\n", + "bgcolor = \"#222222\"\n", + "font_color = \"white\"" + ] + }, + { + "cell_type": "markdown", + "id": "25015cf0-4ee4-418a-8371-a163d179d9e8", + "metadata": { + "papermill": {}, + "tags": [] + }, + "source": [ + "### Model" + ] + }, + { + "cell_type": "markdown", + "id": "d5697de1-307e-4beb-b99c-fc4af92d7fc8", + "metadata": {}, + "source": [ + "### Get templates from JSON" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "f46c9e67-d9c5-4d5c-9e8a-e4beaaa895fb", + "metadata": { + "tags": [] + }, + "outputs": [], + "source": [ + "def get_templates(url):\n", + " res = requests.get(url)\n", + " df = pd.DataFrame(res.json())\n", + " return df\n", + "\n", + "df_temp = get_templates(github_url)\n", + "print(\"Templates:\", len(df_temp))\n", + "df_temp.head(1)" + ] + }, + { + "cell_type": "markdown", + "id": "f5556230-702d-41df-a3b9-921a1e1cd766", + "metadata": {}, + "source": [ + "### Initializing the Pyvis network" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "2d22f8ce-f051-410c-ba35-cff5509a2aa2", + "metadata": { + "tags": [] + }, + "outputs": [], + "source": [ + "net = Network(\n", + " notebook=True,\n", + " height=height,\n", + " width=width,\n", + " bgcolor=bgcolor,\n", + " font_color=font_color\n", + ")" + ] + }, + { + "cell_type": "markdown", + "id": "527710df-4fa5-44de-aa20-ddcdd5846a1e", + "metadata": {}, + "source": [ + "### Create Pyvis network" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "c11aae54-33b4-4f21-889a-988ddf28a079", + "metadata": { + "papermill": {}, + "tags": [] + }, + "outputs": [], + "source": [ + "# 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", + "\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", + " 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", + " else:\n", + " net.add_node(tool, title=tool, image=tool_img[tool], shape='image',size=60,level=1, physics=False)\n", + "\n", + "# Add notebook nodes\n", + "for notebook in 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'])\n", + " \n", + "level_1_count = 0\n", + "level_2_count = 0\n", + "for node in net.nodes:\n", + " if node['level'] == 1:\n", + " level_1_count += 1\n", + " else:\n", + " level_2_count += 1\n", + "\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\")" + ] + }, + { + "cell_type": "markdown", + "id": "lonely-pacific", + "metadata": { + "execution": { + "iopub.execute_input": "2021-07-02T23:32:10.789097Z", + "iopub.status.busy": "2021-07-02T23:32:10.788829Z", + "iopub.status.idle": "2021-07-02T23:32:10.796900Z", + "shell.execute_reply": "2021-07-02T23:32:10.796358Z", + "shell.execute_reply.started": "2021-07-02T23:32:10.789033Z" + }, + "papermill": {}, + "tags": [] + }, + "source": [ + "## Output" + ] + }, + { + "cell_type": "markdown", + "id": "890f7c86-b7bb-4f5d-9a1b-e492dd9580fd", + "metadata": { + "papermill": {}, + "tags": [] + }, + "source": [ + "### Show results" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "9c4e3b7b-6440-4844-8054-265f1aec65eb", + "metadata": { + "papermill": {}, + "tags": [] + }, + "outputs": [], + "source": [ + "# Saving the network to a HTML file in your workdir (optional)\n", + "#net.write_html(f\"{network_name}.html\")\n", + "\n", + "network = net.show(f\"{network_name}.html\")\n", + "network" + ] + }, + { + "cell_type": "markdown", + "id": "a28950bb-1d7d-4835-a83a-faac837ebc7c", + "metadata": { + "papermill": {}, + "tags": [] + }, + "source": [ + "### Share your output" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "39bcdd24-a9f7-4522-acc8-cbe22dfad9d8", + "metadata": { + "tags": [] + }, + "outputs": [], + "source": [ + "naas.asset.add(f\"{network_name}.html\", {\"inline\": True})\n", + "\n", + "# -> Uncomment the line below to remove your asset\n", + "# naas.asset.delete()" + ] + } + ], + "metadata": { + "kernelspec": { + "display_name": "Python 3", + "language": "python", + "name": "python3" + }, + "language_info": { + "codemirror_mode": { + "name": "ipython", + "version": 3 + }, + "file_extension": ".py", + "mimetype": "text/x-python", + "name": "python", + "nbconvert_exporter": "python", + "pygments_lexer": "ipython3", + "version": "3.9.6" + }, + "naas": { + "notebook_id": "2df55afca82f21837a817a57c842dcf4460d0908883b76b3c64576ef8f09f864", + "notebook_path": "Pyvis/Pyvis_Create_a_network_visualization.ipynb" + }, + "papermill": { + "default_parameters": {}, + "environment_variables": {}, + "parameters": {}, + "version": "2.3.3" + }, + "toc-autonumbering": false, + "toc-showmarkdowntxt": false, + "toc-showtags": false, + "widgets": { + "application/vnd.jupyter.widget-state+json": { + "state": {}, + "version_major": 2, + "version_minor": 0 + } + } + }, + "nbformat": 4, + "nbformat_minor": 5 +} From cd85aa3da7fc2a09d03d6e4e5021d8595c7c5e89 Mon Sep 17 00:00:00 2001 From: Florent Ravenel Date: Fri, 1 Dec 2023 11:49:08 +0100 Subject: [PATCH 4/4] fix: add "model" as heading 2 --- Pyvis/Pyvis_Visualize_awesome_notebooks_network.ipynb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Pyvis/Pyvis_Visualize_awesome_notebooks_network.ipynb b/Pyvis/Pyvis_Visualize_awesome_notebooks_network.ipynb index fe249c844b..815feb59e7 100644 --- a/Pyvis/Pyvis_Visualize_awesome_notebooks_network.ipynb +++ b/Pyvis/Pyvis_Visualize_awesome_notebooks_network.ipynb @@ -173,7 +173,7 @@ "tags": [] }, "source": [ - "### Model" + "## Model" ] }, {