Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -27,6 +27,7 @@ streamlit run cell_exp_past.py
|
|
| 27 |
7. Save the processed image locally or rename the processed image and
|
| 28 |
associated files.
|
| 29 |
'''
|
|
|
|
| 30 |
import streamlit as st
|
| 31 |
from PIL import Image, ImageEnhance
|
| 32 |
import pandas as pd
|
|
@@ -106,20 +107,33 @@ if uploaded_files:
|
|
| 106 |
try:
|
| 107 |
new_image_name = f"img_processed{file_ext}.jpg"
|
| 108 |
os.rename(processed_image_path, new_image_name)
|
|
|
|
|
|
|
| 109 |
except FileNotFoundError:
|
| 110 |
st.error(f"{processed_image_path} not found.")
|
|
|
|
| 111 |
else:
|
| 112 |
st.error("Processed image not found.")
|
| 113 |
|
| 114 |
if params_file and os.path.exists(params_file):
|
| 115 |
-
|
| 116 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 117 |
else:
|
| 118 |
st.error("Saved image parameters file not found.")
|
| 119 |
|
| 120 |
if desc_file and os.path.exists(desc_file):
|
| 121 |
-
|
| 122 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 123 |
else:
|
| 124 |
st.error("Saved image description file not found.")
|
| 125 |
|
|
@@ -132,23 +146,28 @@ if uploaded_files:
|
|
| 132 |
|
| 133 |
with tempfile.NamedTemporaryFile(delete=False, suffix='.zip') as zipf:
|
| 134 |
with zipfile.ZipFile(zipf.name, 'w') as z:
|
|
|
|
|
|
|
| 135 |
if desc_file and os.path.exists(desc_file):
|
| 136 |
z.write(desc_file, os.path.basename(desc_file))
|
|
|
|
| 137 |
else:
|
| 138 |
st.warning("Description file not found and was not added to the ZIP.")
|
| 139 |
|
| 140 |
if params_file and os.path.exists(params_file):
|
| 141 |
z.write(params_file, os.path.basename(params_file))
|
|
|
|
| 142 |
else:
|
| 143 |
st.warning("Parameters file not found and was not added to the ZIP.")
|
| 144 |
|
| 145 |
if processed_image_path and os.path.exists(processed_image_path):
|
| 146 |
z.write(processed_image_path, os.path.basename(processed_image_path))
|
|
|
|
| 147 |
else:
|
| 148 |
st.warning("Processed image not found and was not added to the ZIP.")
|
| 149 |
|
| 150 |
# Check if the ZIP file has any content
|
| 151 |
-
if os.path.getsize(zipf.name) > 0:
|
| 152 |
with open(zipf.name, 'rb') as f:
|
| 153 |
st.download_button("Download ZIP", f, "annotations.zip")
|
| 154 |
else:
|
|
|
|
| 27 |
7. Save the processed image locally or rename the processed image and
|
| 28 |
associated files.
|
| 29 |
'''
|
| 30 |
+
|
| 31 |
import streamlit as st
|
| 32 |
from PIL import Image, ImageEnhance
|
| 33 |
import pandas as pd
|
|
|
|
| 107 |
try:
|
| 108 |
new_image_name = f"img_processed{file_ext}.jpg"
|
| 109 |
os.rename(processed_image_path, new_image_name)
|
| 110 |
+
st.session_state['processed_image_path'] = new_image_name # Update session state
|
| 111 |
+
st.success(f"Image renamed to {new_image_name}")
|
| 112 |
except FileNotFoundError:
|
| 113 |
st.error(f"{processed_image_path} not found.")
|
| 114 |
+
|
| 115 |
else:
|
| 116 |
st.error("Processed image not found.")
|
| 117 |
|
| 118 |
if params_file and os.path.exists(params_file):
|
| 119 |
+
try:
|
| 120 |
+
new_params_name = f"saved_image_parameters{file_ext}.json"
|
| 121 |
+
os.rename(params_file, new_params_name)
|
| 122 |
+
st.session_state['params_file'] = new_params_name # Update session state
|
| 123 |
+
st.success(f"Parameters file renamed to {new_params_name}")
|
| 124 |
+
except FileNotFoundError:
|
| 125 |
+
st.error(f"{params_file} not found.")
|
| 126 |
else:
|
| 127 |
st.error("Saved image parameters file not found.")
|
| 128 |
|
| 129 |
if desc_file and os.path.exists(desc_file):
|
| 130 |
+
try:
|
| 131 |
+
new_desc_name = f"saved_image_description{file_ext}.txt"
|
| 132 |
+
os.rename(desc_file, new_desc_name)
|
| 133 |
+
st.session_state['desc_file'] = new_desc_name # Update session state
|
| 134 |
+
st.success(f"Description file renamed to {new_desc_name}")
|
| 135 |
+
except FileNotFoundError:
|
| 136 |
+
st.error(f"{desc_file} not found.")
|
| 137 |
else:
|
| 138 |
st.error("Saved image description file not found.")
|
| 139 |
|
|
|
|
| 146 |
|
| 147 |
with tempfile.NamedTemporaryFile(delete=False, suffix='.zip') as zipf:
|
| 148 |
with zipfile.ZipFile(zipf.name, 'w') as z:
|
| 149 |
+
files_added = False # Flag to check if any file is added
|
| 150 |
+
|
| 151 |
if desc_file and os.path.exists(desc_file):
|
| 152 |
z.write(desc_file, os.path.basename(desc_file))
|
| 153 |
+
files_added = True
|
| 154 |
else:
|
| 155 |
st.warning("Description file not found and was not added to the ZIP.")
|
| 156 |
|
| 157 |
if params_file and os.path.exists(params_file):
|
| 158 |
z.write(params_file, os.path.basename(params_file))
|
| 159 |
+
files_added = True
|
| 160 |
else:
|
| 161 |
st.warning("Parameters file not found and was not added to the ZIP.")
|
| 162 |
|
| 163 |
if processed_image_path and os.path.exists(processed_image_path):
|
| 164 |
z.write(processed_image_path, os.path.basename(processed_image_path))
|
| 165 |
+
files_added = True
|
| 166 |
else:
|
| 167 |
st.warning("Processed image not found and was not added to the ZIP.")
|
| 168 |
|
| 169 |
# Check if the ZIP file has any content
|
| 170 |
+
if os.path.getsize(zipf.name) > 0 and files_added:
|
| 171 |
with open(zipf.name, 'rb') as f:
|
| 172 |
st.download_button("Download ZIP", f, "annotations.zip")
|
| 173 |
else:
|