Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -15,39 +15,39 @@ from typing import List, Tuple, Optional
|
|
| 15 |
|
| 16 |
# ------------------ 安装SAM2依赖 ------------------
|
| 17 |
def install_sam2():
|
| 18 |
-
"""
|
| 19 |
sam2_dir = "third_party/sam2"
|
| 20 |
-
checkpoints_dir = os.path.join(sam2_dir, "checkpoints")
|
| 21 |
-
|
| 22 |
-
# 创建目录
|
| 23 |
-
os.makedirs(checkpoints_dir, exist_ok=True)
|
| 24 |
-
|
| 25 |
-
# 克隆仓库(如果不存在)
|
| 26 |
if not os.path.exists(sam2_dir):
|
| 27 |
-
print("
|
|
|
|
|
|
|
|
|
|
| 28 |
subprocess.run(["git", "clone", "https://github.com/facebookresearch/sam2.git", sam2_dir], check=True)
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
|
| 36 |
-
|
| 37 |
-
|
| 38 |
-
|
| 39 |
-
|
| 40 |
-
|
| 41 |
-
|
| 42 |
-
|
| 43 |
-
|
| 44 |
-
|
| 45 |
-
|
| 46 |
-
|
| 47 |
-
|
| 48 |
-
|
| 49 |
-
|
| 50 |
-
|
|
|
|
|
|
|
|
|
|
| 51 |
|
| 52 |
# 确保安装SAM2
|
| 53 |
install_sam2()
|
|
|
|
| 15 |
|
| 16 |
# ------------------ 安装SAM2依赖 ------------------
|
| 17 |
def install_sam2():
|
| 18 |
+
"""检查并安装SAM2及其依赖"""
|
| 19 |
sam2_dir = "third_party/sam2"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 20 |
if not os.path.exists(sam2_dir):
|
| 21 |
+
print("Installing SAM2...")
|
| 22 |
+
os.makedirs("third_party", exist_ok=True)
|
| 23 |
+
|
| 24 |
+
# 克隆仓库
|
| 25 |
subprocess.run(["git", "clone", "https://github.com/facebookresearch/sam2.git", sam2_dir], check=True)
|
| 26 |
+
|
| 27 |
+
# 切换到sam2目录安装
|
| 28 |
+
original_dir = os.getcwd()
|
| 29 |
+
try:
|
| 30 |
+
os.chdir(sam2_dir)
|
| 31 |
+
|
| 32 |
+
# 安装依赖
|
| 33 |
+
subprocess.run(["pip", "install", "-e", "."], check=True)
|
| 34 |
+
|
| 35 |
+
# 切换到checkpoints目录下载模型
|
| 36 |
+
os.chdir("checkpoints")
|
| 37 |
+
if not os.path.exists("download_ckpts.sh"):
|
| 38 |
+
# 如果脚本不存在,可能是权限问题,尝试直接下载
|
| 39 |
+
subprocess.run(["wget", "https://raw.githubusercontent.com/facebookresearch/sam2/main/checkpoints/download_ckpts.sh"], check=True)
|
| 40 |
+
subprocess.run(["chmod", "+x", "download_ckpts.sh"], check=True)
|
| 41 |
+
|
| 42 |
+
subprocess.run(["./download_ckpts.sh"], check=True)
|
| 43 |
+
|
| 44 |
+
finally:
|
| 45 |
+
# 确保切换回原始目录
|
| 46 |
+
os.chdir(original_dir)
|
| 47 |
+
|
| 48 |
+
print("SAM2 installed successfully!")
|
| 49 |
+
else:
|
| 50 |
+
print("SAM2 already installed.")
|
| 51 |
|
| 52 |
# 确保安装SAM2
|
| 53 |
install_sam2()
|