Update api/seedvr_server.py
Browse files- api/seedvr_server.py +27 -20
api/seedvr_server.py
CHANGED
|
@@ -63,38 +63,42 @@ class SeedVRServer:
|
|
| 63 |
shutil.copy2(input_file, job_input_dir / Path(input_file).name)
|
| 64 |
return job_input_dir, out_dir
|
| 65 |
|
| 66 |
-
def run_inference(self,
|
| 67 |
script = self.SEEDVR_ROOT / "inference_cli.py"
|
| 68 |
-
job_input_dir,
|
| 69 |
-
|
| 70 |
-
|
| 71 |
-
|
|
|
|
| 72 |
effective_nproc = 1 if is_image else self.NUM_GPUS_TOTAL
|
| 73 |
-
|
| 74 |
-
|
| 75 |
-
output_filename = f"result_{Path(filepath).stem}.mp4" if not is_image else f"{Path(filepath).stem}_upscaled"
|
| 76 |
-
output_filepath = outdir / output_filename
|
| 77 |
|
| 78 |
|
|
|
|
|
|
|
|
|
|
| 79 |
|
| 80 |
cmd = [
|
| 81 |
-
"torchrun", "--standalone", "--nnodes=1",
|
| 82 |
-
|
| 83 |
-
str(script),
|
| 84 |
-
"--video_path", str(filepath),
|
| 85 |
"--output", str(output_filepath),
|
| 86 |
"--model_dir", str(self.CKPTS_ROOT),
|
| 87 |
"--seed", str(seed),
|
| 88 |
-
"--cuda_device", "0,1,2,3
|
| 89 |
-
"--resolution", str(
|
| 90 |
-
"--batch_size", str(
|
| 91 |
"--model", "seedvr2_ema_3b_fp16.safetensors",
|
| 92 |
-
"--preserve_vram",
|
| 93 |
"--debug",
|
| 94 |
-
"--output_format", "video"
|
| 95 |
]
|
| 96 |
-
|
| 97 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 98 |
print("SeedVRServer Comando:", " ".join(cmd))
|
| 99 |
try:
|
| 100 |
subprocess.run(cmd, cwd=str(self.SEEDVR_ROOT), check=True, env=os.environ.copy(), stdout=sys.stdout, stderr=sys.stderr)
|
|
@@ -109,3 +113,6 @@ class SeedVRServer:
|
|
| 109 |
except Exception as e:
|
| 110 |
print(f"[UI ERROR] A inferência falhou: {e}")
|
| 111 |
return None, None, None
|
|
|
|
|
|
|
|
|
|
|
|
| 63 |
shutil.copy2(input_file, job_input_dir / Path(input_file).name)
|
| 64 |
return job_input_dir, out_dir
|
| 65 |
|
| 66 |
+
def run_inference(self, file_path: str, *, seed: int, res_h: int, res_w: int, sp_size: int, fps: Optional[float] = None) -> Tuple[Optional[str], Optional[str], Path]:
|
| 67 |
script = self.SEEDVR_ROOT / "inference_cli.py"
|
| 68 |
+
job_input_dir, out_dir = self._prepare_job(file_path)
|
| 69 |
+
|
| 70 |
+
media_type, _ = mimetypes.guess_type(file_path)
|
| 71 |
+
is_image = media_type and media_type.startswith("image")
|
| 72 |
+
|
| 73 |
effective_nproc = 1 if is_image else self.NUM_GPUS_TOTAL
|
| 74 |
+
effective_sp_size = 1 if is_image else sp_size
|
|
|
|
|
|
|
|
|
|
| 75 |
|
| 76 |
|
| 77 |
+
output_filename = f"result_{Path(file_path).stem}.mp4"
|
| 78 |
+
output_filepath = out_dir / output_filename
|
| 79 |
+
|
| 80 |
|
| 81 |
cmd = [
|
| 82 |
+
"torchrun", "--standalone", "--nnodes=1", f"--nproc-per-node={effective_nproc}", str(script),
|
| 83 |
+
"--video_path", str(file_path),
|
|
|
|
|
|
|
| 84 |
"--output", str(output_filepath),
|
| 85 |
"--model_dir", str(self.CKPTS_ROOT),
|
| 86 |
"--seed", str(seed),
|
| 87 |
+
"--cuda_device", str("0,1,2,3"),
|
| 88 |
+
"--resolution", str(res_h),
|
| 89 |
+
"--batch_size", str(effective_sp_size),
|
| 90 |
"--model", "seedvr2_ema_3b_fp16.safetensors",
|
| 91 |
+
"--preserve_vram",
|
| 92 |
"--debug",
|
| 93 |
+
"--output_format", "video"
|
| 94 |
]
|
| 95 |
+
|
| 96 |
+
if effective_nproc > 1:
|
| 97 |
+
cmd = [c for c in cmd if not c.startswith('--cuda_device')]
|
| 98 |
+
|
| 99 |
+
print("[SeedVRServer] Comando:", " ".join(cmd))
|
| 100 |
+
|
| 101 |
+
|
| 102 |
print("SeedVRServer Comando:", " ".join(cmd))
|
| 103 |
try:
|
| 104 |
subprocess.run(cmd, cwd=str(self.SEEDVR_ROOT), check=True, env=os.environ.copy(), stdout=sys.stdout, stderr=sys.stderr)
|
|
|
|
| 113 |
except Exception as e:
|
| 114 |
print(f"[UI ERROR] A inferência falhou: {e}")
|
| 115 |
return None, None, None
|
| 116 |
+
|
| 117 |
+
|
| 118 |
+
|