Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -10,7 +10,7 @@ import numpy as np
|
|
10 |
from PIL import Image
|
11 |
import torch
|
12 |
from huggingface_hub import hf_hub_download
|
13 |
-
|
14 |
sys.path.append('Utils')
|
15 |
sys.path.append('model')
|
16 |
from model.CBAM.reunet_cbam import reunet_cbam
|
@@ -20,7 +20,19 @@ from Utils.area import pixel_to_sqft, process_and_overlay_image
|
|
20 |
from Utils.convert import read_pansharpened_rgb
|
21 |
|
22 |
|
23 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
24 |
|
25 |
@st.cache_resource
|
26 |
def load_model():
|
@@ -32,8 +44,7 @@ def load_model():
|
|
32 |
|
33 |
|
34 |
|
35 |
-
|
36 |
-
REPO_TYPE = "space"
|
37 |
|
38 |
# save to dir func
|
39 |
def save_to_hf_repo(local_path, repo_path):
|
@@ -202,9 +213,14 @@ def upload_page():
|
|
202 |
|
203 |
|
204 |
#st.success(f"Image saved to {filepath}")
|
205 |
-
|
206 |
# Save image to Hugging Face repo----------------------------------------------------------------------------------------------------------------------------------
|
207 |
-
|
|
|
|
|
|
|
|
|
|
|
208 |
|
209 |
# Check if the uploaded file is a GeoTIFF
|
210 |
if file_extension in ['.tiff', '.tif']:
|
@@ -244,8 +260,13 @@ def upload_page():
|
|
244 |
st.session_state.mask_filename = mask_filename
|
245 |
|
246 |
# Save mask to Hugging Face repo---------------------------------------------------------------------------------------------
|
247 |
-
mask
|
248 |
-
|
|
|
|
|
|
|
|
|
|
|
249 |
|
250 |
# Log image details
|
251 |
log_image_details(timestamp, converted_filename, mask_filename)
|
|
|
10 |
from PIL import Image
|
11 |
import torch
|
12 |
from huggingface_hub import hf_hub_download
|
13 |
+
|
14 |
sys.path.append('Utils')
|
15 |
sys.path.append('model')
|
16 |
from model.CBAM.reunet_cbam import reunet_cbam
|
|
|
20 |
from Utils.convert import read_pansharpened_rgb
|
21 |
|
22 |
|
23 |
+
from huggingface_hub import HfApi, login
|
24 |
+
import os
|
25 |
+
|
26 |
+
# Set up Hugging Face authentication
|
27 |
+
HF_TOKEN = os.environ.get("HF_TOKEN")
|
28 |
+
if not HF_TOKEN:
|
29 |
+
raise ValueError("HF_TOKEN environment variable is not set")
|
30 |
+
|
31 |
+
login(token=HF_TOKEN)
|
32 |
+
hf_api = HfApi()
|
33 |
+
|
34 |
+
REPO_ID = "Pavan2k4/Building_area"
|
35 |
+
REPO_TYPE = "space"
|
36 |
|
37 |
@st.cache_resource
|
38 |
def load_model():
|
|
|
44 |
|
45 |
|
46 |
|
47 |
+
|
|
|
48 |
|
49 |
# save to dir func
|
50 |
def save_to_hf_repo(local_path, repo_path):
|
|
|
213 |
|
214 |
|
215 |
#st.success(f"Image saved to {filepath}")
|
216 |
+
|
217 |
# Save image to Hugging Face repo----------------------------------------------------------------------------------------------------------------------------------
|
218 |
+
# Save image to Hugging Face repo
|
219 |
+
try:
|
220 |
+
image_repo_path = f"images/{converted_filename}"
|
221 |
+
save_to_hf_repo(converted_filepath, image_repo_path)
|
222 |
+
except Exception as e:
|
223 |
+
st.error(f"Error saving image to Hugging Face repo: {str(e)}")
|
224 |
|
225 |
# Check if the uploaded file is a GeoTIFF
|
226 |
if file_extension in ['.tiff', '.tif']:
|
|
|
260 |
st.session_state.mask_filename = mask_filename
|
261 |
|
262 |
# Save mask to Hugging Face repo---------------------------------------------------------------------------------------------
|
263 |
+
# Save mask to Hugging Face repo
|
264 |
+
try:
|
265 |
+
mask_repo_path = f"masks/{mask_filename}"
|
266 |
+
save_to_hf_repo(mask_filepath, mask_repo_path)
|
267 |
+
except Exception as e:
|
268 |
+
st.error(f"Error saving mask to Hugging Face repo: {str(e)}")
|
269 |
+
|
270 |
|
271 |
# Log image details
|
272 |
log_image_details(timestamp, converted_filename, mask_filename)
|