pixelpandacreative commited on
Commit
adfd907
1 Parent(s): 0addd51

Create app.py

Browse files

Converter file

Files changed (1) hide show
  1. app.py +33 -0
app.py ADDED
@@ -0,0 +1,33 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ import pydicom
3
+ import pandas as pd
4
+ from io import BytesIO
5
+
6
+ def convert_dicom_to_tsv(dicom_file):
7
+ # Read the DICOM file
8
+ dicom_data = pydicom.dcmread(dicom_file)
9
+
10
+ # Extract data elements from the DICOM file
11
+ data_elements = {de.tag: (de.description(), de.value) for de in dicom_data}
12
+
13
+ # Convert to DataFrame
14
+ df = pd.DataFrame(list(data_elements.values()), columns=["Description", "Value"])
15
+
16
+ # Convert DataFrame to TSV format and store in a buffer
17
+ buffer = BytesIO()
18
+ df.to_csv(buffer, sep='\t', index=False, encoding='utf-8')
19
+ buffer.seek(0)
20
+
21
+ return buffer
22
+
23
+ # Create a Gradio interface
24
+ iface = gr.Interface(
25
+ fn=convert_dicom_to_tsv,
26
+ inputs=gr.inputs.File(label="Upload DICOM File"),
27
+ outputs=gr.outputs.File(label="Download TSV File"),
28
+ title="DICOM to TSV Converter",
29
+ description="Upload a DICOM file and convert it to TSV format."
30
+ )
31
+
32
+ if __name__ == "__main__":
33
+ iface.launch()