| import streamlit as st |
| from idc_index import index |
| from pathlib import Path |
| import pydicom |
| import pandas as pd |
| import pyarrow as pa |
| import pyarrow.parquet as pq |
| from tempfile import TemporaryDirectory |
| import os |
| from pathlib import Path |
| import polars |
| import pydicom.datadict as dd |
| import shutil |
|
|
|
|
| |
| st.title("DICOM Classification Demo") |
| st.write("Select IDC data to download, extract images and metadata, and perform inference using three pre-trained models") |
|
|
| |
| client = index.IDCClient() |
| index_df = client.index |
|
|
| |
| st.subheader("Choose IDC Data to Process") |
| collection_ids = index_df["collection_id"].unique() |
| selected_collection_id = st.selectbox("Select Collection ID", collection_ids) |
|
|
| |
| df_filtered_by_collection = index_df[index_df["collection_id"] == selected_collection_id] |
|
|
| patients = df_filtered_by_collection["PatientID"].unique() |
| selected_patient_id = st.selectbox("Select Patient ID", patients) |
|
|
| |
| df_filtered_by_patient = df_filtered_by_collection[df_filtered_by_collection["PatientID"] == selected_patient_id] |
|
|
| modalities = df_filtered_by_patient["Modality"].unique() |
| selected_modality = st.selectbox("Select Modality", modalities) |
|
|
| |
| df_filtered_by_modality = df_filtered_by_patient[df_filtered_by_patient["Modality"] == selected_modality] |
|
|
| studies = df_filtered_by_modality["StudyInstanceUID"].unique() |
| selected_study = st.selectbox("Select Study", studies) |
|
|
| |
| df_filtered_by_study = df_filtered_by_modality[df_filtered_by_modality["StudyInstanceUID"] == selected_study] |
|
|
| series = df_filtered_by_study["SeriesInstanceUID"].unique() |
| selected_series = st.selectbox("Select Series", series) |
|
|
|
|
| |
| if st.button("Process IDC data"): |
| |
| selection = index_df[ |
| (index_df["SeriesInstanceUID"] == selected_series) |
| ] |
|
|
| series_instance_uids = selection["SeriesInstanceUID"].tolist() |
|
|
| |
| download_errors = [] |
| |
| input_dir=Path("input_data/") |
| if input_dir.exists(): |
| shutil.rmtree(input_dir) |
| os.makedirs(input_dir, exist_ok=True) |
|
|
| try: |
| client.download_from_selection(seriesInstanceUID=series_instance_uids, downloadDir=input_dir) |
| except Exception as e: |
| download_errors.append(f"Error downloading data: {str(e)}") |
|
|
| if download_errors: |
| st.error("\n".join(download_errors)) |
| else: |
| st.success("Data downloaded successfully.") |
|
|
| |
| dicom_files = [str(file) for file in input_dir.glob('**/*.dcm')] |
| |
| |
|
|
| st.success("Processing complete.") |
| |
| |
| |
| |
| |
| |
| |