KevinX-Penn28 commited on
Commit
b0da3be
·
verified ·
1 Parent(s): b428ba7

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +55 -54
app.py CHANGED
@@ -10,53 +10,54 @@ from huggingface_hub import snapshot_download
10
  import sys, pathlib
11
  import os
12
  os.environ["OPENAI_API_KEY"] = "test"
13
-
14
- # 1) Download the repo to a local cache dir
15
- print("Downloading remote vine repo...")
16
- repo_dir = snapshot_download(repo_id="KevinX-Penn28/testing", revision="main")
17
-
18
- # 2) Register the snapshot as an importable package
19
- VINE_PACKAGE = "vine_remote_repo"
20
-
21
- # Drop stale modules in case the script reloads
22
- for module_name in list(sys.modules):
23
- if module_name == VINE_PACKAGE or module_name.startswith(f"{VINE_PACKAGE}."):
24
- del sys.modules[module_name]
25
-
26
- print("Dropped stale modules and registering vine package...")
27
-
28
- package_spec = importlib.util.spec_from_file_location(
29
- VINE_PACKAGE,
30
- Path(repo_dir) / "__init__.py",
31
- submodule_search_locations=[str(repo_dir)],
32
- )
33
- if not package_spec or not package_spec.loader:
34
- raise ImportError(f"Cannot create package spec for {VINE_PACKAGE} at {repo_dir}")
35
-
36
- print("Created package spec, loading module...")
37
-
38
- package_module = importlib.util.module_from_spec(package_spec)
39
- sys.modules[VINE_PACKAGE] = package_module
40
-
41
- try:
42
- print("Executing module...")
43
- package_spec.loader.exec_module(package_module)
44
- print("Module executed successfully!")
45
- except Exception as e:
46
- print(f"ERROR during module execution: {e}")
47
- import traceback
48
- traceback.print_exc()
49
- raise
50
-
51
- # 3) Import and use via the registered package
52
- print("Importing vine modules...")
53
- vine_config_module = importlib.import_module(f"{VINE_PACKAGE}.vine_config")
54
- vine_model_module = importlib.import_module(f"{VINE_PACKAGE}.vine_model")
55
- vine_pipeline_module = importlib.import_module(f"{VINE_PACKAGE}.vine_pipeline")
56
-
57
- VineConfig = vine_config_module.VineConfig # your config class
58
- VineModel = vine_model_module.VineModel # your model class
59
- VinePipeline = vine_pipeline_module.VinePipeline
 
60
 
61
  current_dir = Path(__file__).resolve().parent
62
  sam_config_path = "/" + str(Path(current_dir) / "sam2_hiera_t.yaml")
@@ -65,14 +66,14 @@ gd_config_path = "/" + str(Path(current_dir) / "GroundingDINO_SwinT_OGC.py")
65
  gd_checkpoint_path = "/" + str(Path(current_dir) / "groundingdino_swint_ogc.pth")
66
  visualization_dir = "/" + str(Path(current_dir) / "outputs")
67
 
68
- # current_dir = Path.cwd()
69
- # sam_config_path = "/" + str(current_dir / "sam2_hiera_t.yaml")
70
- # sam_checkpoint_path = "/" + str(current_dir / "sam2_hiera_tiny.pt")
71
- # gd_config_path = "/" + str(current_dir / "GroundingDINO_SwinT_OGC.py")
72
- # gd_checkpoint_path = "/" + str(current_dir / "groundingdino_swint_ogc.pth")
73
- # visualization_dir = "/" + str(current_dir / "outputs")
74
 
75
- print(f"Setting up paths done: {sam_config_path}, {sam_checkpoint_path}, {gd_config_path}, {gd_checkpoint_path}")
76
 
77
  def process_video(video_file, categorical_keywords, unary_keywords, binary_keywords, object_pairs, output_fps):
78
 
 
10
  import sys, pathlib
11
  import os
12
  os.environ["OPENAI_API_KEY"] = "test"
13
+ from vine_hf import VineConfig, VineModel, VinePipeline
14
+
15
+ # # 1) Download the repo to a local cache dir
16
+ # print("Downloading remote vine repo...")
17
+ # repo_dir = snapshot_download(repo_id="KevinX-Penn28/testing", revision="main")
18
+
19
+ # # 2) Register the snapshot as an importable package
20
+ # VINE_PACKAGE = "vine_remote_repo"
21
+
22
+ # # Drop stale modules in case the script reloads
23
+ # for module_name in list(sys.modules):
24
+ # if module_name == VINE_PACKAGE or module_name.startswith(f"{VINE_PACKAGE}."):
25
+ # del sys.modules[module_name]
26
+
27
+ # print("Dropped stale modules and registering vine package...")
28
+
29
+ # package_spec = importlib.util.spec_from_file_location(
30
+ # VINE_PACKAGE,
31
+ # Path(repo_dir) / "__init__.py",
32
+ # submodule_search_locations=[str(repo_dir)],
33
+ # )
34
+ # if not package_spec or not package_spec.loader:
35
+ # raise ImportError(f"Cannot create package spec for {VINE_PACKAGE} at {repo_dir}")
36
+
37
+ # print("Created package spec, loading module...")
38
+
39
+ # package_module = importlib.util.module_from_spec(package_spec)
40
+ # sys.modules[VINE_PACKAGE] = package_module
41
+
42
+ # try:
43
+ # print("Executing module...")
44
+ # package_spec.loader.exec_module(package_module)
45
+ # print("Module executed successfully!")
46
+ # except Exception as e:
47
+ # print(f"ERROR during module execution: {e}")
48
+ # import traceback
49
+ # traceback.print_exc()
50
+ # raise
51
+
52
+ # # 3) Import and use via the registered package
53
+ # print("Importing vine modules...")
54
+ # vine_config_module = importlib.import_module(f"{VINE_PACKAGE}.vine_config")
55
+ # vine_model_module = importlib.import_module(f"{VINE_PACKAGE}.vine_model")
56
+ # vine_pipeline_module = importlib.import_module(f"{VINE_PACKAGE}.vine_pipeline")
57
+
58
+ # VineConfig = vine_config_module.VineConfig # your config class
59
+ # VineModel = vine_model_module.VineModel # your model class
60
+ # VinePipeline = vine_pipeline_module.VinePipeline
61
 
62
  current_dir = Path(__file__).resolve().parent
63
  sam_config_path = "/" + str(Path(current_dir) / "sam2_hiera_t.yaml")
 
66
  gd_checkpoint_path = "/" + str(Path(current_dir) / "groundingdino_swint_ogc.pth")
67
  visualization_dir = "/" + str(Path(current_dir) / "outputs")
68
 
69
+ # # current_dir = Path.cwd()
70
+ # # sam_config_path = "/" + str(current_dir / "sam2_hiera_t.yaml")
71
+ # # sam_checkpoint_path = "/" + str(current_dir / "sam2_hiera_tiny.pt")
72
+ # # gd_config_path = "/" + str(current_dir / "GroundingDINO_SwinT_OGC.py")
73
+ # # gd_checkpoint_path = "/" + str(current_dir / "groundingdino_swint_ogc.pth")
74
+ # # visualization_dir = "/" + str(current_dir / "outputs")
75
 
76
+ # print(f"Setting up paths done: {sam_config_path}, {sam_checkpoint_path}, {gd_config_path}, {gd_checkpoint_path}")
77
 
78
  def process_video(video_file, categorical_keywords, unary_keywords, binary_keywords, object_pairs, output_fps):
79