-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #42 from TIGER-AI-Lab/arena
Adapting arena build into main build
- Loading branch information
Showing
97 changed files
with
86 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
__version__ = "0.1.2" | ||
__version__ = "0.1.4a0" |
Empty file.
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
import torch | ||
|
||
class CogVideoX: | ||
def __init__(self, weight="THUDM/CogVideoX-2b", device="cuda"): | ||
""" | ||
Initializes the CogVideo model with a specific device. | ||
Args: | ||
device (str, optional): The device to run the model on. Defaults to "cuda". | ||
""" | ||
from diffusers import CogVideoXPipeline | ||
|
||
self.pipe = CogVideoXPipeline.from_pretrained(weight).to("cuda") | ||
|
||
def infer_one_video( | ||
self, | ||
prompt: str = None, | ||
size: list = [320, 512], | ||
seconds: int = 2, | ||
fps: int = 8, | ||
seed: int = 42, | ||
): | ||
""" | ||
Generates a single video based on the provided prompt and parameters. | ||
Args: | ||
prompt (str, optional): The text prompt to generate the video from. Defaults to None. | ||
size (list, optional): The size of the video as [height, width]. Defaults to [320, 512]. | ||
seconds (int, optional): The duration of the video in seconds. Defaults to 2. | ||
fps (int, optional): The frames per second of the video. Defaults to 8. | ||
seed (int, optional): The seed for random number generation. Defaults to 42. | ||
Returns: | ||
torch.Tensor: The generated video as a tensor. | ||
""" | ||
|
||
video = self.pipe(prompt=prompt, | ||
guidance_scale=6, | ||
num_frames=seconds * fps, | ||
#height=size[0], | ||
#width=size[1], | ||
num_inference_steps=50, | ||
generator=torch.manual_seed(seed)).frames[0] | ||
from videogen_hub.utils import images_to_tensor | ||
video = video[:-1] # drop the last frame | ||
video = images_to_tensor(video) # parse it back to tensor (T, C, H, W) | ||
|
||
return video |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
|
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import torch | ||
from torchvision import transforms | ||
from PIL import Image | ||
|
||
def images_to_tensor(image_list): | ||
""" | ||
Parse a list of PIL images and convert them to a PyTorch tensor in shape (T, C, H, W). | ||
""" | ||
transform = transforms.ToTensor() | ||
|
||
# Convert each PIL image to tensor and store in a list | ||
tensor_list = [transform(img) for img in image_list] | ||
|
||
# Stack the list of tensors along a new dimension to create the final tensor | ||
tensor = torch.stack(tensor_list, dim=0) | ||
|
||
return tensor |