Welcome to the TripleX repository! This project provides tools for downloading videos from supported websites (such as xHamster) and from Reddit, then processing these files using utilities like scene detection, trimming, frame analysis, and dataset creation for model training.
Reddit: https://www.reddit.com/r/NSFW_API
Discord: https://discord.gg/JVtvyX3HkR
TripleX is designed to help users download videos from supported websites and perform various processing tasks such as scene detection, trimming unwanted frames, analyzing frames using machine learning models, and creating datasets for training custom AI models. The toolkit is modular, allowing for easy addition of new downloaders and utilities.
.
├── LICENSE
├── README.md
├── captioners/
│ ├── gemini.py
│ ├── joycaption2.py
│ └── open_ai.py <--- Former get_captions.py has been moved here
├── data
│ ├── clips
│ ├── images
│ └── videos
├── downloaders
│ ├── download_xhamster.py
| └── reddit_downloader.py
├── guides
│ ├── fine_tuning_hunyuan_video_with_finetrainers.md
│ └── fine_tuning_mochi_with_modal.md
├── requirements.txt
├── setup_models.py
└── utils
├── analyze_frames.py
├── extract_sharpest_frame.py
├── split_by_scene.py
├── training
│ └── hunyuan
│ └── output_clips_to_hunyuan_dataset
└── trim_frame_beginning.py
Clone the Repository:
git clone https://github.com/NSFW-API/TripleX.gitcd TripleXCreate a Virtual Environment:
python3 -m venv venvsource venv/bin/activate # On macOS/Linuxvenv\Scripts\activate)Install Dependencies:
pip install -r requirements.txtInstall FFmpeg:
brew install ffmpegsudo apt-get install ffmpeg(Optional) Install TensorFlow and Additional Dependencies for further processing:
pip install tensorflow opencv-python numpyIf you plan to use the Reddit downloader, you’ll need Reddit API credentials. We recommend storing them in a .env file. We’ve provided an example named .env_example at the repository root:
REDDIT_CLIENT_ID=
REDDIT_CLIENT_SECRET=
REDDIT_USER_AGENT=python:[App Name]:v1.0 (by /u/[YourUsername])
Copy .env_example to .env:
cp .env_example .env
Edit .env and fill in your Reddit credentials. See the Setting Up Reddit Credentials section for how to obtain them.
Ensure .env is in your .gitignore so you don’t accidentally commit secrets:
echo ".env" >> .gitignore
Once .env is set up, scripts like reddit_downloader.py will load these environment variables automatically (via python-dotenv) and use them to authenticate against Reddit.
To obtain the necessary client ID and secret for Reddit:
Create or log into your Reddit account.
Open your apps preferences page:
https://www.reddit.com/prefs/apps/
Click “Create another app…” at the bottom of the page.
Provide an “App name” → pick any descriptive name, e.g. “TripleXScraper.”
Under “App type,” select “script.”
Enter a short description. The “About URL” and “Redirect URL” fields can be any URL (e.g. “http://localhost/”).
Click “Create app.”
Once created, you’ll see something like:
personal use script: ...
secret: ...
redirect uri: http://localhost/
Copy the “personal use script” value into REDDIT_CLIENT_ID and the “secret” value into REDDIT_CLIENT_SECRET.
Your .env might look like this:
REDDIT_CLIENT_ID=abc123def456
REDDIT_CLIENT_SECRET=abc123def4567890abcdef12345
REDDIT_USER_AGENT=python:TripleXScraper:v1.0 (by /u/YourUsername)
The user agent can be any descriptive string, but Reddit recommends using the format “python:app_name:vX.Y (by /u/username).”
The project provides multiple downloaders for different platforms:
The download_xhamster.py script allows you to download videos from xHamster.
Note: Ensure you comply with all legal requirements and terms of service when downloading content.
Example Usage:
python downloaders/download_xhamster.py <video_url>
<video_url> with the actual URL of the xHamster video.Instructions:
Run the Script:
python downloaders/download_xhamster.py <video_url>
The Video will be downloaded to data/videos.
data/videos directory.The chan_downloader.py script allows you to download media (images, GIFs, and videos) from 4chan threads or entire boards.
Example Usage:
# Download from a specific thread
python downloaders/chan_downloader.py w --thread 12345678
# Download from an entire board
python downloaders/chan_downloader.py w --limit 100
# Skip previously downloaded threads
python downloaders/chan_downloader.py wg --skip-existing
Arguments:
board: (required) The board name (e.g., 'w', 'wg', etc.)--thread: (optional) Specific thread ID to download from--limit: (optional) Maximum number of threads to download from board--skip-existing: (optional) Skip threads that have been previously downloaded--log-level: (optional) Set logging level (debug, info, warning, error)Features:
Instructions:
Run the Script:
python downloaders/chan_downloader.py <board> [options]
Media Organization:
data/chan/images/<board>/<thread_id>data/chan/videos/<board>/<thread_id>data/chan/gifs/<board>/<thread_id>Download Tracking:
data/chan/downloaded_threads.json--skip-existing to skip previously downloaded threadsNotes:
chan_downloader.logYou can download images, GIFs, or videos from any public subreddit via the reddit_downloader.py script:
Standard usage looks like this:
python downloaders/reddit_downloader.py SUBREDDIT_NAME [ADDITIONAL_SUBREDDITS] [OPTIONS]
For example:
python downloaders/reddit_downloader.py TittyDrop --limit 100 --convert-gifs
--limit 100 means get up to 100 “hot” posts.--convert-gifs automatically converts downloaded GIFs into MP4s, stored in data/videos.Below are the main flags you can use:
--limit N : Number of posts to scrape per subreddit (default=10).--skip-images : Skip downloading standard image files (.jpg, .png, etc.).--skip-gifs : Skip downloading .gif files.--skip-videos : Skip downloading video files (.mp4, .webm, etc.).--convert-gifs : Convert any downloaded .gif to .mp4 (saved in data/videos).--skip-ingest : Skip creating new JSON (use existing JSON from previous runs).--skip-download : Skip downloading (just scrape or ingest information).When running without any flags, the script will:
After running the script, you can find your media in the data/images or data/videos directories. You can further process them with other TripleX utilities (scene detection, trimming, dataset creation, etc.).
The split_by_scene.py script splits all videos in data/videos into scenes based on content detection.
Example Usage:
python utils/split_by_scene.py
Instructions:
Run the Script:
python utils/split_by_scene.py
Processing:
data/videos.data/clips named after the video file (without extension).Notes:
threshold=15.0, min_scene_len=15).The trim_frame_beginning.py script trims a specified number of frames from the beginning of all videos in data/videos and its subdirectories.
Example Usage:
python utils/trim_frame_beginning.py [num_frames]
[num_frames] (optional): The number of frames to trim from the beginning of each video. If not provided, the default is 5.Instructions:
Run the Script:
To trim a specific number of frames:
python utils/trim_frame_beginning.py 10
10 frames from the beginning of each video.To use the default number of frames (5):
python utils/trim_frame_beginning.py
Processing:
data/videos and its subdirectories.Notes:
The analyze_frames.py script analyzes frames extracted from videos using machine learning models. It processes the sharpest frame from each video scene to classify and detect various elements.
Example Usage:
python utils/analyze_frames.py
Instructions:
Ensure Scenes are Available:
split_by_scene.py.data/clips.Ensure Models are Set Up:
setup_models.py as described in the Installation section to download and set up the required models.Run the Script:
python utils/analyze_frames.py
Processing:
The script processes each video in data/clips.
For each video, it extracts the sharpest frame using extract_sharpest_frame.py.
The extracted frame is analyzed using the following models:
Outputs:
data/images.data/images.Notes:
Dependencies:
Model Requirements:
setup_models.py.Adjustable Parameters:
TripleX can be used to create customized datasets for training video generation AI models like Mochi LoRA. By processing and extracting frames from videos, you can generate datasets suitable for model training.
For a detailed guide on how to use this repository to create a dataset and train a Mochi LoRA model using Modal (a GPU app hosting platform), refer to the following article:
How to Train a Video Model Using TripleX and Mochi LoRA:
Instructions:
Prepare Your Dataset:
Follow the Guide:
Notes:
Model Training Considerations:
Compatibility:
In addition to its video processing utilities, TripleX now includes a new captioning tool located under the /captioners directory. This new script – gemini.py – generates detailed captions for all images and videos in a specified directory. It works by processing individual frames from videos (or single images) and then composing a final, cohesive composite caption for each file. The script uses Google’s Gemini models as its backend with fallback options for reliability.
• Generates frame-level captions for videos using a configurable sampling rate (frames per second).
• Supports both video files (e.g., .mp4, .mov, .avi, .webm, etc.) and image files (e.g., .jpg, .png, .heic, etc.).
• Uses fallback Gemini models for robust caption generation in case of rate limits or resource issues.
• Creates a composite caption that unifies the descriptions from individual frames.
• Offers an optional rewriting step that reformats the composite caption into a concise and elegant narrative.
• Supports parallel processing for faster captioning of video frames.
• Optionally moves the source files and their generated caption files to a specified output directory after successful processing.
Ensure all dependencies are installed (listed in requirements.txt – additional packages used by Gemini captioner include cv2 (OpenCV), google-generativeai, and python-dotenv).
Set your Gemini API key as an environment variable. You can add the following entry to your .env file at the root of the repository:
GEMINI_API_KEY=your_gemini_api_key_here
This key is required to authenticate with the Gemini API. If you are not already using a .env file for other credentials, consider creating one and adding it to your .gitignore.
Run the captioner from the command line by specifying the directory containing video and/or image files:
python captioners/gemini.py --dir <path_to_media_directory>
The script supports additional options:
--fps
--max_frames
--output_dir
--custom_prompt
To caption all media files in the media folder at 1 FPS sampling, with a custom prompt and move completed files to finished_captions:
python captioners/gemini.py --dir media --fps 1 --custom_prompt "Include specific observations about background and accessories." --output_dir finished_captions
--fps flag). Each frame is encoded as a JPEG and sent to the Gemini API for caption generation, making use of parallel processing to speed up the workflow.TripleX now includes a script that can directly process entire video files using Google’s Vertex AI service. Unlike the Gemini-based captioner, which focuses on individual frames or images, this script uploads each video to a Google Cloud Storage (GCS) bucket and then queries Vertex AI to generate a JSON-formatted caption (including timestamps) describing the entire video.
A Google Cloud Platform (GCP) project with the following roles granted to the service account you will use:
• Service Usage Consumer
• Storage Admin
• Vertex AI Administrator
A GCS bucket where your video files will be uploaded before caption generation.
A service account JSON key file to authenticate with Google Cloud. Store this key in a secure location and set the environment variable to point to it (for example):
export GOOGLE_APPLICATION_CREDENTIALS="/path/to/your-service-acct-key.json"
Dependencies for Vertex AI and the GCS Python client (e.g., google-cloud-storage, vertexai, google-cloud-aiplatform) installed in your environment. Make sure these are in your requirements.txt or installed manually: pip install google-cloud-storage google-cloud-aiplatform
To run the Vertex AI captioner, use the following command from the project root (adjusting paths and arguments as needed):
python captioners/vertex_ai.py \
--dir /path/to/videos \
--bucket your-gcs-bucket \
--project your-gcp-project-id \
[--location us-central1] \
[--prompt "Custom instructions"] \
[--output_dir /path/to/output]
• --dir: Path to the local directory containing your video files.
• --bucket: Name of the GCS bucket where videos will be uploaded.
• --project: Your GCP project ID.
• --location (optional): The region for Vertex AI (defaults to us-central1).
• --prompt (optional): Custom text to refine or alter the captioning behavior.
• --output_dir (optional): Directory to which processed files (i.e., the original video, JSON output, and text caption) will be moved upon successful captioning.
When the script runs:
export GOOGLE_APPLICATION_CREDENTIALS="/path/to/your-service-acct-key.json"
python captioners/vertex_ai.py \
--dir data/videos \
--bucket my-video-bucket \
--project my-gcp-project \
--location us-central1 \
--prompt "Emphasize activities and background objects, but remain concise." \
--output_dir data/captioned_videos
After running, you’ll find three files per video in data/captioned_videos:
• Adult Content: If you are processing adult or explicit material, ensure your GCP project and usage of Vertex AI aligns with Google’s content policies and any applicable legal requirements.
• Privacy and Rights: Confirm you have rights and permission to upload and process the video files on Google’s servers.
• Costs: Vertex AI usage may incur charges. Consult Google’s documentation for pricing details.
• Troubleshooting: If you encounter “Resource exhausted” or rate-limit errors, the script will automatically try fallback models. If all attempts fail, an error is printed.
TripleX also includes a script for generating detailed captions for images using the JoyCaption2 model, which is based on LLaVA and Llama 3.1. Unlike video-based captioning tools, this script processes individual images or entire directories of images and generates a long, formal descriptive caption for each image. The captions are saved as .txt files in the same directory as the images.
Install the required dependencies in your Python environment:
pip install -r requiredments.txt
Ensure your system has a compatible GPU to run the JoyCaption2 model efficiently. If no GPU is available, the model will attempt to run on CPU (but performance may be slower).
The script will automatically download the JoyCaption2 model (fancyfeast/llama-joycaption-alpha-two-hf-llava) if it is not already available.
To run the JoyCaption2 image captioner, use the following command from the project root:
python utils/describe-image.py <image_path_or_directory>
<image_path_or_directory>: Either a single image file path or a directory containing multiple images.When executed, the script will:
models/. If not, it will download it automatically..txt file in the same directory as the image.python utils/describe-image.py data/images/example.jpg
data/images/example.txt.python utils/describe-image.py data/images/
data/images/, saving them as .txt files with the same base filenames.For an image named example.jpg, the script will generate:
example.txt containing the long descriptive caption..jpg, .jpeg, .png, .bmp, .gif, and .tiff.models/llama-joycaption-alpha-two-hf-llava/.This tool provides an efficient way to generate high-quality captions for large batches of images while leveraging state-of-the-art AI models. 🚀
Contributions are welcome! You can contribute to this project in the following ways:
download_xhamster.py to create a downloader for another site.downloaders/ Directory.utils/ directory.requirements.txt.Fork the Repository: Click the "Fork" button at the top-right corner of the repository page.
Clone Your Fork:
git clone https://github.com/your-username/TripleX.git
Create a New Branch:
git checkout -b feature/new-utility
Make Your Changes: Add your downloader or utility script.
Commit Your Changes:
git add .
git commit -m "Add new utility for dataset creation"
Push to Your Fork:
git push origin feature/new-utility
Open a Pull Request: Go to the original repository and click "New Pull Request."
Note: Be cautious about including large files (e.g., model files) in your commits. If your changes involve large files, consider alternative methods such as hosting the files externally or using Git LFS (Large File Storage).
This project is licensed under the MIT License. See the LICENSE file for details.
Thank you for using TripleX! If you have any questions or need assistance, feel free to open an issue on the repository or reach out to the maintainers.
Logging: The scripts log their activities, which can be helpful for debugging.
Error Handling: The scripts include basic error handling to inform you of issues that may arise during processing.
Dependencies: Ensure that all dependencies listed in requirements.txt are installed in your virtual environment. If you encounter issues, double-check that all required packages are installed.
# requirements.txt
requests
scenedetect
beautifulsoup4
tensorflow
opencv-python
numpy
FFmpeg: FFmpeg is a crucial dependency for video processing in this toolkit. Ensure that it is correctly installed and accessible from your system's PATH.
Python Version: This toolkit is developed for Python 3.x. Ensure you are using a compatible version of Python.
Model Files: The machine learning models required for frame analysis are downloaded using setup_models.py. Do not add these large files directly to the repository.
Git Limitations:
Using setup_models.py:
setup_models.py script handles the downloading of large model files from external sources (e.g., Google Drive) and places them in the appropriate directories.Modifying setup_models.py:
setup_models.py to include the new download links and ensure models are placed correctly.Alternative Methods:
models/ directory following the required structure.Avoid Committing Large Files:
Use External Hosting:
setup_models.py to download them.Git Large File Storage (LFS):
Feel free to reach out if you need any further assistance or have suggestions for improving the toolkit!
Python
100.0%
Welcome to the TripleX repository! This project provides tools for downloading videos from supported websites (such as xHamster) and from Reddit, then processing these files using utilities like scene detection, trimming, frame analysis, and dataset creation for model training.
Reddit: https://www.reddit.com/r/NSFW_API
Discord: https://discord.gg/JVtvyX3HkR
TripleX is designed to help users download videos from supported websites and perform various processing tasks such as scene detection, trimming unwanted frames, analyzing frames using machine learning models, and creating datasets for training custom AI models. The toolkit is modular, allowing for easy addition of new downloaders and utilities.
.
├── LICENSE
├── README.md
├── captioners/
│ ├── gemini.py
│ ├── joycaption2.py
│ └── open_ai.py <--- Former get_captions.py has been moved here
├── data
│ ├── clips
│ ├── images
│ └── videos
├── downloaders
│ ├── download_xhamster.py
| └── reddit_downloader.py
├── guides
│ ├── fine_tuning_hunyuan_video_with_finetrainers.md
│ └── fine_tuning_mochi_with_modal.md
├── requirements.txt
├── setup_models.py
└── utils
├── analyze_frames.py
├── extract_sharpest_frame.py
├── split_by_scene.py
├── training
│ └── hunyuan
│ └── output_clips_to_hunyuan_dataset
└── trim_frame_beginning.py
Clone the Repository:
git clone https://github.com/NSFW-API/TripleX.gitcd TripleXCreate a Virtual Environment:
python3 -m venv venvsource venv/bin/activate # On macOS/Linuxvenv\Scripts\activate)Install Dependencies:
pip install -r requirements.txtInstall FFmpeg:
brew install ffmpegsudo apt-get install ffmpeg(Optional) Install TensorFlow and Additional Dependencies for further processing:
pip install tensorflow opencv-python numpyIf you plan to use the Reddit downloader, you’ll need Reddit API credentials. We recommend storing them in a .env file. We’ve provided an example named .env_example at the repository root:
REDDIT_CLIENT_ID=
REDDIT_CLIENT_SECRET=
REDDIT_USER_AGENT=python:[App Name]:v1.0 (by /u/[YourUsername])
Copy .env_example to .env:
cp .env_example .env
Edit .env and fill in your Reddit credentials. See the Setting Up Reddit Credentials section for how to obtain them.
Ensure .env is in your .gitignore so you don’t accidentally commit secrets:
echo ".env" >> .gitignore
Once .env is set up, scripts like reddit_downloader.py will load these environment variables automatically (via python-dotenv) and use them to authenticate against Reddit.
To obtain the necessary client ID and secret for Reddit:
Create or log into your Reddit account.
Open your apps preferences page:
https://www.reddit.com/prefs/apps/
Click “Create another app…” at the bottom of the page.
Provide an “App name” → pick any descriptive name, e.g. “TripleXScraper.”
Under “App type,” select “script.”
Enter a short description. The “About URL” and “Redirect URL” fields can be any URL (e.g. “http://localhost/”).
Click “Create app.”
Once created, you’ll see something like:
personal use script: ...
secret: ...
redirect uri: http://localhost/
Copy the “personal use script” value into REDDIT_CLIENT_ID and the “secret” value into REDDIT_CLIENT_SECRET.
Your .env might look like this:
REDDIT_CLIENT_ID=abc123def456
REDDIT_CLIENT_SECRET=abc123def4567890abcdef12345
REDDIT_USER_AGENT=python:TripleXScraper:v1.0 (by /u/YourUsername)
The user agent can be any descriptive string, but Reddit recommends using the format “python:app_name:vX.Y (by /u/username).”
The project provides multiple downloaders for different platforms:
The download_xhamster.py script allows you to download videos from xHamster.
Note: Ensure you comply with all legal requirements and terms of service when downloading content.
Example Usage:
python downloaders/download_xhamster.py <video_url>
<video_url> with the actual URL of the xHamster video.Instructions:
Run the Script:
python downloaders/download_xhamster.py <video_url>
The Video will be downloaded to data/videos.
data/videos directory.The chan_downloader.py script allows you to download media (images, GIFs, and videos) from 4chan threads or entire boards.
Example Usage:
# Download from a specific thread
python downloaders/chan_downloader.py w --thread 12345678
# Download from an entire board
python downloaders/chan_downloader.py w --limit 100
# Skip previously downloaded threads
python downloaders/chan_downloader.py wg --skip-existing
Arguments:
board: (required) The board name (e.g., 'w', 'wg', etc.)--thread: (optional) Specific thread ID to download from--limit: (optional) Maximum number of threads to download from board--skip-existing: (optional) Skip threads that have been previously downloaded--log-level: (optional) Set logging level (debug, info, warning, error)Features:
Instructions:
Run the Script:
python downloaders/chan_downloader.py <board> [options]
Media Organization:
data/chan/images/<board>/<thread_id>data/chan/videos/<board>/<thread_id>data/chan/gifs/<board>/<thread_id>Download Tracking:
data/chan/downloaded_threads.json--skip-existing to skip previously downloaded threadsNotes:
chan_downloader.logYou can download images, GIFs, or videos from any public subreddit via the reddit_downloader.py script:
Standard usage looks like this:
python downloaders/reddit_downloader.py SUBREDDIT_NAME [ADDITIONAL_SUBREDDITS] [OPTIONS]
For example:
python downloaders/reddit_downloader.py TittyDrop --limit 100 --convert-gifs
--limit 100 means get up to 100 “hot” posts.--convert-gifs automatically converts downloaded GIFs into MP4s, stored in data/videos.Below are the main flags you can use:
--limit N : Number of posts to scrape per subreddit (default=10).--skip-images : Skip downloading standard image files (.jpg, .png, etc.).--skip-gifs : Skip downloading .gif files.--skip-videos : Skip downloading video files (.mp4, .webm, etc.).--convert-gifs : Convert any downloaded .gif to .mp4 (saved in data/videos).--skip-ingest : Skip creating new JSON (use existing JSON from previous runs).--skip-download : Skip downloading (just scrape or ingest information).When running without any flags, the script will:
After running the script, you can find your media in the data/images or data/videos directories. You can further process them with other TripleX utilities (scene detection, trimming, dataset creation, etc.).
The split_by_scene.py script splits all videos in data/videos into scenes based on content detection.
Example Usage:
python utils/split_by_scene.py
Instructions:
Run the Script:
python utils/split_by_scene.py
Processing:
data/videos.data/clips named after the video file (without extension).Notes:
threshold=15.0, min_scene_len=15).The trim_frame_beginning.py script trims a specified number of frames from the beginning of all videos in data/videos and its subdirectories.
Example Usage:
python utils/trim_frame_beginning.py [num_frames]
[num_frames] (optional): The number of frames to trim from the beginning of each video. If not provided, the default is 5.Instructions:
Run the Script:
To trim a specific number of frames:
python utils/trim_frame_beginning.py 10
10 frames from the beginning of each video.To use the default number of frames (5):
python utils/trim_frame_beginning.py
Processing:
data/videos and its subdirectories.Notes:
The analyze_frames.py script analyzes frames extracted from videos using machine learning models. It processes the sharpest frame from each video scene to classify and detect various elements.
Example Usage:
python utils/analyze_frames.py
Instructions:
Ensure Scenes are Available:
split_by_scene.py.data/clips.Ensure Models are Set Up:
setup_models.py as described in the Installation section to download and set up the required models.Run the Script:
python utils/analyze_frames.py
Processing:
The script processes each video in data/clips.
For each video, it extracts the sharpest frame using extract_sharpest_frame.py.
The extracted frame is analyzed using the following models:
Outputs:
data/images.data/images.Notes:
Dependencies:
Model Requirements:
setup_models.py.Adjustable Parameters:
TripleX can be used to create customized datasets for training video generation AI models like Mochi LoRA. By processing and extracting frames from videos, you can generate datasets suitable for model training.
For a detailed guide on how to use this repository to create a dataset and train a Mochi LoRA model using Modal (a GPU app hosting platform), refer to the following article:
How to Train a Video Model Using TripleX and Mochi LoRA:
Instructions:
Prepare Your Dataset:
Follow the Guide:
Notes:
Model Training Considerations:
Compatibility:
In addition to its video processing utilities, TripleX now includes a new captioning tool located under the /captioners directory. This new script – gemini.py – generates detailed captions for all images and videos in a specified directory. It works by processing individual frames from videos (or single images) and then composing a final, cohesive composite caption for each file. The script uses Google’s Gemini models as its backend with fallback options for reliability.
• Generates frame-level captions for videos using a configurable sampling rate (frames per second).
• Supports both video files (e.g., .mp4, .mov, .avi, .webm, etc.) and image files (e.g., .jpg, .png, .heic, etc.).
• Uses fallback Gemini models for robust caption generation in case of rate limits or resource issues.
• Creates a composite caption that unifies the descriptions from individual frames.
• Offers an optional rewriting step that reformats the composite caption into a concise and elegant narrative.
• Supports parallel processing for faster captioning of video frames.
• Optionally moves the source files and their generated caption files to a specified output directory after successful processing.
Ensure all dependencies are installed (listed in requirements.txt – additional packages used by Gemini captioner include cv2 (OpenCV), google-generativeai, and python-dotenv).
Set your Gemini API key as an environment variable. You can add the following entry to your .env file at the root of the repository:
GEMINI_API_KEY=your_gemini_api_key_here
This key is required to authenticate with the Gemini API. If you are not already using a .env file for other credentials, consider creating one and adding it to your .gitignore.
Run the captioner from the command line by specifying the directory containing video and/or image files:
python captioners/gemini.py --dir <path_to_media_directory>
The script supports additional options:
--fps
--max_frames
--output_dir
--custom_prompt
To caption all media files in the media folder at 1 FPS sampling, with a custom prompt and move completed files to finished_captions:
python captioners/gemini.py --dir media --fps 1 --custom_prompt "Include specific observations about background and accessories." --output_dir finished_captions
--fps flag). Each frame is encoded as a JPEG and sent to the Gemini API for caption generation, making use of parallel processing to speed up the workflow.TripleX now includes a script that can directly process entire video files using Google’s Vertex AI service. Unlike the Gemini-based captioner, which focuses on individual frames or images, this script uploads each video to a Google Cloud Storage (GCS) bucket and then queries Vertex AI to generate a JSON-formatted caption (including timestamps) describing the entire video.
A Google Cloud Platform (GCP) project with the following roles granted to the service account you will use:
• Service Usage Consumer
• Storage Admin
• Vertex AI Administrator
A GCS bucket where your video files will be uploaded before caption generation.
A service account JSON key file to authenticate with Google Cloud. Store this key in a secure location and set the environment variable to point to it (for example):
export GOOGLE_APPLICATION_CREDENTIALS="/path/to/your-service-acct-key.json"
Dependencies for Vertex AI and the GCS Python client (e.g., google-cloud-storage, vertexai, google-cloud-aiplatform) installed in your environment. Make sure these are in your requirements.txt or installed manually: pip install google-cloud-storage google-cloud-aiplatform
To run the Vertex AI captioner, use the following command from the project root (adjusting paths and arguments as needed):
python captioners/vertex_ai.py \
--dir /path/to/videos \
--bucket your-gcs-bucket \
--project your-gcp-project-id \
[--location us-central1] \
[--prompt "Custom instructions"] \
[--output_dir /path/to/output]
• --dir: Path to the local directory containing your video files.
• --bucket: Name of the GCS bucket where videos will be uploaded.
• --project: Your GCP project ID.
• --location (optional): The region for Vertex AI (defaults to us-central1).
• --prompt (optional): Custom text to refine or alter the captioning behavior.
• --output_dir (optional): Directory to which processed files (i.e., the original video, JSON output, and text caption) will be moved upon successful captioning.
When the script runs:
export GOOGLE_APPLICATION_CREDENTIALS="/path/to/your-service-acct-key.json"
python captioners/vertex_ai.py \
--dir data/videos \
--bucket my-video-bucket \
--project my-gcp-project \
--location us-central1 \
--prompt "Emphasize activities and background objects, but remain concise." \
--output_dir data/captioned_videos
After running, you’ll find three files per video in data/captioned_videos:
• Adult Content: If you are processing adult or explicit material, ensure your GCP project and usage of Vertex AI aligns with Google’s content policies and any applicable legal requirements.
• Privacy and Rights: Confirm you have rights and permission to upload and process the video files on Google’s servers.
• Costs: Vertex AI usage may incur charges. Consult Google’s documentation for pricing details.
• Troubleshooting: If you encounter “Resource exhausted” or rate-limit errors, the script will automatically try fallback models. If all attempts fail, an error is printed.
TripleX also includes a script for generating detailed captions for images using the JoyCaption2 model, which is based on LLaVA and Llama 3.1. Unlike video-based captioning tools, this script processes individual images or entire directories of images and generates a long, formal descriptive caption for each image. The captions are saved as .txt files in the same directory as the images.
Install the required dependencies in your Python environment:
pip install -r requiredments.txt
Ensure your system has a compatible GPU to run the JoyCaption2 model efficiently. If no GPU is available, the model will attempt to run on CPU (but performance may be slower).
The script will automatically download the JoyCaption2 model (fancyfeast/llama-joycaption-alpha-two-hf-llava) if it is not already available.
To run the JoyCaption2 image captioner, use the following command from the project root:
python utils/describe-image.py <image_path_or_directory>
<image_path_or_directory>: Either a single image file path or a directory containing multiple images.When executed, the script will:
models/. If not, it will download it automatically..txt file in the same directory as the image.python utils/describe-image.py data/images/example.jpg
data/images/example.txt.python utils/describe-image.py data/images/
data/images/, saving them as .txt files with the same base filenames.For an image named example.jpg, the script will generate:
example.txt containing the long descriptive caption..jpg, .jpeg, .png, .bmp, .gif, and .tiff.models/llama-joycaption-alpha-two-hf-llava/.This tool provides an efficient way to generate high-quality captions for large batches of images while leveraging state-of-the-art AI models. 🚀
Contributions are welcome! You can contribute to this project in the following ways:
download_xhamster.py to create a downloader for another site.downloaders/ Directory.utils/ directory.requirements.txt.Fork the Repository: Click the "Fork" button at the top-right corner of the repository page.
Clone Your Fork:
git clone https://github.com/your-username/TripleX.git
Create a New Branch:
git checkout -b feature/new-utility
Make Your Changes: Add your downloader or utility script.
Commit Your Changes:
git add .
git commit -m "Add new utility for dataset creation"
Push to Your Fork:
git push origin feature/new-utility
Open a Pull Request: Go to the original repository and click "New Pull Request."
Note: Be cautious about including large files (e.g., model files) in your commits. If your changes involve large files, consider alternative methods such as hosting the files externally or using Git LFS (Large File Storage).
This project is licensed under the MIT License. See the LICENSE file for details.
Thank you for using TripleX! If you have any questions or need assistance, feel free to open an issue on the repository or reach out to the maintainers.
Logging: The scripts log their activities, which can be helpful for debugging.
Error Handling: The scripts include basic error handling to inform you of issues that may arise during processing.
Dependencies: Ensure that all dependencies listed in requirements.txt are installed in your virtual environment. If you encounter issues, double-check that all required packages are installed.
# requirements.txt
requests
scenedetect
beautifulsoup4
tensorflow
opencv-python
numpy
FFmpeg: FFmpeg is a crucial dependency for video processing in this toolkit. Ensure that it is correctly installed and accessible from your system's PATH.
Python Version: This toolkit is developed for Python 3.x. Ensure you are using a compatible version of Python.
Model Files: The machine learning models required for frame analysis are downloaded using setup_models.py. Do not add these large files directly to the repository.
Git Limitations:
Using setup_models.py:
setup_models.py script handles the downloading of large model files from external sources (e.g., Google Drive) and places them in the appropriate directories.Modifying setup_models.py:
setup_models.py to include the new download links and ensure models are placed correctly.Alternative Methods:
models/ directory following the required structure.Avoid Committing Large Files:
Use External Hosting:
setup_models.py to download them.Git Large File Storage (LFS):
Feel free to reach out if you need any further assistance or have suggestions for improving the toolkit!
Python
100.0%