Run this model with HF Jobs
Run Agnes-AI/Agnes-Video-H3-MoE on Hugging Face's managed compute, monitor its progress, and retrieve the results when it's done.
Paste one of these prompts into your coding agent:
Fine-tune on my dataset
Use HF Jobs to fine-tune https://huggingface.co/Agnes-AI/Agnes-Video-H3-MoE. Ask me which dataset to train on, then push the fine-tuned model to a new model repo. Run `hf jobs --help` first to learn the CLI.
Run batch inference
Use HF Jobs to run batch inference with https://huggingface.co/Agnes-AI/Agnes-Video-H3-MoE on the inputs in a mounted HF Bucket. Ask me which Bucket to use, then write the outputs back to it and keep each input ID. Run `hf jobs --help` first to learn the CLI.
Download deploy/diffsynth/utils/music_tools/prosody.py from Agnes-AI/Agnes-Video-H3-MoE: direct link, hf CLI and curl.
- Browser
- Download file 1.68 kB
-
https://huggingface.co/Agnes-AI/Agnes-Video-H3-MoE/resolve/main/deploy/diffsynth/utils/music_tools/prosody.py
- Command line
-
hf download hf://Agnes-AI/Agnes-Video-H3-MoE/deploy/diffsynth/utils/music_tools/prosody.py
-
curl -L -o prosody.py https://huggingface.co/Agnes-AI/Agnes-Video-H3-MoE/resolve/main/deploy/diffsynth/utils/music_tools/prosody.py
1.68 kB
| import torch | |
| import librosa | |
| import numpy as np | |
| from scipy.signal import butter, filtfilt | |
| from einops import repeat | |
| def extract_smooth_envelope(y, sr, cutoff_hz=30.0): | |
| abs_y = np.abs(y) | |
| nyq = 0.5 * sr | |
| b1, a1 = butter(4, cutoff_hz / nyq, btype='low') | |
| env = filtfilt(b1, a1, abs_y) | |
| b2, a2 = butter(2, 80.0 / nyq, btype='low') | |
| env = filtfilt(b2, a2, env) | |
| return env / (np.max(env) + 1e-8) | |
| def fill_nan_f0(arr): | |
| mask = np.isnan(arr) | |
| if not np.any(mask): return arr | |
| idx = np.where(~mask, np.arange(mask.shape[0]), 0) | |
| np.maximum.accumulate(idx, out=idx) | |
| out = arr[idx] | |
| mask2 = np.isnan(out) | |
| if np.any(mask2): | |
| idx2 = np.where(~mask2, np.arange(mask2.shape[0]), mask2.shape[0]-1) | |
| np.minimum.accumulate(idx2[::-1], out=idx2[::-1]) | |
| out = out[idx2] | |
| return out | |
| def extract_prosody(audio_tensor, sr=48000): | |
| audio_tensor = audio_tensor.squeeze() | |
| if audio_tensor.dim() > 1: | |
| audio_tensor = audio_tensor.mean(dim=0) | |
| y = audio_tensor.cpu().numpy() | |
| envelope = extract_smooth_envelope(y, sr) | |
| hop_length = 512 | |
| f0, _, _ = librosa.pyin(y, fmin=65, fmax=1000, sr=sr, hop_length=hop_length) | |
| f0 = fill_nan_f0(f0) | |
| t_frames = librosa.frames_to_time(np.arange(len(f0)), sr=sr, hop_length=hop_length) | |
| t_samples = np.arange(len(y)) / sr | |
| f0_samples = np.interp(t_samples, t_frames, f0) | |
| phase = 2 * np.pi * np.cumsum(f0_samples) / sr | |
| carrier = np.sin(phase) | |
| out = carrier * envelope | |
| out = out * (np.max(np.abs(y)) / (np.max(np.abs(out)) + 1e-8)) | |
| out = torch.from_numpy(out.astype(np.float32)) | |
| out = repeat(out, "l -> n l", n=2) | |
| return out | |