Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -95,10 +95,6 @@ def apply_enhancements(img, x, y, zoom, contrast, brightness, sharpness):
|
|
| 95 |
enhanced_sharpness = ImageEnhance.Sharpness(enhanced_brightness).enhance(sharpness)
|
| 96 |
return enhanced_sharpness
|
| 97 |
|
| 98 |
-
# Initialize session state for processed image
|
| 99 |
-
if 'processed_img' not in st.session_state:
|
| 100 |
-
st.session_state.processed_img = None
|
| 101 |
-
|
| 102 |
st.set_page_config(page_title="CLL Explorer", layout="wide")
|
| 103 |
st.title("CLL Explorer: Cell Image Analysis Prep Tool")
|
| 104 |
|
|
@@ -127,7 +123,7 @@ if uploaded_files:
|
|
| 127 |
|
| 128 |
with image_col:
|
| 129 |
st.subheader("Processed Image")
|
| 130 |
-
if st.session_state
|
| 131 |
st.image(st.session_state.processed_img, use_column_width=True, caption="Processed Image")
|
| 132 |
else:
|
| 133 |
st.image(img, use_column_width=True, caption="Processed Image")
|
|
@@ -143,9 +139,10 @@ if uploaded_files:
|
|
| 143 |
brightness = st.slider("Brightness", 0.0, 5.0, 1.0)
|
| 144 |
sharpness = st.slider("Sharpness", 0.0, 2.0, 1.0)
|
| 145 |
|
| 146 |
-
|
| 147 |
-
|
| 148 |
-
|
|
|
|
| 149 |
processed_img = apply_enhancements(img, x, y, zoom, contrast, brightness, sharpness)
|
| 150 |
st.session_state.processed_img = processed_img
|
| 151 |
|
|
@@ -155,18 +152,16 @@ if uploaded_files:
|
|
| 155 |
|
| 156 |
# Save Options
|
| 157 |
save_image = st.checkbox("Save Processed Image")
|
| 158 |
-
if save_image
|
| 159 |
-
|
| 160 |
-
st.
|
| 161 |
-
st.success(f"Image saved as `{processed_image_path}`")
|
| 162 |
|
| 163 |
with st.expander("Save Options"):
|
| 164 |
description = st.text_area("Describe the image", "")
|
| 165 |
if st.button("Save Description"):
|
| 166 |
-
|
| 167 |
-
with open(desc_path, "w") as f:
|
| 168 |
f.write(description)
|
| 169 |
-
st.success(
|
| 170 |
|
| 171 |
if st.button("Save Image Parameters"):
|
| 172 |
params = {
|
|
@@ -177,18 +172,13 @@ if uploaded_files:
|
|
| 177 |
"brightness": brightness,
|
| 178 |
"sharpness": sharpness
|
| 179 |
}
|
| 180 |
-
|
| 181 |
-
with open(params_path, "w") as f:
|
| 182 |
f.write(pd.DataFrame([params]).to_json(orient="records"))
|
| 183 |
-
st.success(
|
| 184 |
|
| 185 |
if st.button("Rename Files"):
|
| 186 |
file_ext = str(np.random.randint(100))
|
| 187 |
-
|
| 188 |
-
|
| 189 |
-
|
| 190 |
-
new_params_name = f"saved_image_parameters{file_ext}.json"
|
| 191 |
-
new_desc_name = f"saved_image_description{file_ext}.txt"
|
| 192 |
-
os.rename("saved_image_parameters.json", new_params_name)
|
| 193 |
-
os.rename("saved_image_description.txt", new_desc_name)
|
| 194 |
st.success("Files renamed successfully")
|
|
|
|
| 95 |
enhanced_sharpness = ImageEnhance.Sharpness(enhanced_brightness).enhance(sharpness)
|
| 96 |
return enhanced_sharpness
|
| 97 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 98 |
st.set_page_config(page_title="CLL Explorer", layout="wide")
|
| 99 |
st.title("CLL Explorer: Cell Image Analysis Prep Tool")
|
| 100 |
|
|
|
|
| 123 |
|
| 124 |
with image_col:
|
| 125 |
st.subheader("Processed Image")
|
| 126 |
+
if 'processed_img' in st.session_state:
|
| 127 |
st.image(st.session_state.processed_img, use_column_width=True, caption="Processed Image")
|
| 128 |
else:
|
| 129 |
st.image(img, use_column_width=True, caption="Processed Image")
|
|
|
|
| 139 |
brightness = st.slider("Brightness", 0.0, 5.0, 1.0)
|
| 140 |
sharpness = st.slider("Sharpness", 0.0, 2.0, 1.0)
|
| 141 |
|
| 142 |
+
if st.button("Apply Adjustments"):
|
| 143 |
+
processed_img = apply_enhancements(img, x, y, zoom, contrast, brightness, sharpness)
|
| 144 |
+
st.session_state.processed_img = processed_img
|
| 145 |
+
else:
|
| 146 |
processed_img = apply_enhancements(img, x, y, zoom, contrast, brightness, sharpness)
|
| 147 |
st.session_state.processed_img = processed_img
|
| 148 |
|
|
|
|
| 152 |
|
| 153 |
# Save Options
|
| 154 |
save_image = st.checkbox("Save Processed Image")
|
| 155 |
+
if save_image:
|
| 156 |
+
st.session_state.processed_img.save("image-processed.jpg")
|
| 157 |
+
st.success("Image saved as `image-processed.jpg`")
|
|
|
|
| 158 |
|
| 159 |
with st.expander("Save Options"):
|
| 160 |
description = st.text_area("Describe the image", "")
|
| 161 |
if st.button("Save Description"):
|
| 162 |
+
with open("saved_image_description.txt", "w") as f:
|
|
|
|
| 163 |
f.write(description)
|
| 164 |
+
st.success("Description saved as `saved_image_description.txt`")
|
| 165 |
|
| 166 |
if st.button("Save Image Parameters"):
|
| 167 |
params = {
|
|
|
|
| 172 |
"brightness": brightness,
|
| 173 |
"sharpness": sharpness
|
| 174 |
}
|
| 175 |
+
with open("saved_image_parameters.json", "w") as f:
|
|
|
|
| 176 |
f.write(pd.DataFrame([params]).to_json(orient="records"))
|
| 177 |
+
st.success("Image parameters saved as `saved_image_parameters.json`")
|
| 178 |
|
| 179 |
if st.button("Rename Files"):
|
| 180 |
file_ext = str(np.random.randint(100))
|
| 181 |
+
os.rename("image-processed.jpg", f"img_processed{file_ext}.jpg")
|
| 182 |
+
os.rename("saved_image_parameters.json", f"saved_image_parameters{file_ext}.json")
|
| 183 |
+
os.rename("saved_image_description.txt", f"saved_image_description{file_ext}.txt")
|
|
|
|
|
|
|
|
|
|
|
|
|
| 184 |
st.success("Files renamed successfully")
|