Download smoke_test.py from liuyibo/codiffact-full: direct link, hf CLI and curl.
- Browser
- Download file 3.44 kB
-
https://huggingface.co/liuyibo/codiffact-full/resolve/main/smoke_test.py
- Command line
-
hf download hf://liuyibo/codiffact-full/smoke_test.py
-
curl -L -o smoke_test.py https://huggingface.co/liuyibo/codiffact-full/resolve/main/smoke_test.py
3.44 kB
| """Dependency, headless rendering and optional GPU checks; no model downloads.""" | |
| import argparse | |
| import importlib | |
| import importlib.metadata | |
| import json | |
| import os | |
| import subprocess | |
| import tempfile | |
| from pathlib import Path | |
| os.environ.setdefault("PYOPENGL_PLATFORM", "osmesa") | |
| os.environ.setdefault("HF_HUB_OFFLINE", "1") | |
| def main(): | |
| parser = argparse.ArgumentParser() | |
| parser.add_argument("--gpu", action="store_true") | |
| args = parser.parse_args() | |
| modules = [ | |
| "torch", "torchaudio", "torchvision", "numpy", "scipy", "soundfile", | |
| "datasets", "transformers", "huggingface_hub", "safetensors", "yaml", | |
| "f5_tts.api", "vocos", "smplx", "chumpy", "pyrender", "trimesh", | |
| "imageio", "imageio_ffmpeg", "whisper", "jiwer", "python_speech_features", | |
| ] | |
| for name in modules: | |
| importlib.import_module(name) | |
| import numpy as np | |
| import pyrender | |
| import soundfile as sf | |
| import torch | |
| import torchaudio.functional as audio_fn | |
| import trimesh | |
| scene = pyrender.Scene(bg_color=[255, 255, 255, 255], ambient_light=[0.5, 0.5, 0.5]) | |
| material = pyrender.MetallicRoughnessMaterial(baseColorFactor=[0.55, 0.68, 0.82, 1.0]) | |
| scene.add(pyrender.Mesh.from_trimesh(trimesh.creation.icosphere(subdivisions=1), material=material)) | |
| pose = np.eye(4) | |
| pose[2, 3] = 3.0 | |
| scene.add(pyrender.PerspectiveCamera(yfov=np.pi / 3), pose=pose) | |
| scene.add(pyrender.DirectionalLight(color=np.ones(3), intensity=2), pose=pose) | |
| renderer = pyrender.OffscreenRenderer(64, 64) | |
| try: | |
| color, depth = renderer.render(scene) | |
| assert color.shape[:2] == (64, 64) and np.count_nonzero(depth) > 0 | |
| finally: | |
| renderer.delete() | |
| with tempfile.TemporaryDirectory() as temp: | |
| wav = Path(temp) / "tone.wav" | |
| sf.write(wav, np.zeros(24000, np.float32), 24000) | |
| waveform, sr = sf.read(wav) | |
| assert sr == 24000 and len(waveform) == 24000 | |
| video = Path(temp) / "test.mp4" | |
| subprocess.run([ | |
| "ffmpeg", "-nostdin", "-v", "error", "-f", "lavfi", "-i", | |
| "color=c=blue:s=64x64:r=30:d=1", "-i", str(wav), | |
| "-c:v", "libx264", "-pix_fmt", "yuv420p", "-c:a", "aac", | |
| "-t", "1", str(video), | |
| ], check=True) | |
| subprocess.run(["ffmpeg", "-nostdin", "-v", "error", "-xerror", "-i", str(video), "-f", "null", "-"], check=True) | |
| tools = {} | |
| for name, command in { | |
| "git": ["git", "--version"], "git-lfs": ["git", "lfs", "version"], | |
| "font": ["fc-match", "-f", "%{file}", "sans"], | |
| }.items(): | |
| tools[name] = subprocess.check_output(command, text=True).strip() | |
| assert Path(tools["font"]).is_file() | |
| result = { | |
| "tools": tools, | |
| "imports": modules, "osmesa": "passed", "h264_aac": "passed", | |
| "torch": torch.__version__, "cuda_build": torch.version.cuda, | |
| "gpu_test_requested": args.gpu, | |
| } | |
| if args.gpu: | |
| assert torch.cuda.is_available(), "A CUDA-capable runtime is required for --gpu" | |
| x = torch.randn(128, 128, device="cuda") | |
| assert torch.isfinite(x @ x.T).all().item() | |
| resampled = audio_fn.resample(torch.zeros(1, 2400, device="cuda"), 24000, 16000) | |
| assert resampled.shape[-1] == 1600 | |
| torch.cuda.synchronize() | |
| result["gpu"] = torch.cuda.get_device_name(0) | |
| print(json.dumps(result, ensure_ascii=False), flush=True) | |
| if __name__ == "__main__": | |
| main() | |