Update app.py
Browse files
app.py
CHANGED
@@ -7,8 +7,12 @@ from part2_visualization import VisualizationHandler
|
|
7 |
from part3 import SAMAnalyzer
|
8 |
import time
|
9 |
|
10 |
-
|
|
|
11 |
def download_with_progress(url, filename):
|
|
|
|
|
|
|
12 |
print(f"Downloading {filename}...")
|
13 |
start_time = time.time()
|
14 |
urllib.request.urlretrieve(url, filename)
|
@@ -16,11 +20,11 @@ def download_with_progress(url, filename):
|
|
16 |
print(f"Download completed in {end_time - start_time:.2f} seconds")
|
17 |
|
18 |
# Download SAM model if it doesn't exist
|
19 |
-
if not os.path.exists(
|
20 |
try:
|
21 |
download_with_progress(
|
22 |
'https://dl.fbaipublicfiles.com/segment_anything/sam_vit_h_4b8939.pth',
|
23 |
-
|
24 |
)
|
25 |
except Exception as e:
|
26 |
print(f"Error downloading SAM model: {e}")
|
|
|
7 |
from part3 import SAMAnalyzer
|
8 |
import time
|
9 |
|
10 |
+
MODEL_PATH = 'sam_vit_h_4b8939.pth'
|
11 |
+
|
12 |
def download_with_progress(url, filename):
|
13 |
+
if os.path.exists(filename):
|
14 |
+
print(f"Model already exists at {filename}")
|
15 |
+
return
|
16 |
print(f"Downloading {filename}...")
|
17 |
start_time = time.time()
|
18 |
urllib.request.urlretrieve(url, filename)
|
|
|
20 |
print(f"Download completed in {end_time - start_time:.2f} seconds")
|
21 |
|
22 |
# Download SAM model if it doesn't exist
|
23 |
+
if not os.path.exists(MODEL_PATH):
|
24 |
try:
|
25 |
download_with_progress(
|
26 |
'https://dl.fbaipublicfiles.com/segment_anything/sam_vit_h_4b8939.pth',
|
27 |
+
MODEL_PATH
|
28 |
)
|
29 |
except Exception as e:
|
30 |
print(f"Error downloading SAM model: {e}")
|