ariG23498 HF Staff commited on
Commit
fc27f1a
·
verified ·
1 Parent(s): 2460812

Upload Lightricks_LTX-Video_0.py with huggingface_hub

Browse files
Files changed (1) hide show
  1. Lightricks_LTX-Video_0.py +81 -0
Lightricks_LTX-Video_0.py ADDED
@@ -0,0 +1,81 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # /// script
2
+ # requires-python = ">=3.12"
3
+ # dependencies = [
4
+ # "numpy",
5
+ # "einops",
6
+ # "pandas",
7
+ # "matplotlib",
8
+ # "paddleorc",
9
+ # "protobuf",
10
+ # "torch",
11
+ # "sentencepiece",
12
+ # "torchvision",
13
+ # "transformers",
14
+ # "timm",
15
+ # "diffusers",
16
+ # "sentence-transformers",
17
+ # "accelerate",
18
+ # "peft",
19
+ # "slack-sdk",
20
+ # ]
21
+ # ///
22
+
23
+ try:
24
+ import torch
25
+ from diffusers import DiffusionPipeline
26
+ from diffusers.utils import load_image, export_to_video
27
+
28
+ # switch to "mps" for apple devices
29
+ pipe = DiffusionPipeline.from_pretrained("Lightricks/LTX-Video", dtype=torch.bfloat16, device_map="cuda")
30
+ pipe.to("cuda")
31
+
32
+ prompt = "A man with short gray hair plays a red electric guitar."
33
+ image = load_image(
34
+ "https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/diffusers/guitar-man.png"
35
+ )
36
+
37
+ output = pipe(image=image, prompt=prompt).frames[0]
38
+ export_to_video(output, "output.mp4")
39
+ with open('Lightricks_LTX-Video_0.txt', 'w', encoding='utf-8') as f:
40
+ f.write('Everything was good in Lightricks_LTX-Video_0.txt')
41
+ except Exception as e:
42
+ import os
43
+ from slack_sdk import WebClient
44
+ client = WebClient(token=os.environ['SLACK_TOKEN'])
45
+ client.chat_postMessage(
46
+ channel='#hub-model-metadata-snippets-sprint',
47
+ text='Problem in <https://huggingface.co/datasets/model-metadata/code_execution_files/blob/main/Lightricks_LTX-Video_0.txt|Lightricks_LTX-Video_0.txt>',
48
+ )
49
+
50
+ with open('Lightricks_LTX-Video_0.txt', 'a', encoding='utf-8') as f:
51
+ import traceback
52
+ f.write('''```CODE:
53
+ import torch
54
+ from diffusers import DiffusionPipeline
55
+ from diffusers.utils import load_image, export_to_video
56
+
57
+ # switch to "mps" for apple devices
58
+ pipe = DiffusionPipeline.from_pretrained("Lightricks/LTX-Video", dtype=torch.bfloat16, device_map="cuda")
59
+ pipe.to("cuda")
60
+
61
+ prompt = "A man with short gray hair plays a red electric guitar."
62
+ image = load_image(
63
+ "https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/diffusers/guitar-man.png"
64
+ )
65
+
66
+ output = pipe(image=image, prompt=prompt).frames[0]
67
+ export_to_video(output, "output.mp4")
68
+ ```
69
+
70
+ ERROR:
71
+ ''')
72
+ traceback.print_exc(file=f)
73
+
74
+ finally:
75
+ from huggingface_hub import upload_file
76
+ upload_file(
77
+ path_or_fileobj='Lightricks_LTX-Video_0.txt',
78
+ repo_id='model-metadata/code_execution_files',
79
+ path_in_repo='Lightricks_LTX-Video_0.txt',
80
+ repo_type='dataset',
81
+ )