lysandre HF staff commited on
Commit
3366701
0 Parent(s):

Initial commit

Browse files
Files changed (7) hide show
  1. .gitattributes +34 -0
  2. README.md +12 -0
  3. __init__.py +0 -0
  4. app.py +4 -0
  5. requirements.txt +4 -0
  6. text_to_video.py +49 -0
  7. tool_config.json +3 -0
.gitattributes ADDED
@@ -0,0 +1,34 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ *.7z filter=lfs diff=lfs merge=lfs -text
2
+ *.arrow filter=lfs diff=lfs merge=lfs -text
3
+ *.bin filter=lfs diff=lfs merge=lfs -text
4
+ *.bz2 filter=lfs diff=lfs merge=lfs -text
5
+ *.ckpt filter=lfs diff=lfs merge=lfs -text
6
+ *.ftz filter=lfs diff=lfs merge=lfs -text
7
+ *.gz filter=lfs diff=lfs merge=lfs -text
8
+ *.h5 filter=lfs diff=lfs merge=lfs -text
9
+ *.joblib filter=lfs diff=lfs merge=lfs -text
10
+ *.lfs.* filter=lfs diff=lfs merge=lfs -text
11
+ *.mlmodel filter=lfs diff=lfs merge=lfs -text
12
+ *.model filter=lfs diff=lfs merge=lfs -text
13
+ *.msgpack filter=lfs diff=lfs merge=lfs -text
14
+ *.npy filter=lfs diff=lfs merge=lfs -text
15
+ *.npz filter=lfs diff=lfs merge=lfs -text
16
+ *.onnx filter=lfs diff=lfs merge=lfs -text
17
+ *.ot filter=lfs diff=lfs merge=lfs -text
18
+ *.parquet filter=lfs diff=lfs merge=lfs -text
19
+ *.pb filter=lfs diff=lfs merge=lfs -text
20
+ *.pickle filter=lfs diff=lfs merge=lfs -text
21
+ *.pkl filter=lfs diff=lfs merge=lfs -text
22
+ *.pt filter=lfs diff=lfs merge=lfs -text
23
+ *.pth filter=lfs diff=lfs merge=lfs -text
24
+ *.rar filter=lfs diff=lfs merge=lfs -text
25
+ *.safetensors filter=lfs diff=lfs merge=lfs -text
26
+ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
27
+ *.tar.* filter=lfs diff=lfs merge=lfs -text
28
+ *.tflite filter=lfs diff=lfs merge=lfs -text
29
+ *.tgz filter=lfs diff=lfs merge=lfs -text
30
+ *.wasm filter=lfs diff=lfs merge=lfs -text
31
+ *.xz filter=lfs diff=lfs merge=lfs -text
32
+ *.zip filter=lfs diff=lfs merge=lfs -text
33
+ *.zst filter=lfs diff=lfs merge=lfs -text
34
+ *tfevents* filter=lfs diff=lfs merge=lfs -text
README.md ADDED
@@ -0,0 +1,12 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ title: Text to Video
3
+ emoji: ⚡
4
+ colorFrom: red
5
+ colorTo: green
6
+ sdk: gradio
7
+ sdk_version: 3.27.0
8
+ app_file: app.py
9
+ pinned: false
10
+ tags:
11
+ - tool
12
+ ---
__init__.py ADDED
File without changes
app.py ADDED
@@ -0,0 +1,4 @@
 
 
 
 
 
1
+ from transformers.tools.base import launch_gradio_demo
2
+ from text_to_image import TextToVideoTool
3
+
4
+ launch_gradio_demo(TextToVideoTool)
requirements.txt ADDED
@@ -0,0 +1,4 @@
 
 
 
 
 
1
+ transformers @ git+https://github.com/huggingface/transformers@test_composition
2
+ diffusers
3
+ accelerate
4
+ torch
text_to_video.py ADDED
@@ -0,0 +1,49 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import torch
2
+
3
+ from transformers.tools.base import Tool, get_default_device
4
+ from transformers.utils import is_accelerate_available, is_diffusers_available
5
+
6
+ if is_diffusers_available():
7
+ from diffusers import DiffusionPipeline
8
+
9
+
10
+ TEXT_TO_VIDEO_DESCRIPTION = (
11
+ "This is a tool that creates a video according to a text description. It takes an input named `prompt` which "
12
+ "contains the image description, as well as an optional input `seconds` which will be the duration of the video. "
13
+ "The default is of two seconds. The tool outputs a video object."
14
+ )
15
+
16
+
17
+ class TextToVideoTool(Tool):
18
+ default_checkpoint = "damo-vilab/text-to-video-ms-1.7b"
19
+ description = TEXT_TO_VIDEO_DESCRIPTION
20
+
21
+ def __init__(self, device=None, **hub_kwargs) -> None:
22
+ if not is_accelerate_available():
23
+ raise ImportError("Accelerate should be installed in order to use tools.")
24
+ if not is_diffusers_available():
25
+ raise ImportError("Diffusers should be installed in order to use the StableDiffusionTool.")
26
+
27
+ super().__init__()
28
+
29
+ self.device = device
30
+ self.pipeline = None
31
+ self.hub_kwargs = hub_kwargs
32
+
33
+ def setup(self):
34
+ if self.device is None:
35
+ self.device = get_default_device()
36
+
37
+ self.pipeline = DiffusionPipeline.from_pretrained(
38
+ self.default_checkpoint, torch_dtype=torch.float16, variant="fp16"
39
+ )
40
+ self.pipeline.to(self.device)
41
+
42
+ self.is_initialized = True
43
+
44
+ def __call__(self, prompt, seconds=2):
45
+ if not self.is_initialized:
46
+ self.setup()
47
+
48
+ return self.pipeline(prompt, num_frames=8 * seconds).frames
49
+
tool_config.json ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ {
2
+ "custom_tools": {"text-to-video": "text_to_video.TextToVideoTool"}
3
+ }