{"metadata":{"kernelspec":{"language":"python","display_name":"Python 3","name":"python3"},"language_info":{"name":"python","version":"3.11.13","mimetype":"text/x-python","codemirror_mode":{"name":"ipython","version":3},"pygments_lexer":"ipython3","nbconvert_exporter":"python","file_extension":".py"},"kaggle":{"accelerator":"none","dataSources":[{"sourceId":99552,"databundleVersionId":13851420,"sourceType":"competition"}],"dockerImageVersionId":31089,"isInternetEnabled":false,"language":"python","sourceType":"notebook","isGpuEnabled":false}},"nbformat_minor":4,"nbformat":4,"cells":[{"cell_type":"code","source":"# RSNA Intracranial Aneurysm Detection - MINIMAL WORKING SUBMISSION\nimport os\nimport shutil\nfrom collections import defaultdict\nimport pandas as pd\nimport polars as pl\nimport pydicom\nimport kaggle_evaluation.rsna_inference_server\n\n# Competition constants (copy from demo)\nID_COL = 'SeriesInstanceUID'\nLABEL_COLS = [\n    'Left Infraclinoid Internal Carotid Artery',\n    'Right Infraclinoid Internal Carotid Artery',\n    'Left Supraclinoid Internal Carotid Artery',\n    'Right Supraclinoid Internal Carotid Artery',\n    'Left Middle Cerebral Artery',\n    'Right Middle Cerebral Artery',\n    'Anterior Communicating Artery',\n    'Left Anterior Cerebral Artery',\n    'Right Anterior Cerebral Artery',\n    'Left Posterior Communicating Artery',\n    'Right Posterior Communicating Artery',\n    'Basilar Tip',\n    'Other Posterior Circulation',\n    'Aneurysm Present',\n]\n\nDICOM_TAG_ALLOWLIST = [\n    'BitsAllocated', 'BitsStored', 'Columns', 'FrameOfReferenceUID', 'HighBit',\n    'ImageOrientationPatient', 'ImagePositionPatient', 'InstanceNumber', 'Modality',\n    'PatientID', 'PhotometricInterpretation', 'PixelRepresentation', 'PixelSpacing',\n    'PlanarConfiguration', 'RescaleIntercept', 'RescaleSlope', 'RescaleType', 'Rows',\n    'SOPClassUID', 'SOPInstanceUID', 'SamplesPerPixel', 'SliceThickness',\n    'SpacingBetweenSlices', 'StudyInstanceUID', 'TransferSyntaxUID',\n]\n\n# REPLACE THIS FUNCTION WITH YOUR INFERENCE CODE\ndef predict(series_path: str) -> pl.DataFrame | pd.DataFrame:\n    \"\"\"Make a prediction - MINIMAL VERSION\"\"\"\n    series_id = os.path.basename(series_path)\n    \n    # Default predictions (0.5 for all classes)\n    predictions = pl.DataFrame(\n        data=[[series_id] + [0.5] * len(LABEL_COLS)],\n        schema=[ID_COL] + LABEL_COLS,\n        orient='row',\n    )\n    \n    # IMPORTANT: Clean up to prevent disk space errors\n    shutil.rmtree('/kaggle/shared', ignore_errors=True)\n    \n    return predictions.drop(ID_COL)\n\n# Competition execution flow\nprint(\"🚀 Starting RSNA Aneurysm Detection Submission\")\ninference_server = kaggle_evaluation.rsna_inference_server.RSNAInferenceServer(predict)\n\nif os.getenv('KAGGLE_IS_COMPETITION_RERUN'):\n    print(\"🏆 COMPETITION MODE: Serving inference server...\")\n    inference_server.serve()\nelse:\n    print(\"💻 LOCAL MODE: Running local gateway...\")\n    inference_server.run_local_gateway()\n    result = pl.read_parquet('/kaggle/working/submission.parquet')\n    print(\"✅ submission.parquet created successfully!\")\n    print(\"📊 Submission preview:\")\n    display(result)","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-09-30T18:33:26.586664Z","iopub.execute_input":"2025-09-30T18:33:26.587142Z","iopub.status.idle":"2025-09-30T18:33:33.642475Z","shell.execute_reply.started":"2025-09-30T18:33:26.587116Z","shell.execute_reply":"2025-09-30T18:33:33.641421Z"}},"outputs":[],"execution_count":null}]}