Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -177,6 +177,9 @@ def upload_page():
|
|
177 |
|
178 |
st.success(f"Image saved to {filepath}")
|
179 |
|
|
|
|
|
|
|
180 |
# Check if the uploaded file is a GeoTIFF
|
181 |
if file_extension in ['.tiff', '.tif']:
|
182 |
st.info('Processing GeoTIFF image...')
|
@@ -193,29 +196,35 @@ def upload_page():
|
|
193 |
# Store the full path of the converted image
|
194 |
st.session_state.filename = converted_filename
|
195 |
|
196 |
-
#
|
197 |
-
|
198 |
-
|
199 |
-
|
200 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
201 |
# Save the full mask
|
202 |
mask_filename = f"mask_{timestamp}.png"
|
203 |
mask_filepath = os.path.join(MASK_DIR, mask_filename)
|
204 |
cv2.imwrite(mask_filepath, full_mask)
|
205 |
st.session_state.mask_filename = mask_filename
|
206 |
|
207 |
-
|
|
|
208 |
|
209 |
# Log image details
|
210 |
log_image_details(timestamp, converted_filename, mask_filename)
|
211 |
|
212 |
st.session_state.file_uploaded = True
|
213 |
-
|
214 |
-
# Clean up temporary patch files
|
215 |
-
st.info('Cleaning up temporary files...')
|
216 |
-
for file in os.listdir(PRED_PATCHES_DIR):
|
217 |
-
os.remove(os.path.join(PRED_PATCHES_DIR, file))
|
218 |
-
st.success('Temporary files cleaned up')
|
219 |
|
220 |
except Exception as e:
|
221 |
st.error(f"An error occurred: {str(e)}")
|
|
|
177 |
|
178 |
st.success(f"Image saved to {filepath}")
|
179 |
|
180 |
+
# Save image to Hugging Face repo
|
181 |
+
save_to_hf_repo(filepath, f'uploaded_images/{filename}')
|
182 |
+
|
183 |
# Check if the uploaded file is a GeoTIFF
|
184 |
if file_extension in ['.tiff', '.tif']:
|
185 |
st.info('Processing GeoTIFF image...')
|
|
|
196 |
# Store the full path of the converted image
|
197 |
st.session_state.filename = converted_filename
|
198 |
|
199 |
+
# Convert image to numpy array
|
200 |
+
img_array = np.array(img)
|
201 |
+
|
202 |
+
# Check if image shape is more than 650x650
|
203 |
+
if img_array.shape[0] > 650 or img_array.shape[1] > 650:
|
204 |
+
st.info('Large image detected. Using patch-based processing.')
|
205 |
+
with st.spinner('Analyzing large image...'):
|
206 |
+
full_mask = process_large_image(model, converted_filepath)
|
207 |
+
else:
|
208 |
+
st.info('Small image detected. Processing whole image at once.')
|
209 |
+
with st.spinner('Analyzing image...'):
|
210 |
+
img_transformed = transforms(img)
|
211 |
+
prediction = predict(img_transformed)
|
212 |
+
full_mask = (prediction > 0.5).astype(np.uint8) * 255
|
213 |
+
|
214 |
# Save the full mask
|
215 |
mask_filename = f"mask_{timestamp}.png"
|
216 |
mask_filepath = os.path.join(MASK_DIR, mask_filename)
|
217 |
cv2.imwrite(mask_filepath, full_mask)
|
218 |
st.session_state.mask_filename = mask_filename
|
219 |
|
220 |
+
# Save mask to Hugging Face repo
|
221 |
+
save_to_hf_repo(mask_filepath, f'generated_masks/{mask_filename}')
|
222 |
|
223 |
# Log image details
|
224 |
log_image_details(timestamp, converted_filename, mask_filename)
|
225 |
|
226 |
st.session_state.file_uploaded = True
|
227 |
+
st.success("Image processed successfully")
|
|
|
|
|
|
|
|
|
|
|
228 |
|
229 |
except Exception as e:
|
230 |
st.error(f"An error occurred: {str(e)}")
|