@@ -38,6 +38,17 @@ def send(self, payload: dict[str, object]) -> None:
3838 self ._stream .flush ()
3939
4040
41+ def _configure_wangp_root () -> Path :
42+ """Make the pinned WanGP checkout importable from this copied script."""
43+ root = Path (os .environ .get ("WANGP_ROOT" , "/opt/Wan2GP" )).resolve ()
44+ if not (root / "shared" ).is_dir ():
45+ raise FileNotFoundError (f"WanGP checkout is missing its shared package: { root } " )
46+ root_text = str (root )
47+ if root_text not in sys .path :
48+ sys .path .insert (0 , root_text )
49+ return root
50+
51+
4152def _model_files (runtime : Any , model_type : str ) -> list [tuple [str , int , int ]]:
4253 """Mirror WanGP's own pre-load selection, stopping before model loading."""
4354 module = runtime .module
@@ -135,6 +146,7 @@ def _prepare(runtime: Any, model_type: str) -> None:
135146def main () -> int :
136147 emitter = _Emitter ()
137148 request = _read_request ()
149+ wangp_root = _configure_wangp_root ()
138150 model_type = str (request .get ("model_type" ) or "" ).strip ()
139151 if not model_type :
140152 raise ValueError ("model_type is required" )
@@ -188,7 +200,7 @@ def observe() -> None:
188200 from shared .api import init
189201
190202 session = init (
191- root = os . environ . get ( "WANGP_ROOT" , "/opt/Wan2GP" ),
203+ root = str ( wangp_root ),
192204 config_path = os .environ .get ("WANGP_CONFIG_PATH" ),
193205 output_dir = os .environ .get ("WANGP_OUTPUT_DIR" ),
194206 console_output = True ,
0 commit comments