Update app.py
Browse files
app.py
CHANGED
|
@@ -16,6 +16,11 @@ os.environ["CUDA_DEVICE_ORDER"] = "PCI_BUS_ID"
|
|
| 16 |
os.environ["CUDA_VISIBLE_DEVICES"] = "" # Set the GPU to use, if available
|
| 17 |
|
| 18 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 19 |
import os
|
| 20 |
|
| 21 |
output_root = os.path.join("/tmp", "DICOM_OUTPUTS")
|
|
@@ -511,6 +516,19 @@ def clear_dir(path):
|
|
| 511 |
else:
|
| 512 |
os.makedirs(path, exist_ok=True)
|
| 513 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 514 |
|
| 515 |
|
| 516 |
# =========================================================
|
|
@@ -640,23 +658,25 @@ def main():
|
|
| 640 |
df.to_excel(xlsx_path, index=False)
|
| 641 |
print(f"\nCSV written: {csv_path}")
|
| 642 |
print(f"Excel written: {xlsx_path}")
|
| 643 |
-
|
| 644 |
-
|
| 645 |
-
|
| 646 |
-
|
| 647 |
-
|
| 648 |
-
|
| 649 |
-
|
| 650 |
-
|
| 651 |
-
|
| 652 |
-
|
| 653 |
-
|
| 654 |
-
|
| 655 |
-
|
| 656 |
-
|
| 657 |
-
|
| 658 |
-
|
| 659 |
-
|
|
|
|
|
|
|
| 660 |
|
| 661 |
|
| 662 |
|
|
|
|
| 16 |
os.environ["CUDA_VISIBLE_DEVICES"] = "" # Set the GPU to use, if available
|
| 17 |
|
| 18 |
|
| 19 |
+
if "artifacts" not in st.session_state:
|
| 20 |
+
st.session_state.artifacts = {} # {"gif_bytes": ..., "csv_bytes": ...}
|
| 21 |
+
if "processed" not in st.session_state:
|
| 22 |
+
st.session_state.processed = False
|
| 23 |
+
|
| 24 |
import os
|
| 25 |
|
| 26 |
output_root = os.path.join("/tmp", "DICOM_OUTPUTS")
|
|
|
|
| 516 |
else:
|
| 517 |
os.makedirs(path, exist_ok=True)
|
| 518 |
|
| 519 |
+
def process_zip_and_make_artifacts(uploaded_zip):
|
| 520 |
+
# ... your existing extraction + processing ...
|
| 521 |
+
# e.g., write GIF to a BytesIO and CSV to bytes
|
| 522 |
+
|
| 523 |
+
gif_buf = BytesIO()
|
| 524 |
+
# anim.save(gif_buf, writer="pillow", format="gif"); gif_buf.seek(0)
|
| 525 |
+
# For demo, pretend we have bytes:
|
| 526 |
+
# gif_buf.write(b"..."); gif_buf.seek(0)
|
| 527 |
+
|
| 528 |
+
csv_bytes = b"col1,col2\n1,2\n3,4\n"
|
| 529 |
+
|
| 530 |
+
return gif_buf.getvalue(), csv_bytes
|
| 531 |
+
|
| 532 |
|
| 533 |
|
| 534 |
# =========================================================
|
|
|
|
| 658 |
df.to_excel(xlsx_path, index=False)
|
| 659 |
print(f"\nCSV written: {csv_path}")
|
| 660 |
print(f"Excel written: {xlsx_path}")
|
| 661 |
+
st.session_state.processed = True
|
| 662 |
+
|
| 663 |
+
if st.session_state.processed == True:
|
| 664 |
+
|
| 665 |
+
with open(gif_path, "rb") as f:
|
| 666 |
+
st.download_button(
|
| 667 |
+
label="📥 Download GIF",
|
| 668 |
+
data=f,
|
| 669 |
+
file_name="mask.gif",
|
| 670 |
+
mime="image/gif"
|
| 671 |
+
)
|
| 672 |
+
|
| 673 |
+
with open(csv_path, "rb") as f:
|
| 674 |
+
st.download_button(
|
| 675 |
+
label="Download CSV",
|
| 676 |
+
data=f,
|
| 677 |
+
file_name="/Cardiac_Volumes_And_Mass_fromPredictions.csv",
|
| 678 |
+
mime="text/csv"
|
| 679 |
+
)
|
| 680 |
|
| 681 |
|
| 682 |
|