Download code/evaluation/tests/test_quality_input.py from luyu1021/turbot2va-ltx2: direct link, hf CLI and curl.
- Browser
- Download file 2.93 kB
-
https://huggingface.co/luyu1021/turbot2va-ltx2/resolve/main/code/evaluation/tests/test_quality_input.py
- Command line
-
hf download hf://luyu1021/turbot2va-ltx2/code/evaluation/tests/test_quality_input.py
-
curl -L -o test_quality_input.py https://huggingface.co/luyu1021/turbot2va-ltx2/resolve/main/code/evaluation/tests/test_quality_input.py
2.93 kB
| import argparse | |
| import csv | |
| import sys | |
| import tempfile | |
| import unittest | |
| from pathlib import Path | |
| from unittest.mock import patch | |
| sys.path.insert(0, str(Path(__file__).resolve().parents[1] / "scripts")) | |
| from run_quality_javisbench import input_csv, launch, prepare_input_csv # noqa: E402 | |
| class QualityInputTest(unittest.TestCase): | |
| def test_seeded_media_and_official_cli(self): | |
| with tempfile.TemporaryDirectory() as root: | |
| root = Path(root) | |
| media = root / "media" / "model" | |
| media.mkdir(parents=True) | |
| for extension in ("mp4", "wav"): | |
| (media / f"sample_0000_seed0000.{extension}").write_bytes(b"sample") | |
| python = root / "python" | |
| python.touch() | |
| config = { | |
| "_config_dir": str(root), | |
| "paths": { | |
| "diversity_root": str(root / "media"), | |
| "quality_input_root": str(root / "input"), | |
| "quality_output_root": str(root / "output"), | |
| "javis_root": str(root), | |
| "javis_python": str(python), | |
| }, | |
| "javisbench": {"metrics": ["av-score"]}, | |
| } | |
| model = {"name": "model"} | |
| prepare_input_csv(config, model, ["A prompt"], 0) | |
| with input_csv(config, model).open(newline="") as handle: | |
| row = list(csv.DictReader(handle))[0] | |
| self.assertEqual(row["text"], "A prompt") | |
| self.assertEqual(row["path"], str(media / "sample_0000_seed0000.mp4")) | |
| with patch("run_quality_javisbench.subprocess.Popen") as popen: | |
| popen.return_value.pid = 123 | |
| run = launch(config, model, "0", argparse.Namespace( | |
| max_audio_len_s=None, num_workers=None | |
| )) | |
| command = popen.call_args.args[0] | |
| self.assertNotIn("--infer_data_dir", command) | |
| self.assertNotIn("--video_quality_bs", command) | |
| self.assertEqual(command[command.index("--input_file") + 1], str(input_csv(config, model))) | |
| run["log_f"].close() | |
| def test_unseeded_media_fallback(self): | |
| with tempfile.TemporaryDirectory() as root: | |
| root = Path(root) | |
| media = root / "model" | |
| media.mkdir() | |
| for extension in ("mp4", "wav"): | |
| (media / f"sample_0000.{extension}").write_bytes(b"sample") | |
| config = {"_config_dir": str(root), "paths": { | |
| "diversity_root": str(root), "quality_input_root": str(root / "input") | |
| }} | |
| prepare_input_csv(config, {"name": "model"}, ["Another prompt"], 0) | |
| with input_csv(config, {"name": "model"}).open(newline="") as handle: | |
| row = list(csv.DictReader(handle))[0] | |
| self.assertEqual(row["pred_video_path"], str(media / "sample_0000.mp4")) | |