Spaces:
Sleeping
Sleeping
File size: 984 Bytes
2f0fdb0 adfd907 75e757f adfd907 d9cd8bd adfd907 2f0fdb0 adfd907 cbcfa0d 2f0fdb0 f9cf1cf adfd907 75e757f e8679dd |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
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
|