{"metadata":{"kernelspec":{"display_name":"Python 3","language":"python","name":"python3"},"language_info":{"name":"python","version":"3.12.12","mimetype":"text/x-python","codemirror_mode":{"name":"ipython","version":3},"pygments_lexer":"ipython3","nbconvert_exporter":"python","file_extension":".py"},"kaggle":{"accelerator":"nvidiaTeslaT4","dataSources":[{"sourceType":"competition","sourceId":14774,"databundleVersionId":875431},{"sourceType":"datasetVersion","sourceId":15682028,"datasetId":10042795,"databundleVersionId":16620057},{"sourceType":"datasetVersion","sourceId":15671194,"datasetId":10034601,"databundleVersionId":16608570},{"sourceType":"datasetVersion","sourceId":14719917,"datasetId":9405236,"databundleVersionId":15566711},{"sourceType":"datasetVersion","sourceId":15833963,"datasetId":10149714,"databundleVersionId":16783765}],"dockerImageVersionId":31328,"isInternetEnabled":true,"language":"python","sourceType":"notebook","isGpuEnabled":true}},"nbformat_minor":4,"nbformat":4,"cells":[{"cell_type":"markdown","source":"# Two-Stage Lesion-Aware DR Grading — Viva Notebook!\n\nUniversity of Leicester — CO3201 | Simran Sajan\n\n**Required Kaggle dataset inputs:**\n- `simransajan/idriddata` — IDRiD images and ground-truth labels\n- `simransajan/dr-models` — Stage 1 segmentation checkpoints (best_ex_model.pth, best_he_model.pth, best_ma_model.pth)\n- `simransajan/stage-2` — Stage 2 grading checkpoint (best_grading_model.pth)\n\n**MAKE SURE YOU'RE USING T4 AND NOT P100**","metadata":{}},{"cell_type":"code","source":"# install dependencies\n!pip install -q gradio segmentation-models-pytorch monai opencv-python-headless albumentations","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2026-05-03T18:31:48.847609Z","iopub.execute_input":"2026-05-03T18:31:48.847961Z","iopub.status.idle":"2026-05-03T18:31:56.840707Z","shell.execute_reply.started":"2026-05-03T18:31:48.847923Z","shell.execute_reply":"2026-05-03T18:31:56.840026Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"# checkpoints and clone repo\nimport os, shutil\n\nos.makedirs('/kaggle/working/checkpoints', exist_ok=True)\n\nseg_src = '/kaggle/input/datasets/simransajan/dr-models'\nfor f in ['best_ex_model.pth', 'best_he_model.pth', 'best_ma_model.pth']:\n    shutil.copy(os.path.join(seg_src, f), '/kaggle/working/checkpoints/')\n    print(f'copied {f}')\n\nshutil.copy('/kaggle/input/datasets/simransajan/stage-2/best_grading_model.pth', '/kaggle/working/checkpoints/')\nprint('copied best_grading_model.pth')\n\nprint('\\ncheckpoints:')\n!ls -lh /kaggle/working/checkpoints/\n\n!git clone https://huggingface.co/spaces/simrannotts/drgraderdiss /kaggle/working/drgraderdiss","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2026-05-03T18:32:22.399761Z","iopub.execute_input":"2026-05-03T18:32:22.400539Z","iopub.status.idle":"2026-05-03T18:32:27.664512Z","shell.execute_reply.started":"2026-05-03T18:32:22.400502Z","shell.execute_reply":"2026-05-03T18:32:27.663758Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"# launch :)\nimport os, sys\n\nos.chdir('/kaggle/working/drgraderdiss')\nsys.path.insert(0, '/kaggle/working/drgraderdiss')\n\nos.environ['CHECKPOINT_DIR'] = '/kaggle/working/checkpoints'\n\nimport app as _app\n_app.demo.launch(share=True)","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2026-05-03T18:32:33.345932Z","iopub.execute_input":"2026-05-03T18:32:33.346695Z","iopub.status.idle":"2026-05-03T18:33:31.526195Z","shell.execute_reply.started":"2026-05-03T18:32:33.346642Z","shell.execute_reply":"2026-05-03T18:33:31.525260Z"}},"outputs":[],"execution_count":null}]}