Skip to content

Commit 76ef8c9

Browse files
committed
Colab: git clone で GIT_TERMINAL_PROMPT=0 を使用して認証エラーを回避
Made-with: Cursor
1 parent cd26ccb commit 76ef8c9

1 file changed

Lines changed: 55 additions & 43 deletions

File tree

MediSeg_AI_Colab.ipynb

Lines changed: 55 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -32,28 +32,38 @@
3232
},
3333
{
3434
"cell_type": "code",
35-
"execution_count": null,
3635
"metadata": {},
37-
"outputs": [],
3836
"source": [
3937
"# リポジトリのクローン\n",
4038
"# このリポジトリ (shingo257/MediSeg-AI) をクローン。フォークした場合は URL を書き換えてください。\n",
39+
"# GIT_TERMINAL_PROMPT=0 で Colab 環境での認証プロンプトエラーを防ぐ\n",
4140
"REPO_URL = \"https://github.com/shingo257/MediSeg-AI.git\"\n",
4241
"REPO_DIR = \"/content/MediSeg-AI\"\n",
4342
"\n",
4443
"import os\n",
4544
"if not os.path.exists(REPO_DIR):\n",
46-
" !git clone {REPO_URL} {REPO_DIR}\n",
47-
" print(\"Repository cloned\")\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",
4857
"else:\n",
49-
" print(\"Repository already exists\")\n"
50-
]
58+
" print(\"Repository already exists\")\n",
59+
""
60+
],
61+
"execution_count": null,
62+
"outputs": []
5163
},
5264
{
5365
"cell_type": "code",
54-
"execution_count": null,
5566
"metadata": {},
56-
"outputs": [],
5767
"source": [
5868
"# 作業ディレクトリに移動\n",
5969
"import os\n",
@@ -68,7 +78,9 @@
6878
"# セットアップスクリプトの実行\n",
6979
"print(\"\\n🔧 Running setup script...\")\n",
7080
"!python colab_setup.py\n"
71-
]
81+
],
82+
"execution_count": null,
83+
"outputs": []
7284
},
7385
{
7486
"cell_type": "markdown",
@@ -83,9 +95,7 @@
8395
},
8496
{
8597
"cell_type": "code",
86-
"execution_count": null,
8798
"metadata": {},
88-
"outputs": [],
8999
"source": [
90100
"# Google Driveのマウント\n",
91101
"try:\n",
@@ -103,7 +113,9 @@
103113
"except Exception as e:\n",
104114
" print(f'⚠️ Google Drive mount failed: {e}')\n",
105115
" print(' Continuing without Drive (data will be lost when session ends)')\n"
106-
]
116+
],
117+
"execution_count": null,
118+
"outputs": []
107119
},
108120
{
109121
"cell_type": "markdown",
@@ -119,9 +131,7 @@
119131
},
120132
{
121133
"cell_type": "code",
122-
"execution_count": null,
123134
"metadata": {},
124-
"outputs": [],
125135
"source": [
126136
"# ngrokトークンを設定(オプション)\n",
127137
"# ⚠️ ここにngrokトークンを貼り付けてください\n",
@@ -132,7 +142,9 @@
132142
"else:\n",
133143
" print(\"⚠️ No ngrok token - using local access only\")\n",
134144
" print(\" Get free token at: https://dashboard.ngrok.com/get-started/your-authtoken\")\n"
135-
]
145+
],
146+
"execution_count": null,
147+
"outputs": []
136148
},
137149
{
138150
"cell_type": "markdown",
@@ -145,9 +157,7 @@
145157
},
146158
{
147159
"cell_type": "code",
148-
"execution_count": null,
149160
"metadata": {},
150-
"outputs": [],
151161
"source": [
152162
"# GPUの確認\n",
153163
"import torch\n",
@@ -168,7 +178,9 @@
168178
" _token = \"\"\n",
169179
"from colab_launcher import launch_web_gui\n",
170180
"launch_web_gui(ngrok_token=_token if _token else None)\n"
171-
]
181+
],
182+
"execution_count": null,
183+
"outputs": []
172184
},
173185
{
174186
"cell_type": "markdown",
@@ -181,9 +193,7 @@
181193
},
182194
{
183195
"cell_type": "code",
184-
"execution_count": null,
185196
"metadata": {},
186-
"outputs": [],
187197
"source": [
188198
"# デモ(データ不要・数秒で完了)\n",
189199
"!python main.py demo\n",
@@ -193,7 +203,9 @@
193203
"# d = RealDatasetDownloader(data_dir=\"/content/MediSeg-AI/data\")\n",
194204
"# d.download_dataset(\"medical_small\")\n",
195205
"# !python main.py train-medical --data-dir /content/MediSeg-AI/data/medical_small --save-dir /content/MediSeg-AI/results"
196-
]
206+
],
207+
"execution_count": null,
208+
"outputs": []
197209
},
198210
{
199211
"cell_type": "markdown",
@@ -290,9 +302,7 @@
290302
},
291303
{
292304
"cell_type": "code",
293-
"execution_count": null,
294305
"metadata": {},
295-
"outputs": [],
296306
"source": [
297307
"# システム情報の表示\n",
298308
"import torch\n",
@@ -341,7 +351,9 @@
341351
" print(f\"\\n⚠️ Could not load dataset information: {e}\")\n",
342352
"\n",
343353
"print(\"=\"*60)\n"
344-
]
354+
],
355+
"execution_count": null,
356+
"outputs": []
345357
},
346358
{
347359
"cell_type": "markdown",
@@ -354,9 +366,7 @@
354366
},
355367
{
356368
"cell_type": "code",
357-
"execution_count": null,
358369
"metadata": {},
359-
"outputs": [],
360370
"source": [
361371
"# データセットのダウンロード\n",
362372
"# ⚠️ データセットによっては時間がかかります\n",
@@ -382,7 +392,9 @@
382392
"\n",
383393
"# 例: 小さな医療データセットをダウンロード(コメントアウトを外して実行)\n",
384394
"# downloader.download_dataset('medical_small')\n"
385-
]
395+
],
396+
"execution_count": null,
397+
"outputs": []
386398
},
387399
{
388400
"cell_type": "markdown",
@@ -395,9 +407,7 @@
395407
},
396408
{
397409
"cell_type": "code",
398-
"execution_count": null,
399410
"metadata": {},
400-
"outputs": [],
401411
"source": [
402412
"# メモリ管理ヘルパー関数\n",
403413
"\n",
@@ -440,7 +450,9 @@
440450
"print(\"✅ Memory management functions loaded\")\n",
441451
"print(\" Use clear_memory() to free memory\")\n",
442452
"print(\" Use show_memory_usage() to check GPU memory\")\n"
443-
]
453+
],
454+
"execution_count": null,
455+
"outputs": []
444456
},
445457
{
446458
"cell_type": "markdown",
@@ -471,9 +483,7 @@
471483
},
472484
{
473485
"cell_type": "code",
474-
"execution_count": null,
475486
"metadata": {},
476-
"outputs": [],
477487
"source": [
478488
"# 環境テスト: すべてのコンポーネントが正しく動作するか確認\n",
479489
"\n",
@@ -528,7 +538,9 @@
528538
"\n",
529539
"print(\"=\"*60)\n",
530540
"print(\"✅ Environment test complete!\")\n"
531-
]
541+
],
542+
"execution_count": null,
543+
"outputs": []
532544
},
533545
{
534546
"cell_type": "markdown",
@@ -541,9 +553,7 @@
541553
},
542554
{
543555
"cell_type": "code",
544-
"execution_count": null,
545556
"metadata": {},
546-
"outputs": [],
547557
"source": [
548558
"# 便利なヘルパー関数\n",
549559
"\n",
@@ -616,7 +626,9 @@
616626
"print(\" - load_from_drive(file_name): Load file from Google Drive\")\n",
617627
"print(\" - check_session_time(): Check session information\")\n",
618628
"print(\" - list_files(directory): List files in directory\")\n"
619-
]
629+
],
630+
"execution_count": null,
631+
"outputs": []
620632
},
621633
{
622634
"cell_type": "markdown",
@@ -629,9 +641,7 @@
629641
},
630642
{
631643
"cell_type": "code",
632-
"execution_count": null,
633644
"metadata": {},
634-
"outputs": [],
635645
"source": [
636646
"# 使用例: 画像のセグメンテーション処理\n",
637647
"\n",
@@ -668,13 +678,13 @@
668678
"\n",
669679
"# 実行(コメントアウトを外して実行)\n",
670680
"# example_segmentation()\n"
671-
]
681+
],
682+
"execution_count": null,
683+
"outputs": []
672684
},
673685
{
674686
"cell_type": "code",
675-
"execution_count": null,
676687
"metadata": {},
677-
"outputs": [],
678688
"source": [
679689
"# クイックスタート: すべてのセットアップを一度に実行\n",
680690
"# ⚠️ 上記のセルを個別に実行することを推奨します\n",
@@ -705,7 +715,9 @@
705715
"NGROK_TOKEN = \"\" # オプション: ngrokトークンを設定\n",
706716
"from colab_launcher import launch_web_gui\n",
707717
"launch_web_gui(ngrok_token=NGROK_TOKEN if NGROK_TOKEN else None)\n"
708-
]
718+
],
719+
"execution_count": null,
720+
"outputs": []
709721
}
710722
],
711723
"metadata": {
@@ -715,4 +727,4 @@
715727
},
716728
"nbformat": 4,
717729
"nbformat_minor": 2
718-
}
730+
}

0 commit comments

Comments
 (0)