Spaces:
Sleeping
Sleeping
import gradio as gr | |
import pydicom | |
import pandas as pd | |
from pathlib import Path | |
from io import BytesIO | |
def convert_dicom_to_tsv(dicom_file): | |
# dicom_file = pathlib.Path(__loader__).parent / "." | |
# Read the DICOM file | |
pydicom = dicom_data.dcmread(dicom_file) | |
# Extract data elements from the DICOM file | |
data_elements = {de.tag: (de.description(), de.value) for de in dicom_data} | |
# Convert to DataFrame | |
df = pd.DataFrame(list(data_elements.values()), columns=["Description", "Value"]) | |
# Convert DataFrame to TSV format and store in a buffer | |
buffer = BytesIO() | |
df.to_csv(buffer, sep='\t', index=False, encoding='utf-8') | |
buffer.seek(0) | |
return buffer | |
# Create a Gradio interface | |
app = gr.Interface( | |
fn=convert_dicom_to_tsv, | |
gr.inputs.File(label="Upload DICOM File",), | |
gr.outputs.File(label="Download TSV File"), | |
title="DICOM to TSV Converter", | |
description="Upload a DICOM file and convert it to TSV format." | |
) | |
if __name__ == "__main__": | |
app.launch(share=True) |