Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -34,15 +34,12 @@ if not HF_TOKEN:
|
|
34 |
REPO_ID = "Pavan2k4/Building_area"
|
35 |
REPO_TYPE = "space"
|
36 |
|
37 |
-
# Define base directory for Hugging Face Spaces
|
38 |
-
BASE_DIR = "DATA/"
|
39 |
-
|
40 |
# Define subdirectories
|
41 |
-
UPLOAD_DIR =
|
42 |
-
MASK_DIR =
|
43 |
-
PATCHES_DIR =
|
44 |
-
PRED_PATCHES_DIR =
|
45 |
-
CSV_LOG_PATH =
|
46 |
|
47 |
|
48 |
def split(image, destination = PATCHES_DIR, patch_size = 650):
|
@@ -117,7 +114,6 @@ def save_to_hf_repo(local_path, repo_path):
|
|
117 |
repo_type=REPO_TYPE,
|
118 |
token=HF_TOKEN
|
119 |
)
|
120 |
-
st.success(f"File uploaded successfully to {repo_path}")
|
121 |
except Exception as e:
|
122 |
st.error(f"Error uploading file: {str(e)}")
|
123 |
st.error("Detailed error information:")
|
@@ -181,7 +177,7 @@ def upload_page():
|
|
181 |
with open(filepath, "wb") as f:
|
182 |
f.write(bytes_data)
|
183 |
|
184 |
-
st.success(
|
185 |
|
186 |
# Save image to Hugging Face repo
|
187 |
save_to_hf_repo(filepath, f'uploaded_images/{filename}')
|
@@ -191,13 +187,11 @@ def upload_page():
|
|
191 |
st.info('Processing GeoTIFF image...')
|
192 |
rgb_image = read_pansharpened_rgb(filepath)
|
193 |
cv2.imwrite(converted_filepath, cv2.cvtColor(rgb_image, cv2.COLOR_RGB2BGR))
|
194 |
-
st.success(f'GeoTIFF converted to 8-bit image and saved as {converted_filename}')
|
195 |
img = Image.open(converted_filepath)
|
196 |
else:
|
197 |
img = Image.open(filepath)
|
198 |
|
199 |
st.image(img, caption='Uploaded Image', use_column_width=True)
|
200 |
-
st.success(f'Image processed and saved as {converted_filename}')
|
201 |
|
202 |
# Store the full path of the converted image
|
203 |
st.session_state.filename = converted_filename
|
@@ -238,7 +232,6 @@ def upload_page():
|
|
238 |
shutil.rmtree(PRED_PATCHES_DIR)
|
239 |
os.makedirs(PATCHES_DIR) # Recreate empty folders
|
240 |
os.makedirs(PRED_PATCHES_DIR)
|
241 |
-
st.success('Temporary files cleaned up')
|
242 |
else:
|
243 |
# Predict on whole image
|
244 |
st.session_state.tr_img = transforms(img)
|
@@ -249,6 +242,8 @@ def upload_page():
|
|
249 |
Image.fromarray(mask).save(mask_filepath)
|
250 |
st.session_state.mask_filename = mask_filename
|
251 |
|
|
|
|
|
252 |
# Save mask to Hugging Face repo
|
253 |
mask_filepath = os.path.join(MASK_DIR, st.session_state.mask_filename)
|
254 |
save_to_hf_repo(mask_filepath, f'generated_masks/{st.session_state.mask_filename}')
|
|
|
34 |
REPO_ID = "Pavan2k4/Building_area"
|
35 |
REPO_TYPE = "space"
|
36 |
|
|
|
|
|
|
|
37 |
# Define subdirectories
|
38 |
+
UPLOAD_DIR = "uploaded_images"
|
39 |
+
MASK_DIR = "generated_masks"
|
40 |
+
PATCHES_DIR = "patches"
|
41 |
+
PRED_PATCHES_DIR = "pred_patches"
|
42 |
+
CSV_LOG_PATH = "image_log.csv"
|
43 |
|
44 |
|
45 |
def split(image, destination = PATCHES_DIR, patch_size = 650):
|
|
|
114 |
repo_type=REPO_TYPE,
|
115 |
token=HF_TOKEN
|
116 |
)
|
|
|
117 |
except Exception as e:
|
118 |
st.error(f"Error uploading file: {str(e)}")
|
119 |
st.error("Detailed error information:")
|
|
|
177 |
with open(filepath, "wb") as f:
|
178 |
f.write(bytes_data)
|
179 |
|
180 |
+
st.success('File uploaded and saved')
|
181 |
|
182 |
# Save image to Hugging Face repo
|
183 |
save_to_hf_repo(filepath, f'uploaded_images/{filename}')
|
|
|
187 |
st.info('Processing GeoTIFF image...')
|
188 |
rgb_image = read_pansharpened_rgb(filepath)
|
189 |
cv2.imwrite(converted_filepath, cv2.cvtColor(rgb_image, cv2.COLOR_RGB2BGR))
|
|
|
190 |
img = Image.open(converted_filepath)
|
191 |
else:
|
192 |
img = Image.open(filepath)
|
193 |
|
194 |
st.image(img, caption='Uploaded Image', use_column_width=True)
|
|
|
195 |
|
196 |
# Store the full path of the converted image
|
197 |
st.session_state.filename = converted_filename
|
|
|
232 |
shutil.rmtree(PRED_PATCHES_DIR)
|
233 |
os.makedirs(PATCHES_DIR) # Recreate empty folders
|
234 |
os.makedirs(PRED_PATCHES_DIR)
|
|
|
235 |
else:
|
236 |
# Predict on whole image
|
237 |
st.session_state.tr_img = transforms(img)
|
|
|
242 |
Image.fromarray(mask).save(mask_filepath)
|
243 |
st.session_state.mask_filename = mask_filename
|
244 |
|
245 |
+
st.success('Mask generated and saved')
|
246 |
+
|
247 |
# Save mask to Hugging Face repo
|
248 |
mask_filepath = os.path.join(MASK_DIR, st.session_state.mask_filename)
|
249 |
save_to_hf_repo(mask_filepath, f'generated_masks/{st.session_state.mask_filename}')
|