Skier8402 commited on
Commit
fc4f887
·
verified ·
1 Parent(s): eefdadb

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +25 -16
app.py CHANGED
@@ -95,6 +95,10 @@ 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
  st.set_page_config(page_title="CLL Explorer", layout="wide")
99
  st.title("CLL Explorer: Cell Image Analysis Prep Tool")
100
 
@@ -123,7 +127,7 @@ if uploaded_files:
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,11 +143,9 @@ if uploaded_files:
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
- st.experimental_rerun()
146
- else:
147
  processed_img = apply_enhancements(img, x, y, zoom, contrast, brightness, sharpness)
148
  st.session_state.processed_img = processed_img
149
 
@@ -153,16 +155,18 @@ if uploaded_files:
153
 
154
  # Save Options
155
  save_image = st.checkbox("Save Processed Image")
156
- if save_image:
157
- st.session_state.processed_img.save("image-processed.jpg")
158
- st.success("Image saved as `image-processed.jpg`")
 
159
 
160
  with st.expander("Save Options"):
161
  description = st.text_area("Describe the image", "")
162
  if st.button("Save Description"):
163
- with open("saved_image_description.txt", "w") as f:
 
164
  f.write(description)
165
- st.success("Description saved as `saved_image_description.txt`")
166
 
167
  if st.button("Save Image Parameters"):
168
  params = {
@@ -173,13 +177,18 @@ if uploaded_files:
173
  "brightness": brightness,
174
  "sharpness": sharpness
175
  }
176
- with open("saved_image_parameters.json", "w") as f:
 
177
  f.write(pd.DataFrame([params]).to_json(orient="records"))
178
- st.success("Image parameters saved as `saved_image_parameters.json`")
179
 
180
  if st.button("Rename Files"):
181
  file_ext = str(np.random.randint(100))
182
- os.rename("image-processed.jpg", f"img_processed{file_ext}.jpg")
183
- os.rename("saved_image_parameters.json", f"saved_image_parameters{file_ext}.json")
184
- os.rename("saved_image_description.txt", f"saved_image_description{file_ext}.txt")
 
 
 
 
185
  st.success("Files renamed successfully")
 
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
 
128
  with image_col:
129
  st.subheader("Processed Image")
130
+ if st.session_state.processed_img:
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
  brightness = st.slider("Brightness", 0.0, 5.0, 1.0)
144
  sharpness = st.slider("Sharpness", 0.0, 2.0, 1.0)
145
 
146
+ apply_button = st.button("Apply Adjustments")
147
+
148
+ if apply_button:
 
 
149
  processed_img = apply_enhancements(img, x, y, zoom, contrast, brightness, sharpness)
150
  st.session_state.processed_img = processed_img
151
 
 
155
 
156
  # Save Options
157
  save_image = st.checkbox("Save Processed Image")
158
+ if save_image and st.session_state.processed_img:
159
+ processed_image_path = "image-processed.jpg"
160
+ st.session_state.processed_img.save(processed_image_path)
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
+ desc_path = "saved_image_description.txt"
167
+ with open(desc_path, "w") as f:
168
  f.write(description)
169
+ st.success(f"Description saved as `{desc_path}`")
170
 
171
  if st.button("Save Image Parameters"):
172
  params = {
 
177
  "brightness": brightness,
178
  "sharpness": sharpness
179
  }
180
+ params_path = "saved_image_parameters.json"
181
+ with open(params_path, "w") as f:
182
  f.write(pd.DataFrame([params]).to_json(orient="records"))
183
+ st.success(f"Image parameters saved as `{params_path}`")
184
 
185
  if st.button("Rename Files"):
186
  file_ext = str(np.random.randint(100))
187
+ if st.session_state.processed_img:
188
+ new_image_name = f"img_processed{file_ext}.jpg"
189
+ os.rename("image-processed.jpg", new_image_name)
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")