Spaces:
Running
Running
pangyuteng commited on
Commit ·
f11f091
1
Parent(s): 0d568ed
2024-01-02 per grace,rreplace json output with csv file
Browse files- .gitignore +2 -1
- app.py +15 -11
.gitignore
CHANGED
|
@@ -1,2 +1,3 @@
|
|
| 1 |
gradio_cached_examples
|
| 2 |
-
|
|
|
|
|
|
| 1 |
gradio_cached_examples
|
| 2 |
+
flagged
|
| 3 |
+
.env
|
app.py
CHANGED
|
@@ -5,6 +5,8 @@ import uuid
|
|
| 5 |
import shutil
|
| 6 |
import tempfile
|
| 7 |
import pydicom
|
|
|
|
|
|
|
| 8 |
import SimpleITK as sitk
|
| 9 |
from huggingface_hub import snapshot_download
|
| 10 |
|
|
@@ -38,6 +40,7 @@ def imread(file_list):
|
|
| 38 |
|
| 39 |
def main_func(input_file_list):
|
| 40 |
with tempfile.TemporaryDirectory() as tempdir:
|
|
|
|
| 41 |
image_file = os.path.join(tempdir,f"image.nii.gz")
|
| 42 |
first_file = input_file_list[0].name
|
| 43 |
if first_file.endswith(".dcm"):
|
|
@@ -63,22 +66,23 @@ def main_func(input_file_list):
|
|
| 63 |
inference(image_file,tempdir,weight_file)
|
| 64 |
|
| 65 |
mask_file = os.path.join(tempdir,"lungqia-0.nii.gz")
|
| 66 |
-
|
| 67 |
my_uid = uuid.uuid4().hex
|
| 68 |
output_pdf_file = os.path.join('/tmp',f'{my_uid}.pdf')
|
| 69 |
-
|
| 70 |
|
| 71 |
-
inst = NiftiVisualizer("NA",image_file,mask_file,
|
| 72 |
tmp_pdf_file = inst.gen_pdf()
|
| 73 |
assert(os.path.exists(tmp_pdf_file))
|
| 74 |
|
| 75 |
-
|
| 76 |
-
output_json = json.loads(f.read())
|
| 77 |
|
| 78 |
shutil.copy(tmp_pdf_file,output_pdf_file)
|
| 79 |
-
shutil.copy(
|
| 80 |
-
|
| 81 |
-
|
|
|
|
|
|
|
| 82 |
|
| 83 |
with gr.Blocks() as demo:
|
| 84 |
with gr.Column():
|
|
@@ -95,12 +99,12 @@ with gr.Blocks() as demo:
|
|
| 95 |
btn = gr.Button("process")
|
| 96 |
with gr.Column():
|
| 97 |
pdf = PDF(label="Upload a PDF", interactive=True)
|
| 98 |
-
|
| 99 |
download_button_pdf = gr.DownloadButton("Download report pdf", visible=True)
|
| 100 |
-
|
| 101 |
btn.click(fn=main_func,
|
| 102 |
inputs=[in_file],
|
| 103 |
-
outputs=[pdf,
|
| 104 |
)#example=[example_nifti_path],cache_examples=True
|
| 105 |
|
| 106 |
|
|
|
|
| 5 |
import shutil
|
| 6 |
import tempfile
|
| 7 |
import pydicom
|
| 8 |
+
import datetime
|
| 9 |
+
import pandas as pd
|
| 10 |
import SimpleITK as sitk
|
| 11 |
from huggingface_hub import snapshot_download
|
| 12 |
|
|
|
|
| 40 |
|
| 41 |
def main_func(input_file_list):
|
| 42 |
with tempfile.TemporaryDirectory() as tempdir:
|
| 43 |
+
print('start time:',datetime.datetime.now().strftime('%Y-%m-%d-%H-%M-%S'))
|
| 44 |
image_file = os.path.join(tempdir,f"image.nii.gz")
|
| 45 |
first_file = input_file_list[0].name
|
| 46 |
if first_file.endswith(".dcm"):
|
|
|
|
| 66 |
inference(image_file,tempdir,weight_file)
|
| 67 |
|
| 68 |
mask_file = os.path.join(tempdir,"lungqia-0.nii.gz")
|
| 69 |
+
csv_file = os.path.join(tempdir,"export-0.csv")
|
| 70 |
my_uid = uuid.uuid4().hex
|
| 71 |
output_pdf_file = os.path.join('/tmp',f'{my_uid}.pdf')
|
| 72 |
+
output_csv_file = os.path.join('/tmp',f'{my_uid}.csv')
|
| 73 |
|
| 74 |
+
inst = NiftiVisualizer("NA",image_file,mask_file,csv_file,tempdir)
|
| 75 |
tmp_pdf_file = inst.gen_pdf()
|
| 76 |
assert(os.path.exists(tmp_pdf_file))
|
| 77 |
|
| 78 |
+
output_df = pd.read_csv(csv_file)
|
|
|
|
| 79 |
|
| 80 |
shutil.copy(tmp_pdf_file,output_pdf_file)
|
| 81 |
+
shutil.copy(csv_file,output_csv_file)
|
| 82 |
+
|
| 83 |
+
print('uid:',os.path.basename(output_csv_file))
|
| 84 |
+
print('end time:',datetime.datetime.now().strftime('%Y-%m-%d-%H-%M-%S'))
|
| 85 |
+
return output_pdf_file, output_df, output_pdf_file, output_csv_file
|
| 86 |
|
| 87 |
with gr.Blocks() as demo:
|
| 88 |
with gr.Column():
|
|
|
|
| 99 |
btn = gr.Button("process")
|
| 100 |
with gr.Column():
|
| 101 |
pdf = PDF(label="Upload a PDF", interactive=True)
|
| 102 |
+
gr_df = gr.Dataframe()
|
| 103 |
download_button_pdf = gr.DownloadButton("Download report pdf", visible=True)
|
| 104 |
+
download_button_csv = gr.DownloadButton("Download report csv", visible=True)
|
| 105 |
btn.click(fn=main_func,
|
| 106 |
inputs=[in_file],
|
| 107 |
+
outputs=[pdf,gr_df,download_button_pdf,download_button_csv],
|
| 108 |
)#example=[example_nifti_path],cache_examples=True
|
| 109 |
|
| 110 |
|