KevinX-Penn28 commited on
Commit
4a652b7
·
verified ·
1 Parent(s): dc83469

hanging changes

Browse files
Files changed (1) hide show
  1. app.py +31 -31
app.py CHANGED
@@ -13,48 +13,48 @@ import sys, pathlib
13
  import os
14
  os.environ["OPENAI_API_KEY"] = "test"
15
 
16
- # 1) Download the repo to a local cache dir
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
- package_spec = importlib.util.spec_from_file_location(
28
- VINE_PACKAGE,
29
- Path(repo_dir) / "__init__.py",
30
- submodule_search_locations=[str(repo_dir)],
31
- )
32
- if not package_spec or not package_spec.loader:
33
- raise ImportError(f"Cannot create package spec for {VINE_PACKAGE} at {repo_dir}")
 
 
 
 
 
 
 
 
 
 
34
 
35
- package_module = importlib.util.module_from_spec(package_spec)
36
- sys.modules[VINE_PACKAGE] = package_module
37
- package_spec.loader.exec_module(package_module)
38
 
39
- # 3) Import and use via the registered package
40
- vine_config_module = importlib.import_module(f"{VINE_PACKAGE}.vine_config")
41
- vine_model_module = importlib.import_module(f"{VINE_PACKAGE}.vine_model")
42
- vine_pipeline_module = importlib.import_module(f"{VINE_PACKAGE}.vine_pipeline")
43
 
44
- VineConfig = vine_config_module.VineConfig # your config class
45
- VineModel = vine_model_module.VineModel # your model class
46
- VinePipeline = vine_pipeline_module.VinePipeline
47
 
48
- current_dir = Path(__file__).parent
49
- sam_config_path = "//" + str(current_dir / "sam2_hiera_t.yaml")
50
- sam_checkpoint_path = "//" + str(current_dir / "sam2_hiera_tiny.pt")
51
- gd_config_path = "//" + str(current_dir / "GroundingDINO_SwinT_OGC.py")
52
- gd_checkpoint_path = "//" + str(current_dir / "groundingdino_swint_ogc.pth")
53
- visualization_dir = "//" + str(current_dir / "outputs")
54
 
55
  #@spaces.GPU(duration=200)
56
  def process_video(video_file, categorical_keywords, unary_keywords, binary_keywords, object_pairs, output_fps):
57
  log_buffer = io.StringIO()
 
58
  try:
59
  with contextlib.redirect_stdout(log_buffer), contextlib.redirect_stderr(log_buffer):
60
  categorical_keywords = [kw.strip() for kw in categorical_keywords.split(",")] if categorical_keywords else []
 
13
  import os
14
  os.environ["OPENAI_API_KEY"] = "test"
15
 
16
+ print("=== VINE SPACE DEBUG START ===")
 
17
 
18
+ os.environ.setdefault("OMP_NUM_THREADS", "1")
19
+ os.environ.setdefault("TOKENIZERS_PARALLELISM", "false")
20
 
21
+ print("Step 1: Loading Vine repo lazily...")
22
+ VineConfig = VineModel = VinePipeline = None
 
 
23
 
24
+ def load_vine():
25
+ global VineConfig, VineModel, VinePipeline
26
+ if VineModel is not None:
27
+ return VineConfig, VineModel, VinePipeline
28
+
29
+ print("Downloading repo...")
30
+ repo_dir = snapshot_download(repo_id="KevinX-Penn28/testing", revision="main")
31
+
32
+ print("Importing modules...")
33
+ package_spec = importlib.util.spec_from_file_location(
34
+ VINE_PACKAGE,
35
+ Path(repo_dir) / "__init__.py",
36
+ submodule_search_locations=[str(repo_dir)],
37
+ )
38
+ package_module = importlib.util.module_from_spec(package_spec)
39
+ sys.modules[VINE_PACKAGE] = package_module
40
+ package_spec.loader.exec_module(package_module)
41
 
42
+ vine_config_module = importlib.import_module(f"{VINE_PACKAGE}.vine_config")
43
+ vine_model_module = importlib.import_module(f"{VINE_PACKAGE}.vine_model")
44
+ vine_pipeline_module = importlib.import_module(f"{VINE_PACKAGE}.vine_pipeline")
45
 
46
+ VineConfig = vine_config_module.VineConfig
47
+ VineModel = vine_model_module.VineModel
48
+ VinePipeline = vine_pipeline_module.VinePipeline
 
49
 
50
+ print("Vine loaded")
51
+ return VineConfig, VineModel, VinePipeline
 
52
 
 
 
 
 
 
 
53
 
54
  #@spaces.GPU(duration=200)
55
  def process_video(video_file, categorical_keywords, unary_keywords, binary_keywords, object_pairs, output_fps):
56
  log_buffer = io.StringIO()
57
+ VineConfig, VineModel, VinePipeline = load_vine()
58
  try:
59
  with contextlib.redirect_stdout(log_buffer), contextlib.redirect_stderr(log_buffer):
60
  categorical_keywords = [kw.strip() for kw in categorical_keywords.split(",")] if categorical_keywords else []