RyZ commited on
Commit ·
a2d73c6
1
Parent(s): ce458f9
refactor: change Kaggle deploy kernel_type to notebook with ipynb
Browse files- scripts/build_kaggle_deploy.py +46 -29
scripts/build_kaggle_deploy.py
CHANGED
|
@@ -18,33 +18,50 @@ def build_deploy_dir():
|
|
| 18 |
if os.path.exists(os.path.join(base_dir, "README.md")):
|
| 19 |
shutil.copy(os.path.join(base_dir, "README.md"), os.path.join(deploy_dir, "README.md"))
|
| 20 |
|
| 21 |
-
#
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
|
| 36 |
-
|
| 37 |
-
|
| 38 |
-
print("
|
| 39 |
-
|
| 40 |
-
|
| 41 |
-
|
| 42 |
-
|
| 43 |
-
|
| 44 |
-
|
| 45 |
-
"""
|
| 46 |
-
|
| 47 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 48 |
|
| 49 |
# Generate kernel-metadata.json
|
| 50 |
username = os.environ.get("KAGGLE_USERNAME", "benedictusryugunawan")
|
|
@@ -53,9 +70,9 @@ except Exception as e:
|
|
| 53 |
metadata = {
|
| 54 |
"id": f"{username}/{slug}",
|
| 55 |
"title": "BP Monitoring Consumer Daemon",
|
| 56 |
-
"code_file": "run_consumer_kaggle.
|
| 57 |
"language": "python",
|
| 58 |
-
"kernel_type": "
|
| 59 |
"is_private": "true",
|
| 60 |
"enable_gpu": "true",
|
| 61 |
"enable_tpu": "false",
|
|
|
|
| 18 |
if os.path.exists(os.path.join(base_dir, "README.md")):
|
| 19 |
shutil.copy(os.path.join(base_dir, "README.md"), os.path.join(deploy_dir, "README.md"))
|
| 20 |
|
| 21 |
+
# Generate run_consumer_kaggle.ipynb (Jupyter Notebook format)
|
| 22 |
+
notebook_content = {
|
| 23 |
+
"cells": [
|
| 24 |
+
{
|
| 25 |
+
"cell_type": "code",
|
| 26 |
+
"execution_count": None,
|
| 27 |
+
"metadata": {},
|
| 28 |
+
"outputs": [],
|
| 29 |
+
"source": [
|
| 30 |
+
"import subprocess\n",
|
| 31 |
+
"import sys\n",
|
| 32 |
+
"import os\n",
|
| 33 |
+
"\n",
|
| 34 |
+
"print(\"=== Starting Kaggle Consumer Bootstrap ===\")\n",
|
| 35 |
+
"try:\n",
|
| 36 |
+
" print(\"Installing python package and dependencies...\")\n",
|
| 37 |
+
" subprocess.check_call([sys.executable, \"-m\", \"pip\", \"install\", \"-e\", \".\"])\n",
|
| 38 |
+
" print(\"Dependencies installed successfully.\")\n",
|
| 39 |
+
"except Exception as e:\n",
|
| 40 |
+
" print(f\"Error installing dependencies: {e}\")\n",
|
| 41 |
+
" sys.exit(1)\n",
|
| 42 |
+
"\n",
|
| 43 |
+
"try:\n",
|
| 44 |
+
" print(\"Launching message consumer...\")\n",
|
| 45 |
+
" subprocess.check_call([sys.executable, \"-m\", \"src.interface.consumer.run_consumer\"])\n",
|
| 46 |
+
"except KeyboardInterrupt:\n",
|
| 47 |
+
" print(\"Consumer stopped by user.\")\n",
|
| 48 |
+
"except Exception as e:\n",
|
| 49 |
+
" print(f\"Consumer execution failed: {e}\")\n",
|
| 50 |
+
" sys.exit(1)"
|
| 51 |
+
]
|
| 52 |
+
}
|
| 53 |
+
],
|
| 54 |
+
"metadata": {
|
| 55 |
+
"language_info": {
|
| 56 |
+
"name": "python"
|
| 57 |
+
}
|
| 58 |
+
},
|
| 59 |
+
"nbformat": 4,
|
| 60 |
+
"nbformat_minor": 2
|
| 61 |
+
}
|
| 62 |
+
|
| 63 |
+
with open(os.path.join(deploy_dir, "run_consumer_kaggle.ipynb"), "w", encoding="utf-8") as f:
|
| 64 |
+
json.dump(notebook_content, f, indent=4)
|
| 65 |
|
| 66 |
# Generate kernel-metadata.json
|
| 67 |
username = os.environ.get("KAGGLE_USERNAME", "benedictusryugunawan")
|
|
|
|
| 70 |
metadata = {
|
| 71 |
"id": f"{username}/{slug}",
|
| 72 |
"title": "BP Monitoring Consumer Daemon",
|
| 73 |
+
"code_file": "run_consumer_kaggle.ipynb",
|
| 74 |
"language": "python",
|
| 75 |
+
"kernel_type": "notebook",
|
| 76 |
"is_private": "true",
|
| 77 |
"enable_gpu": "true",
|
| 78 |
"enable_tpu": "false",
|