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): | |
# Read the DICOM file | |
dicom_data = pydicom.dcmread(dicom_file.name) | |
# 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, | |
inputs=gr.File(label="Upload DICOM file"), | |
outputs=gr.File(label="Download TSV file"), | |
title="DICOM to TSV Converter", | |
description="Upload a DICOM file to convert it to TSV format." | |
) | |
if __name__ == "__main__": | |
app.launch | |