### Setup Development Environment Source: https://github.com/tencent-hunyuan/hunyuanvideo-foley/blob/main/INSTALL.md Clone the project, install the development version with dependencies, set up pre-commit hooks, and run tests. Includes commands for code formatting and type checking. ```bash # Clone the project git clone https://github.com/Tencent-Hunyuan/HunyuanVideo-Foley cd HunyuanVideo-Foley # Install development version pip install -e .[dev] # Install pre-commit hooks pre-commit install # Run tests python -m pytest # Code formatting black --line-length 120 . isort --profile black . # Type checking mypy --ignore-missing-imports . ``` -------------------------------- ### Setup Development Environment Source: https://github.com/tencent-hunyuan/hunyuanvideo-foley/blob/main/DEVELOPMENT.md Steps to set up a Python virtual environment, activate it, and install project dependencies including the project in editable mode. ```bash python -m venv venv source venv/bin/activate # Linux/Mac # or venv\Scripts\activate # Windows pip install -r requirements.txt pip install -e . ``` -------------------------------- ### Install and Install Pre-commit Hooks Source: https://github.com/tencent-hunyuan/hunyuanvideo-foley/blob/main/DEVELOPMENT.md Install the pre-commit package and set up the hooks to automatically format code before each commit. ```bash pip install pre-commit pre-commit install ``` -------------------------------- ### Build and Install Wheel Package Source: https://github.com/tencent-hunyuan/hunyuanvideo-foley/blob/main/INSTALL.md Build a wheel package from the source and then install it using pip. ```bash # In the project root directory python setup.py bdist_wheel pip install dist/hunyuanvideo_foley-1.0.0-py3-none-any.whl ``` -------------------------------- ### Install from Source (Recommended) Source: https://github.com/tencent-hunyuan/hunyuanvideo-foley/blob/main/INSTALL.md Clone the repository and install the package in development mode. Use '[all]' to include all optional dependencies. ```bash # Clone the repository git clone https://github.com/Tencent-Hunyuan/HunyuanVideo-Foley cd HunyuanVideo-Foley # Install the package (development mode) pip install -e . # Or install with all optional dependencies pip install -e .[all] ``` -------------------------------- ### Install Directly from GitHub Source: https://github.com/tencent-hunyuan/hunyuanvideo-foley/blob/main/INSTALL.md Install the package directly using pip from its GitHub repository. ```bash pip install git+https://github.com/Tencent-Hunyuan/HunyuanVideo-Foley.git ``` -------------------------------- ### Verify Installation Source: https://github.com/tencent-hunyuan/hunyuanvideo-foley/blob/main/INSTALL.md Check if the package is installed correctly by importing it and checking the command-line tool help. ```bash # Check if the package is installed correctly python -c "import hunyuanvideo_foley; print(hunyuanvideo_foley.__version__)" # Check the command-line tool hunyuanvideo-foley --help ``` -------------------------------- ### Install Special Dependencies Source: https://github.com/tencent-hunyuan/hunyuanvideo-foley/blob/main/INSTALL.md Install 'audiotools' and a specific version of 'transformers' that supports SigLIP2, as these are not on PyPI. ```bash # Install audiotools (required) pip install git+https://github.com/descriptinc/audiotools # Install specific version of transformers (SigLIP2 support) pip install git+https://github.com/huggingface/transformers@v4.49.0-SigLIP-2 ``` -------------------------------- ### Install Optional Dependencies Source: https://github.com/tencent-hunyuan/hunyuanvideo-foley/blob/main/INSTALL.md Install optional dependencies for development, testing, Gradio interface, or all available optional packages. ```bash # Install development dependencies pip install hunyuanvideo-foley[dev] # Install testing dependencies pip install hunyuanvideo-foley[test] # Install Gradio interface dependencies pip install hunyuanvideo-foley[gradio] # Install all optional dependencies pip install hunyuanvideo-foley[all] ``` -------------------------------- ### Example Function with Type Hints and Docstrings Source: https://github.com/tencent-hunyuan/hunyuanvideo-foley/blob/main/DEVELOPMENT.md A Python function demonstrating type hints for parameters and return values, along with Google-style docstrings including Args, Returns, and Raises sections. ```python import os from typing import Optional, Tuple import numpy as np def process_video( video_path: str, max_duration: Optional[float] = None ) -> Tuple[np.ndarray, float]: """ Process video file and extract frames. Args: video_path: Path to input video file max_duration: Maximum duration in seconds (optional) Returns: Tuple of (frames array, duration in seconds) Raises: FileNotFoundError: If video file doesn't exist VideoProcessingError: If video processing fails """ if not os.path.exists(video_path): raise FileNotFoundError(f"Video file not found: {video_path}") # Implementation here... ``` -------------------------------- ### Download Pretrained Models from Huggingface (git-lfs) Source: https://github.com/tencent-hunyuan/hunyuanvideo-foley/blob/main/README.md Download the pretrained model weights from Huggingface using git-lfs. Ensure git-lfs is installed and configured. ```bash # using git-lfs git clone https://huggingface.co/tencent/HunyuanVideo-Foley ``` -------------------------------- ### Clone HunyuanVideo-Foley Repository Source: https://github.com/tencent-hunyuan/hunyuanvideo-foley/blob/main/README.md Clone the official repository to your local machine and navigate into the project directory. This is the first step to begin setup. ```bash # \ud83d\udce6 Clone the repository git clone https://github.com/Tencent-Hunyuan/HunyuanVideo-Foley cd HunyuanVideo-Foley ``` -------------------------------- ### Install Project Dependencies Source: https://github.com/tencent-hunyuan/hunyuanvideo-foley/blob/main/README.md Install all necessary Python dependencies listed in the requirements.txt file. It is recommended to use a Conda environment for managing dependencies. ```bash # \u2699\ufe0f Install dependencies pip install -r requirements.txt ``` -------------------------------- ### Troubleshoot Transformers Version Source: https://github.com/tencent-hunyuan/hunyuanvideo-foley/blob/main/INSTALL.md If you face issues related to the 'transformers' library, install the specific version that supports SigLIP2. ```bash pip install git+https://github.com/huggingface/transformers@v4.49.0-SigLIP-2 ``` -------------------------------- ### Troubleshoot ImportError for audiotools Source: https://github.com/tencent-hunyuan/hunyuanvideo-foley/blob/main/INSTALL.md If you encounter an 'ImportError: No module named 'audiotools'', install it using the provided pip command. ```bash pip install git+https://github.com/descriptinc/audiotools ``` -------------------------------- ### Use Command-Line Tool Source: https://github.com/tencent-hunyuan/hunyuanvideo-foley/blob/main/INSTALL.md Process single videos, batch videos from a CSV, or launch the Gradio interface using the command-line tool. ```bash # Single video processing hunyuanvideo-foley \ --model_path ./pretrained_models \ --single_video video.mp4 \ --single_prompt "footsteps on gravel" \ --output_dir ./outputs # Batch processing hunyuanvideo-foley \ --model_path ./pretrained_models \ --csv_path batch_videos.csv \ --output_dir ./outputs # Launch Gradio interface hunyuanvideo-foley --gradio --model_path ./pretrained_models ``` -------------------------------- ### Launch Gradio Web Interface (XL Model) Source: https://github.com/tencent-hunyuan/hunyuanvideo-foley/blob/main/README.md Launch the interactive Gradio web interface with the memory-friendly XL model. Set the HIFI_FOLEY_MODEL_PATH environment variable and specify MODEL_SIZE=xl. ```bash export HIFI_FOLEY_MODEL_PATH=PRETRAINED_MODEL_PATH_DIR MODEL_SIZE=xl python3 gradio_app.py ``` -------------------------------- ### Launch Gradio Web Interface with Offload Enabled Source: https://github.com/tencent-hunyuan/hunyuanvideo-foley/blob/main/README.md Launch the Gradio web interface with optional offload enabled to reduce memory usage. Set the HIFI_FOLEY_MODEL_PATH environment variable and ENABLE_OFFLOAD=true. ```bash export HIFI_FOLEY_MODEL_PATH=PRETRAINED_MODEL_PATH_DIR ENABLE_OFFLOAD=true python3 gradio_app.py ``` -------------------------------- ### Download Pretrained Models from Huggingface (huggingface-cli) Source: https://github.com/tencent-hunyuan/hunyuanvideo-foley/blob/main/README.md Download the pretrained model weights from Huggingface using the huggingface-cli tool. This is an alternative method to git-lfs. ```bash # using huggingface-cli huggingface-cli download tencent/HunyuanVideo-Foley ``` -------------------------------- ### Download Test Videos Source: https://github.com/tencent-hunyuan/hunyuanvideo-foley/blob/main/README.md Download sample test videos required for batch processing. This script should be run before executing batch processing commands. ```bash bash ./download_test_videos.sh ``` -------------------------------- ### Download Model using HuggingFace Hub Source: https://github.com/tencent-hunyuan/hunyuanvideo-foley/blob/main/INSTALL.md Download the pre-trained model from HuggingFace Hub using git clone or the huggingface-cli. ```bash # Using HuggingFace Hub git clone https://huggingface.co/tencent/HunyuanVideo-Foley # Or using huggingface-cli huggingface-cli download tencent/HunyuanVideo-Foley ``` -------------------------------- ### Launch Gradio Web Interface (XXL Model) Source: https://github.com/tencent-hunyuan/hunyuanvideo-foley/blob/main/README.md Launch the interactive Gradio web interface using the default XXL model. Set the HIFI_FOLEY_MODEL_PATH environment variable to your model directory. ```bash export HIFI_FOLEY_MODEL_PATH=PRETRAINED_MODEL_PATH_DIR python3 gradio_app.py ``` -------------------------------- ### Use Original Scripts (Backward Compatibility) Source: https://github.com/tencent-hunyuan/hunyuanvideo-foley/blob/main/INSTALL.md Run inference using the original 'infer.py' script or launch the Gradio application by setting the model path environment variable. ```bash # Use the original infer.py script python infer.py --model_path ./pretrained_models --single_video video.mp4 --single_prompt "audio description" # Launch Gradio application export HIFI_FOLEY_MODEL_PATH=./pretrained_models python gradio_app.py ``` -------------------------------- ### Batch Process Videos with CSV Source: https://github.com/tencent-hunyuan/hunyuanvideo-foley/blob/main/README.md Process multiple videos by providing a CSV file containing video paths and descriptions. This command requires the model path, CSV file path, and output directory. ```bash python3 infer.py \ --model_path PRETRAINED_MODEL_PATH_DIR \ --csv_path assets/test.csv \ --output_dir OUTPUT_DIR \ # --enable_offload ``` -------------------------------- ### Generate Foley Audio for Single Video (XXL Model) Source: https://github.com/tencent-hunyuan/hunyuanvideo-foley/blob/main/README.md Use this command to generate Foley audio for a single video file using the default XXL model. Specify the model path, video path, audio description prompt, and output directory. ```bash python3 infer.py \ --model_path PRETRAINED_MODEL_PATH_DIR \ --single_video video_path \ --single_prompt "audio description" \ --output_dir OUTPUT_DIR \ # --enable_offload ``` -------------------------------- ### Generate Foley Audio for Single Video (XL Model) Source: https://github.com/tencent-hunyuan/hunyuanvideo-foley/blob/main/README.md Use this command for generating Foley audio with the memory-friendly XL model. Ensure to set the model size to 'xl' and specify the model path, video path, prompt, and output directory. ```bash python3 infer.py \ --model_path PRETRAINED_MODEL_PATH_DIR \ --model_size xl \ --single_video video_path \ --single_prompt "audio description" \ --output_dir OUTPUT_DIR \ # --enable_offload ``` -------------------------------- ### Use as Python Package Source: https://github.com/tencent-hunyuan/hunyuanvideo-foley/blob/main/INSTALL.md Load the model and process features using the HunyuanVideo-Foley Python package. This involves loading models and then processing visual, text, and audio data. ```python import hunyuanvideo_foley as hvf # Load the model model_dict, cfg = hvf.load_model( model_path="path/to/model", config_path="configs/hunyuanvideo-foley-xxl.yaml" ) # Process features visual_feats, text_feats, audio_len = hvf.feature_process( video_path="video.mp4", prompt="footsteps on gravel", model_dict=model_dict, cfg=cfg ) # Generate audio audio, sample_rate = hvf.denoise_process( visual_feats, text_feats, audio_len, model_dict, cfg ) ``` -------------------------------- ### Run Quality Checks Source: https://github.com/tencent-hunyuan/hunyuanvideo-foley/blob/main/DEVELOPMENT.md Execute the automated quality checks for code formatting, import sorting, linting, type checking, and running tests. ```bash black --check --line-length 120 . isort --check-only --profile black . flake8 --max-line-length 120 mypy --ignore-missing-imports . pytest ``` -------------------------------- ### Run Pytest Tests Source: https://github.com/tencent-hunyuan/hunyuanvideo-foley/blob/main/DEVELOPMENT.md Commands to execute tests using pytest, including running all tests, targeting a specific file, and running tests with code coverage. ```bash # Run all tests python -m pytest # Run specific test file python -m pytest tests/test_feature_utils.py # Run with coverage python -m pytest --cov=hunyuanvideo_foley ``` -------------------------------- ### Manually Format and Lint Code Source: https://github.com/tencent-hunyuan/hunyuanvideo-foley/blob/main/DEVELOPMENT.md Commands to manually format Python code using Black, sort imports with isort, check style with flake8, and perform static type checking with mypy. ```bash # Format all Python files black --line-length 120 . # Sort imports isort --profile black --line-length 120 . # Check code style flake8 --max-line-length 120 # Type checking mypy --ignore-missing-imports . ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.