|
2 | 2 | "cells": [ |
3 | 3 | { |
4 | 4 | "cell_type": "code", |
5 | | - "execution_count": 2, |
| 5 | + "execution_count": null, |
6 | 6 | "id": "517be871-a02b-40b2-9ef7-c1d4723df1d0", |
7 | 7 | "metadata": { |
8 | 8 | "tags": [] |
9 | 9 | }, |
| 10 | + "outputs": [], |
| 11 | + "source": [ |
| 12 | + "from IPython.core.display import display, HTML\n", |
| 13 | + "from bs4 import BeautifulSoup as bs\n", |
| 14 | + "import os\n", |
| 15 | + "import re\n", |
| 16 | + "import codecs" |
| 17 | + ] |
| 18 | + }, |
| 19 | + { |
| 20 | + "cell_type": "code", |
| 21 | + "execution_count": 1, |
| 22 | + "id": "517822cc-ea03-4e7f-a726-5d67c126ff10", |
| 23 | + "metadata": { |
| 24 | + "tags": [] |
| 25 | + }, |
10 | 26 | "outputs": [ |
11 | 27 | { |
12 | | - "name": "stderr", |
13 | | - "output_type": "stream", |
14 | | - "text": [ |
15 | | - "/tmp/ipykernel_1621/599365976.py:1: DeprecationWarning: Importing display from IPython.core.display is deprecated since IPython 7.14, please import from IPython display\n", |
16 | | - " from IPython.core.display import display, HTML\n" |
| 28 | + "ename": "SyntaxError", |
| 29 | + "evalue": "unterminated string literal (detected at line 14) (513320101.py, line 14)", |
| 30 | + "output_type": "error", |
| 31 | + "traceback": [ |
| 32 | + "\u001b[0;36m Cell \u001b[0;32mIn[1], line 14\u001b[0;36m\u001b[0m\n\u001b[0;31m template_cluster_map = parsed_template_cluster_map.replace(\"'id', \"id\")\u001b[0m\n\u001b[0m ^\u001b[0m\n\u001b[0;31mSyntaxError\u001b[0m\u001b[0;31m:\u001b[0m unterminated string literal (detected at line 14)\n" |
17 | 33 | ] |
18 | 34 | } |
19 | 35 | ], |
20 | 36 | "source": [ |
21 | | - "from IPython.core.display import display, HTML" |
| 37 | + "class Oracle:\n", |
| 38 | + " def __init__(self, access = 'offline',\n", |
| 39 | + " node_map = '',\n", |
| 40 | + " node_profile = '',\n", |
| 41 | + " node_weights = []):\n", |
| 42 | + " self.access = access,\n", |
| 43 | + " self.node_map = node_map\n", |
| 44 | + " self.node_profile = node_profile\n", |
| 45 | + " self.node_weights = node_weights\n", |
| 46 | + " #print('\\n-> configured oracle')\n", |
| 47 | + " \n", |
| 48 | + " def template_parser(self):\n", |
| 49 | + " parsed_template_cluster_map = str(self.generate_map())\n", |
| 50 | + " template_cluster_map = parsed_template_cluster_map.replace(\"'id'\", \"id\").replace(\"'parent'\", \"parent\").replace(\"'name'\", \"name\").replace(\"'value'\", \"value\")\n", |
| 51 | + " template_script = codecs.open(\"./appTemplate.html\", 'r')\n", |
| 52 | + " oracle_script = codecs.open(\"./oracleReport.html\", 'w')\n", |
| 53 | + " html = template_script.read()\n", |
| 54 | + " parsed_script = html.replace('cluster_map', template_cluster_map)\n", |
| 55 | + " oracle_script.write(parsed_script)\n", |
| 56 | + " \n", |
| 57 | + " #soup = bs(html, 'html.parser')\n", |
| 58 | + " #parsed_script = soup.find_all('script')\n", |
| 59 | + " #parsed_script[1] = parsed_script[1].text.replace('cluster_map', template_cluster_map)\n", |
| 60 | + " #soup.find_all('script').replace_with(parsed_script)\n", |
| 61 | + " #help(soup.find_all('script'))\n", |
| 62 | + " #.replace_with(template_cluster_map)\n", |
| 63 | + " \n", |
| 64 | + " return parsed_script\n", |
| 65 | + " \n", |
| 66 | + " def get_model_type(self, model_id):\n", |
| 67 | + " if model_id == 1:\n", |
| 68 | + " return 'gant'\n", |
| 69 | + " elif model_id == 2:\n", |
| 70 | + " return 'gan' \n", |
| 71 | + " elif model_id == 3:\n", |
| 72 | + " return 'cnnt' \n", |
| 73 | + " elif model_id == 4:\n", |
| 74 | + " return 'cnn'\n", |
| 75 | + " elif model_id == 5:\n", |
| 76 | + " return 'gpt'\n", |
| 77 | + " elif model_id == 6:\n", |
| 78 | + " return 'dalle' \n", |
| 79 | + " elif model_id == 7:\n", |
| 80 | + " return 'malta'\n", |
| 81 | + " else:\n", |
| 82 | + " return 'yolo'\n", |
| 83 | + " \n", |
| 84 | + " def get_model_names(self):\n", |
| 85 | + " models = []\n", |
| 86 | + " for index in range(len(self.node_profile)):\n", |
| 87 | + " node_id = int(self.node_profile[index])\n", |
| 88 | + " models.append(self.get_model_type(node_id))\n", |
| 89 | + " models.append('alpha')\n", |
| 90 | + " return models\n", |
| 91 | + " \n", |
| 92 | + " \n", |
| 93 | + " \n", |
| 94 | + " def generate_map(self):\n", |
| 95 | + " node_cluster_map = []\n", |
| 96 | + " model_names = self.get_model_names()\n", |
| 97 | + " node_weights = self.node_weights\n", |
| 98 | + " \n", |
| 99 | + " for node in range(len(self.node_profile)):\n", |
| 100 | + " weights = node_weights[node]\n", |
| 101 | + " for index in range(len(weights)):\n", |
| 102 | + " model_id = model_names[node]+str(index)\n", |
| 103 | + " weight = int(weights[index])\n", |
| 104 | + " parent = model_names[weight]+str(0)\n", |
| 105 | + " description = model_names[node]\n", |
| 106 | + " \n", |
| 107 | + " node_map = {'id': model_id, \n", |
| 108 | + " 'parent': parent,\n", |
| 109 | + " 'name': description,\n", |
| 110 | + " 'value': 741000000\n", |
| 111 | + " }\n", |
| 112 | + " node_cluster_map.append(node_map)\n", |
| 113 | + " node_map = {'id': 'alpha0', \n", |
| 114 | + " 'parent': '',\n", |
| 115 | + " 'name': 'alpha'}\n", |
| 116 | + " node_cluster_map.append(node_map)\n", |
| 117 | + " \n", |
| 118 | + " return node_cluster_map\n", |
| 119 | + " \n", |
| 120 | + " \n", |
| 121 | + " \n", |
| 122 | + " return self.node_map\n", |
| 123 | + " \n", |
| 124 | + " def set_node(self, node_number, model_path):\n", |
| 125 | + " #set node\n", |
| 126 | + " return none \n", |
| 127 | + " \n", |
| 128 | + " def train(self):\n", |
| 129 | + " #train model\n", |
| 130 | + " return none\n", |
| 131 | + " \n", |
| 132 | + " def optimize(self):\n", |
| 133 | + " #optimize model\n", |
| 134 | + " return none\n", |
| 135 | + " \n", |
| 136 | + " def run(self, oracle_data):\n", |
| 137 | + " #magic\n", |
| 138 | + " return none\n", |
| 139 | + " \n", |
| 140 | + " " |
22 | 141 | ] |
23 | 142 | }, |
24 | 143 | { |
25 | 144 | "cell_type": "code", |
26 | 145 | "execution_count": null, |
27 | | - "id": "517822cc-ea03-4e7f-a726-5d67c126ff10", |
| 146 | + "id": "a6703cd5-699a-4f30-a1bb-3c8dd10d5952", |
28 | 147 | "metadata": {}, |
29 | 148 | "outputs": [], |
30 | | - "source": [] |
| 149 | + "source": [ |
| 150 | + "# engine = oracle()\n", |
| 151 | + "# engine.template_parser()" |
| 152 | + ] |
| 153 | + }, |
| 154 | + { |
| 155 | + "cell_type": "code", |
| 156 | + "execution_count": null, |
| 157 | + "id": "4c430313-2553-48d5-8ae2-ca12e56fa2d2", |
| 158 | + "metadata": {}, |
| 159 | + "outputs": [], |
| 160 | + "source": [ |
| 161 | + "\n", |
| 162 | + " # Give location where text is\n", |
| 163 | + " # stored which you wish to alter\n", |
| 164 | + "# old_text = soup.find(\"p\", {\"id\": \"para\"})\n", |
| 165 | + "\n", |
| 166 | + "# # Replace the already stored text with\n", |
| 167 | + "# # the new text which you wish to assign\n", |
| 168 | + "# new_text = old_text.find(text=re.compile(\n", |
| 169 | + "# 'Geeks For Geeks')).replace_with('Vinayak Rai')\n", |
| 170 | + "\n", |
| 171 | + "# # Alter HTML file to see the changes done\n", |
| 172 | + "# with open(\"gfg.html\", \"wb\") as f_output:\n", |
| 173 | + "# f_output.write(soup.prettify(\"utf-8\"))" |
| 174 | + ] |
31 | 175 | }, |
32 | 176 | { |
33 | 177 | "cell_type": "code", |
34 | | - "execution_count": 10, |
| 178 | + "execution_count": null, |
35 | 179 | "id": "7558603e-e170-4e36-8b51-1117f4ff9d0a", |
36 | 180 | "metadata": { |
37 | 181 | "tags": [] |
38 | 182 | }, |
39 | | - "outputs": [ |
40 | | - { |
41 | | - "data": { |
42 | | - "text/html": [ |
43 | | - "\n", |
44 | | - " <iframe\n", |
45 | | - " width=\"1200\"\n", |
46 | | - " height=\"1000\"\n", |
47 | | - " src=\"./appTemplate.html\"\n", |
48 | | - " frameborder=\"0\"\n", |
49 | | - " allowfullscreen\n", |
50 | | - " \n", |
51 | | - " ></iframe>\n", |
52 | | - " " |
53 | | - ], |
54 | | - "text/plain": [ |
55 | | - "<IPython.lib.display.IFrame at 0x7f54c6dfba00>" |
56 | | - ] |
57 | | - }, |
58 | | - "execution_count": 10, |
59 | | - "metadata": {}, |
60 | | - "output_type": "execute_result" |
61 | | - } |
62 | | - ], |
| 183 | + "outputs": [], |
63 | 184 | "source": [ |
64 | | - "from IPython.display import IFrame\n", |
| 185 | + "# from IPython.display import IFrame\n", |
65 | 186 | "\n", |
66 | | - "IFrame(src='./appTemplate.html', width=1200, height=1000)" |
| 187 | + "# IFrame(src='./appTemplate.html', width=1200, height=1000)" |
67 | 188 | ] |
68 | 189 | }, |
69 | 190 | { |
|
0 commit comments