Skip to content

Commit a891c43

Browse files
committed
Colab: git clone を ZIP ダウンロードに変更(認証エラー回避)
Made-with: Cursor
1 parent 76ef8c9 commit a891c43

1 file changed

Lines changed: 56 additions & 58 deletions

File tree

MediSeg_AI_Colab.ipynb

Lines changed: 56 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -32,38 +32,38 @@
3232
},
3333
{
3434
"cell_type": "code",
35+
"execution_count": null,
3536
"metadata": {},
37+
"outputs": [],
3638
"source": [
37-
"# リポジトリのクローン\n",
38-
"# このリポジトリ (shingo257/MediSeg-AI) をクローン。フォークした場合は URL を書き換えてください。\n",
39-
"# GIT_TERMINAL_PROMPT=0 で Colab 環境での認証プロンプトエラーを防ぐ\n",
40-
"REPO_URL = \"https://github.com/shingo257/MediSeg-AI.git\"\n",
39+
"# リポジトリの取得(ZIP でダウンロード - Colab で git 認証エラーを避ける)\n",
40+
"# このリポジトリ (shingo257/MediSeg-AI) を取得。フォークした場合は ZIP_URL を書き換えてください。\n",
4141
"REPO_DIR = \"/content/MediSeg-AI\"\n",
42+
"ZIP_URL = \"https://github.com/shingo257/MediSeg-AI/archive/refs/heads/main.zip\"\n",
4243
"\n",
4344
"import os\n",
45+
"import urllib.request\n",
46+
"import zipfile\n",
47+
"\n",
4448
"if not os.path.exists(REPO_DIR):\n",
45-
" import subprocess\n",
46-
" r = subprocess.run(\n",
47-
" [\"git\", \"clone\", REPO_URL, REPO_DIR],\n",
48-
" env={**os.environ, \"GIT_TERMINAL_PROMPT\": \"0\"},\n",
49-
" capture_output=True,\n",
50-
" text=True,\n",
51-
" )\n",
52-
" if r.returncode == 0:\n",
53-
" print(\"Repository cloned\")\n",
54-
" else:\n",
55-
" print(\"Clone failed:\", r.stderr or r.stdout)\n",
56-
" raise SystemExit(r.returncode)\n",
49+
" zip_path = \"/tmp/MediSeg-AI-main.zip\"\n",
50+
" print(\"Downloading repository...\")\n",
51+
" urllib.request.urlretrieve(ZIP_URL, zip_path)\n",
52+
" print(\"Extracting...\")\n",
53+
" with zipfile.ZipFile(zip_path, \"r\") as z:\n",
54+
" z.extractall(\"/content\")\n",
55+
" os.rename(\"/content/MediSeg-AI-main\", REPO_DIR)\n",
56+
" os.remove(zip_path)\n",
57+
" print(\"Repository ready:\", REPO_DIR)\n",
5758
"else:\n",
58-
" print(\"Repository already exists\")\n",
59-
""
60-
],
61-
"execution_count": null,
62-
"outputs": []
59+
" print(\"Repository already exists\")\n"
60+
]
6361
},
6462
{
6563
"cell_type": "code",
64+
"execution_count": null,
6665
"metadata": {},
66+
"outputs": [],
6767
"source": [
6868
"# 作業ディレクトリに移動\n",
6969
"import os\n",
@@ -78,9 +78,7 @@
7878
"# セットアップスクリプトの実行\n",
7979
"print(\"\\n🔧 Running setup script...\")\n",
8080
"!python colab_setup.py\n"
81-
],
82-
"execution_count": null,
83-
"outputs": []
81+
]
8482
},
8583
{
8684
"cell_type": "markdown",
@@ -95,7 +93,9 @@
9593
},
9694
{
9795
"cell_type": "code",
96+
"execution_count": null,
9897
"metadata": {},
98+
"outputs": [],
9999
"source": [
100100
"# Google Driveのマウント\n",
101101
"try:\n",
@@ -113,9 +113,7 @@
113113
"except Exception as e:\n",
114114
" print(f'⚠️ Google Drive mount failed: {e}')\n",
115115
" print(' Continuing without Drive (data will be lost when session ends)')\n"
116-
],
117-
"execution_count": null,
118-
"outputs": []
116+
]
119117
},
120118
{
121119
"cell_type": "markdown",
@@ -131,7 +129,9 @@
131129
},
132130
{
133131
"cell_type": "code",
132+
"execution_count": null,
134133
"metadata": {},
134+
"outputs": [],
135135
"source": [
136136
"# ngrokトークンを設定(オプション)\n",
137137
"# ⚠️ ここにngrokトークンを貼り付けてください\n",
@@ -142,9 +142,7 @@
142142
"else:\n",
143143
" print(\"⚠️ No ngrok token - using local access only\")\n",
144144
" print(\" Get free token at: https://dashboard.ngrok.com/get-started/your-authtoken\")\n"
145-
],
146-
"execution_count": null,
147-
"outputs": []
145+
]
148146
},
149147
{
150148
"cell_type": "markdown",
@@ -157,7 +155,9 @@
157155
},
158156
{
159157
"cell_type": "code",
158+
"execution_count": null,
160159
"metadata": {},
160+
"outputs": [],
161161
"source": [
162162
"# GPUの確認\n",
163163
"import torch\n",
@@ -178,9 +178,7 @@
178178
" _token = \"\"\n",
179179
"from colab_launcher import launch_web_gui\n",
180180
"launch_web_gui(ngrok_token=_token if _token else None)\n"
181-
],
182-
"execution_count": null,
183-
"outputs": []
181+
]
184182
},
185183
{
186184
"cell_type": "markdown",
@@ -193,7 +191,9 @@
193191
},
194192
{
195193
"cell_type": "code",
194+
"execution_count": null,
196195
"metadata": {},
196+
"outputs": [],
197197
"source": [
198198
"# デモ(データ不要・数秒で完了)\n",
199199
"!python main.py demo\n",
@@ -203,9 +203,7 @@
203203
"# d = RealDatasetDownloader(data_dir=\"/content/MediSeg-AI/data\")\n",
204204
"# d.download_dataset(\"medical_small\")\n",
205205
"# !python main.py train-medical --data-dir /content/MediSeg-AI/data/medical_small --save-dir /content/MediSeg-AI/results"
206-
],
207-
"execution_count": null,
208-
"outputs": []
206+
]
209207
},
210208
{
211209
"cell_type": "markdown",
@@ -302,7 +300,9 @@
302300
},
303301
{
304302
"cell_type": "code",
303+
"execution_count": null,
305304
"metadata": {},
305+
"outputs": [],
306306
"source": [
307307
"# システム情報の表示\n",
308308
"import torch\n",
@@ -351,9 +351,7 @@
351351
" print(f\"\\n⚠️ Could not load dataset information: {e}\")\n",
352352
"\n",
353353
"print(\"=\"*60)\n"
354-
],
355-
"execution_count": null,
356-
"outputs": []
354+
]
357355
},
358356
{
359357
"cell_type": "markdown",
@@ -366,7 +364,9 @@
366364
},
367365
{
368366
"cell_type": "code",
367+
"execution_count": null,
369368
"metadata": {},
369+
"outputs": [],
370370
"source": [
371371
"# データセットのダウンロード\n",
372372
"# ⚠️ データセットによっては時間がかかります\n",
@@ -392,9 +392,7 @@
392392
"\n",
393393
"# 例: 小さな医療データセットをダウンロード(コメントアウトを外して実行)\n",
394394
"# downloader.download_dataset('medical_small')\n"
395-
],
396-
"execution_count": null,
397-
"outputs": []
395+
]
398396
},
399397
{
400398
"cell_type": "markdown",
@@ -407,7 +405,9 @@
407405
},
408406
{
409407
"cell_type": "code",
408+
"execution_count": null,
410409
"metadata": {},
410+
"outputs": [],
411411
"source": [
412412
"# メモリ管理ヘルパー関数\n",
413413
"\n",
@@ -450,9 +450,7 @@
450450
"print(\"✅ Memory management functions loaded\")\n",
451451
"print(\" Use clear_memory() to free memory\")\n",
452452
"print(\" Use show_memory_usage() to check GPU memory\")\n"
453-
],
454-
"execution_count": null,
455-
"outputs": []
453+
]
456454
},
457455
{
458456
"cell_type": "markdown",
@@ -483,7 +481,9 @@
483481
},
484482
{
485483
"cell_type": "code",
484+
"execution_count": null,
486485
"metadata": {},
486+
"outputs": [],
487487
"source": [
488488
"# 環境テスト: すべてのコンポーネントが正しく動作するか確認\n",
489489
"\n",
@@ -538,9 +538,7 @@
538538
"\n",
539539
"print(\"=\"*60)\n",
540540
"print(\"✅ Environment test complete!\")\n"
541-
],
542-
"execution_count": null,
543-
"outputs": []
541+
]
544542
},
545543
{
546544
"cell_type": "markdown",
@@ -553,7 +551,9 @@
553551
},
554552
{
555553
"cell_type": "code",
554+
"execution_count": null,
556555
"metadata": {},
556+
"outputs": [],
557557
"source": [
558558
"# 便利なヘルパー関数\n",
559559
"\n",
@@ -626,9 +626,7 @@
626626
"print(\" - load_from_drive(file_name): Load file from Google Drive\")\n",
627627
"print(\" - check_session_time(): Check session information\")\n",
628628
"print(\" - list_files(directory): List files in directory\")\n"
629-
],
630-
"execution_count": null,
631-
"outputs": []
629+
]
632630
},
633631
{
634632
"cell_type": "markdown",
@@ -641,7 +639,9 @@
641639
},
642640
{
643641
"cell_type": "code",
642+
"execution_count": null,
644643
"metadata": {},
644+
"outputs": [],
645645
"source": [
646646
"# 使用例: 画像のセグメンテーション処理\n",
647647
"\n",
@@ -678,13 +678,13 @@
678678
"\n",
679679
"# 実行(コメントアウトを外して実行)\n",
680680
"# example_segmentation()\n"
681-
],
682-
"execution_count": null,
683-
"outputs": []
681+
]
684682
},
685683
{
686684
"cell_type": "code",
685+
"execution_count": null,
687686
"metadata": {},
687+
"outputs": [],
688688
"source": [
689689
"# クイックスタート: すべてのセットアップを一度に実行\n",
690690
"# ⚠️ 上記のセルを個別に実行することを推奨します\n",
@@ -715,9 +715,7 @@
715715
"NGROK_TOKEN = \"\" # オプション: ngrokトークンを設定\n",
716716
"from colab_launcher import launch_web_gui\n",
717717
"launch_web_gui(ngrok_token=NGROK_TOKEN if NGROK_TOKEN else None)\n"
718-
],
719-
"execution_count": null,
720-
"outputs": []
718+
]
721719
}
722720
],
723721
"metadata": {
@@ -727,4 +725,4 @@
727725
},
728726
"nbformat": 4,
729727
"nbformat_minor": 2
730-
}
728+
}

0 commit comments

Comments
 (0)