### Install Dolphin Dependencies Source: https://github.com/kaleido-lab/dolphin/blob/main/README.md Use conda to manage the environment and install project dependencies. Python 3.8 is recommended. ```bash conda create -n dolphin python=3.8 conda activate dolphin git clone https://github.com/BUAA-PrismGroup/dolphin.git cd dolphin pip install -r requirements.txt ``` -------------------------------- ### Install Dependencies and Launch Dolphin Source: https://context7.com/kaleido-lab/dolphin/llms.txt Install necessary dependencies using conda and pip. Launch the application with default settings, specific models, or CPU-only mode. You can also specify a custom configuration file and port. ```bash # Install dependencies (Python 3.8, CUDA 11.3) conda create -n dolphin python=3.8 conda activate dolphin pip install -r requirements.txt ``` ```bash # Start with all models on 4 GPUs (uses configs/backends.yaml) python video_chatgpt.py ``` ```bash # Start with only specific models to save GPU memory # Format: ModelName_device, comma-separated python video_chatgpt.py --load VideoCaptioning_cuda:0,MoviepyInterface_cpu,ModelscopeT2V_cpu ``` ```bash # CPU-only mode python video_chatgpt.py --load VideoCaptioning_cpu,ImageCaptioning_cpu,ModelscopeT2V_cpu ``` ```bash # Custom config file and port python video_chatgpt.py --cfg ./configs/backends.yaml --port 7890 ``` -------------------------------- ### Run Dolphin on CPU Source: https://github.com/kaleido-lab/dolphin/blob/main/README.md Start the Dolphin application with specific models loaded on the CPU. This is recommended for users without a GPU. ```bash python video_chatgpt.py --load VideoCaptioning_cpu,ImageCaptioning_cpu,ModelscopeT2V_cpu ``` -------------------------------- ### Conditioned Video Generation Source: https://context7.com/kaleido-lab/dolphin/llms.txt Generates new videos guided by a structural control signal (canny edges, pose skeleton, or depth map) plus a text prompt. Input is a comma-separated string of control video path and text prompt. ```python from modules.text2video_zero import CannyText2Video, PoseText2Video, DepthText2Video # Generate video from canny edges + text canny2vid = CannyText2Video(device="cuda:2") result = canny2vid.inference("video/edge_clip.mp4, a robot dancing in a futuristic city") print(result) # "video/xxxx_canny2video_....mp4" # Generate video from pose skeleton + text pose2vid = PoseText2Video(device="cuda:2") result = pose2vid.inference("video/pose_clip.mp4, an astronaut performing ballet") print(result) # "video/xxxx_pose2video_....mp4" # Generate video from depth map + text depth2vid = DepthText2Video(device="cuda:2") result = depth2vid.inference("video/depth_clip.mp4, a golden retriever running through snow") print(result) # "video/xxxx_depth2video_....mp4" ``` -------------------------------- ### Conditioned Video Generation Source: https://context7.com/kaleido-lab/dolphin/llms.txt Generates new videos guided by a structural control signal (canny edges, pose skeleton, or depth map) plus a text prompt, using Text2Video-Zero with ControlNet. ```APIDOC ## CannyText2Video, PoseText2Video, DepthText2Video ### Description Generate new videos guided by a structural control signal (canny edges, pose skeleton, or depth map) plus a text prompt, using Text2Video-Zero with ControlNet. Input is a comma-separated string of the control video path and the text prompt. ### Methods - `CannyText2Video(device)`: Initializes the Canny-guided video generator. `device` can be a string like "cuda:0". - `PoseText2Video(device)`: Initializes the Pose-guided video generator. `device` can be a string like "cuda:0". - `DepthText2Video(device)`: Initializes the Depth-guided video generator. `device` can be a string like "cuda:0". ### Inference - `canny2vid.inference(input_string)`: Generates a video from canny edges and a text prompt. `input_string` format: "video/edge_clip.mp4, a robot dancing in a futuristic city". - `pose2vid.inference(input_string)`: Generates a video from pose skeleton and a text prompt. `input_string` format: "video/pose_clip.mp4, an astronaut performing ballet". - `depth2vid.inference(input_string)`: Generates a video from a depth map and a text prompt. `input_string` format: "video/depth_clip.mp4, a golden retriever running through snow". ### Returns All inference methods return the path to the generated video file (e.g., "video/xxxx_canny2video_....mp4"). ``` -------------------------------- ### Configure New Video Foundation Model in backends.yaml Source: https://github.com/kaleido-lab/dolphin/blob/main/README.md This YAML configuration defines a new video foundation model, 'FaceText2Video', specifying its target class path and initialization parameters. It also includes a tool definition for this model, detailing its name, description, instance, and inference function. ```yaml model_zoos: FaceText2Video: # foundation model class target: modules.face2video.FaceText2Video # path of the class in project params: # params passed to the class device: cuda:0 tools: # - name: tool name # desc: description about new tool # instance: keep the name consistent with the one in the model_zoos section mentioned above # func: inference function in foundation model class - name: Generate Video Condition On Face Video desc: "useful when you want to generate a new video from both the user description and a facial keypoints video. / like: generate a new video of a human face from this human face video, or can you generate a video based on both the text 'A boy is playing basketball.' and this face video. / The input to this tool should be a comma separated string of two, representing the video_path and the user description. " instance: FaceText2Video func: inference ``` -------------------------------- ### Initialize Text-to-Video Generation with Control Source: https://github.com/kaleido-lab/dolphin/blob/main/inference.ipynb Initializes various text-to-video models that utilize control mechanisms like Canny, Pose, and Depth, along with a VideoPix2Pix model. All require a CUDA-enabled device. ```python from modules.text2video_zero import CannyText2Video, PoseText2Video, DepthText2Video, VideoPix2Pix pose_text2video = PoseText2Video("cuda:5").inference # input: f"{video_path}, {prompt}", output: new_video_path canny_text2video = CannyText2Video("cuda:5").inference # input: f"{video_path}, {prompt}", output: new_video_path depth_text2video = DepthText2Video("cuda:5").inference # input: f"{video_path}, {prompt}", output: new_video_path video_pix2pix = VideoPix2Pix("cuda:5").inference # input: f"{video_path}, {prompt}", output: new_video_path ``` -------------------------------- ### Text-to-Video Generation (ModelScope) Source: https://context7.com/kaleido-lab/dolphin/llms.txt Generates a short video from a text prompt using the damo-vilab/text-to-video-ms-1.7b diffusion model. Offers a basic inference method and a lower-level generate_video method for more control. ```python from modules.modelscope_t2v import ModelscopeT2V t2v = ModelscopeT2V(device="cuda:3") # Basic text-to-video video_path = t2v.inference("A panda eating bamboo in a misty forest") print(video_path) # "video/f3a1b2c4.mp4" # Use the lower-level method for more control custom_path = t2v.generate_video( prompt="A spaceship landing on Mars at sunset", seed=42, num_frames=16, num_inference_steps=25, out_file="video/mars_landing.mp4", ) print(custom_path) # "video/mars_landing.mp4" ``` -------------------------------- ### Load and Preprocess Video Frames Source: https://context7.com/kaleido-lab/dolphin/llms.txt The `prepare_video` function loads video files using decord, resamples frames to a target FPS, resizes them, and optionally normalizes pixel values. It returns a float tensor and the output FPS. ```python from video_utils import prepare_video import torch # Load full video at native FPS, resize to 512px, normalized video_tensor, fps = prepare_video( video_path="video/sample.mp4", resolution=512, device=torch.device("cuda:0"), dtype=torch.float16, normalize=True, # pixel values in [-1, 1] start_t=0, end_t=-1, # -1 means full duration output_fps=-1, # -1 uses native FPS ) print(video_tensor.shape) # torch.Size([48, 3, 512, 288]) (F, C, H, W) print(fps) # 24 # Load a 5-second clip without normalization (for annotators) clip, fps = prepare_video("video/sample.mp4", 512, "cpu", normalize=False, start_t=3.0, end_t=8.0) print(clip.shape) # torch.Size([120, 3, 512, 288]) print(clip.min(), clip.max()) # tensor(0.) tensor(255.) ``` -------------------------------- ### Pose-Guided Text-to-Video Generation Source: https://github.com/kaleido-lab/dolphin/blob/main/inference.ipynb Generates a video based on a human pose and a text description. Requires paths to the pose video and a text prompt. ```python print("./" + pose_text2video("video/0d50_human-pose_1759_v0006.mp4, an astronaut dancing on the moon")) ``` -------------------------------- ### Run Dolphin with GPU Acceleration Source: https://github.com/kaleido-lab/dolphin/blob/main/README.md Launch the Dolphin application, allowing it to utilize available GPUs. Model and device assignments can be configured in `configs/backend.yaml` for optimal performance. ```bash python video_chatgpt.py ``` -------------------------------- ### Initialize BLIP2 Image Captioning Source: https://github.com/kaleido-lab/dolphin/blob/main/inference.ipynb Initializes the BLIP2 model for image captioning, which can be used on video frames. Requires a CUDA-enabled device. ```python from modules.blip import ImageCaptioning tool_blip2 = ImageCaptioning("cuda:0") frames_captioning = tool_blip2.inference # input: f"{video_path}", output: caption (str) ``` -------------------------------- ### Initialize Modelscope Text-to-Video Generation Source: https://github.com/kaleido-lab/dolphin/blob/main/inference.ipynb Initializes the ModelscopeT2V model for generating videos from text descriptions. Requires a CUDA-enabled device. ```python from modules.modelscope_t2v import ModelscopeT2V mst2v = ModelscopeT2V("cuda:1") text2video = mst2v.inference # input: f"{description}", output: new_video_path ``` -------------------------------- ### Configure Model Zoo and Tools in YAML Source: https://context7.com/kaleido-lab/dolphin/llms.txt Define foundation models and their exposure as agent tools in the `configs/backends.yaml` file. Specify the Python class path and constructor parameters for models, and map natural language names and descriptions to tool instances and their methods. ```yaml model_zoos: VideoCaptioning: target: modules.mplug.VideoCaptioning params: device: cuda:0 ModelscopeT2V: target: modules.modelscope_t2v.ModelscopeT2V params: device: cuda:1 # Add a custom model: FaceText2Video: target: modules.face2video.FaceText2Video params: device: cuda:2 tools: - name: Get Video Description desc: "useful when you want to know what the video shows. The input should be the video_path string." instance: VideoCaptioning func: inference - name: Generate Video Condition On Text desc: "useful when you want to generate a video from text. The input should be a text string." instance: ModelscopeT2V func: inference # Register the custom tool: - name: Generate Video Condition On Face Video desc: "useful when you want to generate a new video from a face video and a text description. The input should be a comma-separated string of video_path and user description." instance: FaceText2Video func: inference ``` -------------------------------- ### Initialize mPLUG Video Captioning Source: https://github.com/kaleido-lab/dolphin/blob/main/inference.ipynb Initializes the mPLUG model for video captioning. Requires a CUDA-enabled device. ```python from modules.mplug import VideoCaptioning tool_vc = VideoCaptioning("cuda:7") video_captioning = tool_vc.inference # input: f"{video_path}", output: caption (str) ``` -------------------------------- ### Dynamically Instantiate Models from Config Source: https://context7.com/kaleido-lab/dolphin/llms.txt Use `utils.instantiate_from_config` to load and instantiate Python classes based on a YAML configuration. This is the primary method for building model zoo objects at startup. Ensure the configuration file is loaded using `OmegaConf.load`. ```python from omegaconf import OmegaConf import utils # Load config and instantiate a single model programmatically cfg = OmegaConf.load("configs/backends.yaml") video_caption_cfg = cfg.model_zoos["VideoCaptioning"] # {"target": "modules.mplug.VideoCaptioning", "params": {"device": "cuda:0"}} model = utils.instantiate_from_config(video_caption_cfg) # Equivalent to: from modules.mplug import VideoCaptioning; model = VideoCaptioning(device="cuda:0") result = model.inference("video/sample.mp4") print(result) # "A dog is running in a grassy park near a lake." ``` -------------------------------- ### Initialize Text2Audio from Bark Source: https://github.com/kaleido-lab/dolphin/blob/main/inference.ipynb Initializes the Text2Audio tool from the Bark module and exposes its text-to-audio and text-to-music functions. Use these functions for audio generation from text. ```python from modules.bark import Text2Audio tool_t2a = Text2Audio() text2audio = tool_t2a.text2audio # input: f"{text}", output: audio_path text2music = tool_t2a.text2music # input: f"{text}", output: audio_path ``` -------------------------------- ### Video Captioning with mPLUG Source: https://context7.com/kaleido-lab/dolphin/llms.txt Generates a single natural-language description for an entire video using the mPLUG model. Downloads model weights on first use. ```python from modules.mplug import VideoCaptioning model = VideoCaptioning(device="cuda:0") # Prints: "Initializing mPLUG for VideoCaptioning" caption = model.inference("video/skateboard_clip.mp4") print(caption) ``` -------------------------------- ### ModelscopeT2V Source: https://context7.com/kaleido-lab/dolphin/llms.txt Generates a short video from a text prompt using the `damo-vilab/text-to-video-ms-1.7b` diffusion model. ```APIDOC ## ModelscopeT2V ### Description Generates a short video (16 frames at 8 fps) from a text prompt using the `damo-vilab/text-to-video-ms-1.7b` diffusion model with DPM-Solver++ scheduling and VAE slicing enabled. ### Method - `ModelscopeT2V(device)`: Initializes the text-to-video generation model. `device` can be a string like "cuda:0". ### Inference - `t2v.inference(prompt)`: Generates a video from a text prompt. - `t2v.generate_video(prompt, seed, num_frames, num_inference_steps, out_file)`: A lower-level method for more control over video generation parameters. ### Parameters for `generate_video` - `prompt` (string): The text description for the video. - `seed` (int): The random seed for generation. - `num_frames` (int): The number of frames in the generated video. - `num_inference_steps` (int): The number of inference steps. - `out_file` (string): The path to save the output video. ### Returns Both `inference` and `generate_video` return the path to the generated video file (e.g., "video/f3a1b2c4.mp4"). ``` -------------------------------- ### Depth-Guided Text-to-Video Generation Source: https://github.com/kaleido-lab/dolphin/blob/main/inference.ipynb Generates a video based on depth information and a text description. Requires paths to the depth video and a text prompt. ```python print("./" + depth_text2video("video/7574_depth_235ee6b2_235ee6b2.mp4, a tiger")) ``` -------------------------------- ### VideoCaptioning (mPLUG) Source: https://context7.com/kaleido-lab/dolphin/llms.txt Generates a single natural-language description for an entire video using the mPLUG model. It downloads necessary model weights on first use. ```APIDOC ## VideoCaptioning (mPLUG) — Video-Level Caption Generation Wraps the mPLUG large model to produce a single natural-language description of an entire video. On first use it downloads `ViT-L-14.tar` and `mplug_large.pth` from Aliyun OSS into `model_zoo/mplug/`. ```python from modules.mplug import VideoCaptioning model = VideoCaptioning(device="cuda:0") # Prints: "Initializing mPLUG for VideoCaptioning" caption = model.inference("video/skateboard_clip.mp4") print(caption) # "A young man performs tricks on a skateboard in a city plaza while bystanders watch." ``` ``` -------------------------------- ### Initialize LangChain Agent with ConversationBot Source: https://context7.com/kaleido-lab/dolphin/llms.txt Instantiate the `ConversationBot` class, which orchestrates the model zoo, a LangChain agent, and conversation memory. Call `init_agent` with an OpenAI API key to activate the agent, specifying the desired language. ```python from omegaconf import OmegaConf from video_chatgpt import ConversationBot cfg = OmegaConf.load("configs/backends.yaml") bot = ConversationBot(cfg) # Initialize the agent (English mode) bot.init_agent(openai_api_key="sk-ինչ", lang="English") ``` -------------------------------- ### Run Video Analysis with ConversationBot Source: https://context7.com/kaleido-lab/dolphin/llms.txt The `run_video` method uploads a video, generates descriptions using captioning models, and updates the agent's memory. It returns the updated state, a video path, and text. ```python import types from video_chatgpt import ConversationBot from omegaconf import OmegaConf cfg = OmegaConf.load("configs/backends.yaml") bot = ConversationBot(cfg) bot.init_agent(openai_api_key="sk-...", lang="English") # Simulate a Gradio NamedString upload object fake_upload = types.SimpleNamespace(name="/tmp/my_clip.mp4") state = [] state, _, updated_txt = bot.run_video(fake_upload, state, txt="", lang="English") # state[-1] == ('