Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -16,14 +16,12 @@ import sys
|
|
| 16 |
|
| 17 |
|
| 18 |
def add_sam2_to_path():
|
| 19 |
-
"""将SAM2安装目录添加到Python路径"""
|
| 20 |
sam2_dir = os.path.abspath("third_party/sam2")
|
| 21 |
if sam2_dir not in sys.path:
|
| 22 |
sys.path.insert(0, sam2_dir)
|
| 23 |
return sam2_dir
|
| 24 |
|
| 25 |
def install_sam2():
|
| 26 |
-
"""检查并安装SAM2及其依赖"""
|
| 27 |
sam2_dir = "third_party/sam2"
|
| 28 |
if not os.path.exists(sam2_dir):
|
| 29 |
print("Installing SAM2...")
|
|
@@ -85,12 +83,8 @@ except Exception as e:
|
|
| 85 |
# SAM Wrapper
|
| 86 |
class CustomSAMWrapper:
|
| 87 |
def __init__(self, model_path: str, device: str = DEVICE):
|
| 88 |
-
try:
|
| 89 |
-
from sam2.build_sam import build_sam2
|
| 90 |
-
from sam2.sam2_image_predictor import SAM2ImagePredictor
|
| 91 |
-
|
| 92 |
self.device = torch.device(device)
|
| 93 |
-
# model_cfg = os.path.join("third_party/sam2", "configs/sam2.1/sam2.1_hiera_l.yaml")
|
| 94 |
sam_model = build_sam2("configs/sam2.1/sam2.1_hiera_l.yaml", model_path)
|
| 95 |
sam_model = sam_model.to(self.device)
|
| 96 |
self.predictor = SAM2ImagePredictor(sam_model)
|
|
@@ -317,8 +311,9 @@ def run_pipeline(image: PILImage.Image, prompt: str):
|
|
| 317 |
|
| 318 |
|
| 319 |
with gr.Blocks(title="Seg-R1") as demo:
|
| 320 |
-
gr.Markdown("# Seg-R1")
|
| 321 |
# gr.Markdown("Upload an image and ask questions about segmentation.")
|
|
|
|
| 322 |
|
| 323 |
with gr.Row():
|
| 324 |
with gr.Column():
|
|
|
|
| 16 |
|
| 17 |
|
| 18 |
def add_sam2_to_path():
|
|
|
|
| 19 |
sam2_dir = os.path.abspath("third_party/sam2")
|
| 20 |
if sam2_dir not in sys.path:
|
| 21 |
sys.path.insert(0, sam2_dir)
|
| 22 |
return sam2_dir
|
| 23 |
|
| 24 |
def install_sam2():
|
|
|
|
| 25 |
sam2_dir = "third_party/sam2"
|
| 26 |
if not os.path.exists(sam2_dir):
|
| 27 |
print("Installing SAM2...")
|
|
|
|
| 83 |
# SAM Wrapper
|
| 84 |
class CustomSAMWrapper:
|
| 85 |
def __init__(self, model_path: str, device: str = DEVICE):
|
| 86 |
+
try:
|
|
|
|
|
|
|
|
|
|
| 87 |
self.device = torch.device(device)
|
|
|
|
| 88 |
sam_model = build_sam2("configs/sam2.1/sam2.1_hiera_l.yaml", model_path)
|
| 89 |
sam_model = sam_model.to(self.device)
|
| 90 |
self.predictor = SAM2ImagePredictor(sam_model)
|
|
|
|
| 311 |
|
| 312 |
|
| 313 |
with gr.Blocks(title="Seg-R1") as demo:
|
| 314 |
+
# gr.Markdown("# Seg-R1")
|
| 315 |
# gr.Markdown("Upload an image and ask questions about segmentation.")
|
| 316 |
+
gr.HTML(load_description("assets/title.md"))
|
| 317 |
|
| 318 |
with gr.Row():
|
| 319 |
with gr.Column():
|