oahzxl commited on
Commit
9b08739
1 Parent(s): 07c6a04

update app

Browse files
Files changed (1) hide show
  1. app.py +8 -263
app.py CHANGED
@@ -1,253 +1,7 @@
1
- # # import gradio as gr
2
- # # from videosys import CogVideoConfig, VideoSysEngine
3
- # # import tempfile
4
- # # import os
5
- # # import logging
6
- # # import uuid
7
-
8
- # # logging.basicConfig(level=logging.INFO)
9
- # # logger = logging.getLogger(__name__)
10
-
11
- # # config = CogVideoConfig(world_size=1)
12
- # # engine = VideoSysEngine(config)
13
-
14
- # # def generate_video(prompt):
15
- # # try:
16
- # # video = engine.generate(prompt).video[0]
17
-
18
- # # # 使用临时文件和唯一标识符
19
- # # with tempfile.NamedTemporaryFile(delete=False, suffix=".mp4") as temp_file:
20
- # # temp_filename = temp_file.name
21
- # # unique_filename = f"{uuid.uuid4().hex}.mp4"
22
- # # output_path = os.path.join(tempfile.gettempdir(), unique_filename)
23
-
24
- # # engine.save_video(video, output_path)
25
-
26
- # # return output_path
27
- # # except Exception as e:
28
- # # logger.error(f"An error occurred: {str(e)}")
29
- # # return None # 返回 None 而不是错误消息
30
-
31
- # # iface = gr.Interface(
32
- # # fn=generate_video,
33
- # # inputs=gr.Textbox(lines=2, placeholder="Enter your prompt here..."),
34
- # # outputs=gr.Video(label="Generated Video"),
35
- # # title="CogVideoX-2b: Text-to-Video Generation",
36
- # # description="Enter a text prompt to generate a video using CogVideoX-2b."
37
- # # )
38
-
39
- # # iface.launch()
40
-
41
-
42
- # from videosys import CogVideoConfig, VideoSysEngine
43
- # from videosys.models.cogvideo.pipeline import CogVideoPABConfig
44
- # import os
45
-
46
- # import gradio as gr
47
- # import numpy as np
48
- # import torch
49
- # from openai import OpenAI
50
- # from time import time
51
- # import tempfile
52
- # import uuid
53
- # import logging
54
-
55
- # logging.basicConfig(level=logging.INFO)
56
- # logger = logging.getLogger(__name__)
57
-
58
- # dtype = torch.bfloat16
59
- # sys_prompt = """You are part of a team of bots that creates videos. You work with an assistant bot that will draw anything you say in square brackets.
60
-
61
- # For example , outputting " a beautiful morning in the woods with the sun peaking through the trees " will trigger your partner bot to output an video of a forest morning , as described. You will be prompted by people looking to create detailed , amazing videos. The way to accomplish this is to take their short prompts and make them extremely detailed and descriptive.
62
- # There are a few rules to follow:
63
-
64
- # You will only ever output a single video description per user request.
65
-
66
- # When modifications are requested , you should not simply make the description longer . You should refactor the entire description to integrate the suggestions.
67
- # Other times the user will not want modifications , but instead want a new image . In this case , you should ignore your previous conversation with the user.
68
-
69
- # Video descriptions must have the same num of words as examples below. Extra words will be ignored.
70
- # """
71
-
72
- # def convert_prompt(prompt: str, retry_times: int = 3) -> str:
73
- # if not os.environ.get("OPENAI_API_KEY"):
74
- # return prompt
75
- # client = OpenAI()
76
- # text = prompt.strip()
77
-
78
- # for i in range(retry_times):
79
- # response = client.chat.completions.create(
80
- # messages=[
81
- # {"role": "system", "content": sys_prompt},
82
- # {
83
- # "role": "user",
84
- # "content": 'Create an imaginative video descriptive caption or modify an earlier caption for the user input : "a girl is on the beach"',
85
- # },
86
- # {
87
- # "role": "assistant",
88
- # "content": "A radiant woman stands on a deserted beach, arms outstretched, wearing a beige trench coat, white blouse, light blue jeans, and chic boots, against a backdrop of soft sky and sea. Moments later, she is seen mid-twirl, arms exuberant, with the lighting suggesting dawn or dusk. Then, she runs along the beach, her attire complemented by an off-white scarf and black ankle boots, the tranquil sea behind her. Finally, she holds a paper airplane, her pose reflecting joy and freedom, with the ocean's gentle waves and the sky's soft pastel hues enhancing the serene ambiance.",
89
- # },
90
- # {
91
- # "role": "user",
92
- # "content": 'Create an imaginative video descriptive caption or modify an earlier caption for the user input : "A man jogging on a football field"',
93
- # },
94
- # {
95
- # "role": "assistant",
96
- # "content": "A determined man in athletic attire, including a blue long-sleeve shirt, black shorts, and blue socks, jogs around a snow-covered soccer field, showcasing his solitary exercise in a quiet, overcast setting. His long dreadlocks, focused expression, and the serene winter backdrop highlight his dedication to fitness. As he moves, his attire, consisting of a blue sports sweatshirt, black athletic pants, gloves, and sneakers, grips the snowy ground. He is seen running past a chain-link fence enclosing the playground area, with a basketball hoop and children's slide, suggesting a moment of solitary exercise amidst the empty field.",
97
- # },
98
- # {
99
- # "role": "user",
100
- # "content": 'Create an imaginative video descriptive caption or modify an earlier caption for the user input : " A woman is dancing, HD footage, close-up"',
101
- # },
102
- # {
103
- # "role": "assistant",
104
- # "content": "A young woman with her hair in an updo and wearing a teal hoodie stands against a light backdrop, initially looking over her shoulder with a contemplative expression. She then confidently makes a subtle dance move, suggesting rhythm and movement. Next, she appears poised and focused, looking directly at the camera. Her expression shifts to one of introspection as she gazes downward slightly. Finally, she dances with confidence, her left hand over her heart, symbolizing a poignant moment, all while dressed in the same teal hoodie against a plain, light-colored background.",
105
- # },
106
- # {
107
- # "role": "user",
108
- # "content": f'Create an imaginative video descriptive caption or modify an earlier caption in ENGLISH for the user input: "{text}"',
109
- # },
110
- # ],
111
- # model="glm-4-0520",
112
- # temperature=0.01,
113
- # top_p=0.7,
114
- # stream=False,
115
- # max_tokens=250,
116
- # )
117
- # if response.choices:
118
- # return response.choices[0].message.content
119
- # return prompt
120
-
121
- # def load_model(enable_video_sys=False, pab_threshold=[100, 850], pab_gap=2):
122
- # pab_config = CogVideoPABConfig(full_threshold=pab_threshold, full_gap=pab_gap)
123
- # config = CogVideoConfig(world_size=1, enable_pab=enable_video_sys, pab_config=pab_config)
124
- # engine = VideoSysEngine(config)
125
- # return engine
126
-
127
-
128
-
129
- # def generate(engine, prompt, num_inference_steps=50, guidance_scale=6.0):
130
- # try:
131
- # video = engine.generate(prompt, num_inference_steps=num_inference_steps, guidance_scale=guidance_scale).video[0]
132
-
133
- # with tempfile.NamedTemporaryFile(delete=False, suffix=".mp4") as temp_file:
134
- # temp_file.name
135
- # unique_filename = f"{uuid.uuid4().hex}.mp4"
136
- # output_path = os.path.join(tempfile.gettempdir(), unique_filename)
137
-
138
- # engine.save_video(video, output_path)
139
- # return output_path
140
- # except Exception as e:
141
- # logger.error(f"An error occurred: {str(e)}")
142
- # return None
143
-
144
-
145
-
146
- # with gr.Blocks() as demo:
147
- # gr.Markdown("""
148
- # <div style="text-align: center; font-size: 32px; font-weight: bold; margin-bottom: 20px;">
149
- # VideoSys Huggingface Space🤗
150
- # </div>
151
- # <div style="text-align: center;">
152
- # <a href="https://github.com/NUS-HPC-AI-Lab/VideoSys">🌐 Github</a>
153
- # </div>
154
-
155
- # <div style="text-align: center; font-size: 15px; font-weight: bold; color: red; margin-bottom: 20px;">
156
- # ⚠️ This demo is for academic research and experiential use only.
157
- # Users should strictly adhere to local laws and ethics.
158
- # </div>
159
- # <div style="text-align: center; font-size: 15px; font-weight: bold; color: magenta; margin-bottom: 20px;">
160
- # 💡 This demo only demonstrates single-device inference. To experience the full power of VideoSys, please deploy it with multiple devices.
161
- # </div>
162
- # """)
163
- # with gr.Row():
164
- # with gr.Column():
165
- # prompt = gr.Textbox(label="Prompt (Less than 200 Words)", value="a bear hunting for prey", lines=5)
166
- # with gr.Row():
167
- # gr.Markdown(
168
- # "✨Upon pressing the enhanced prompt button, we will use [GLM-4 Model](https://github.com/THUDM/GLM-4) to polish the prompt and overwrite the original one."
169
- # )
170
- # enhance_button = gr.Button("✨ Enhance Prompt(Optional)")
171
-
172
- # with gr.Column():
173
- # gr.Markdown(
174
- # "**Optional Parameters** (default values are recommended)<br>"
175
- # "Turn Inference Steps larger if you want more detailed video, but it will be slower.<br>"
176
- # "50 steps are recommended for most cases. will cause 120 seconds for inference.<br>"
177
- # )
178
- # with gr.Row():
179
- # num_inference_steps = gr.Number(label="Inference Steps", value=50)
180
- # guidance_scale = gr.Number(label="Guidance Scale", value=6.0)
181
- # pab_gap = gr.Number(label="PAB Gap", value=2, precision=0)
182
- # pab_threshold = gr.Textbox(label="PAB Threshold", value="100,850", lines=1)
183
- # with gr.Row():
184
- # generate_button = gr.Button("🎬 Generate Video")
185
- # generate_button_vs = gr.Button("⚡️ Generate Video with VideoSys (Faster)")
186
-
187
- # with gr.Column():
188
- # with gr.Row():
189
- # video_output = gr.Video(label="CogVideoX", width=720, height=480)
190
- # with gr.Row():
191
- # download_video_button = gr.File(label="📥 Download Video", visible=False)
192
- # elapsed_time = gr.Textbox(label="Elapsed Time", value="0s", visible=False)
193
- # with gr.Row():
194
- # video_output_vs = gr.Video(label="CogVideoX with VideoSys", width=720, height=480)
195
- # with gr.Row():
196
- # download_video_button_vs = gr.File(label="📥 Download Video", visible=False)
197
- # elapsed_time_vs = gr.Textbox(label="Elapsed Time", value="0s", visible=False)
198
-
199
- # def generate_vanilla(prompt, num_inference_steps, guidance_scale, progress=gr.Progress(track_tqdm=True)):
200
- # # tensor = infer(prompt, num_inference_steps, guidance_scale, progress=progress)
201
- # engine = load_model()
202
- # t = time()
203
- # video_path = generate(engine, prompt, num_inference_steps, guidance_scale)
204
- # elapsed_time = time() - t
205
- # video_update = gr.update(visible=True, value=video_path)
206
- # elapsed_time = gr.update(visible=True, value=f"{elapsed_time:.2f}s")
207
-
208
- # return video_path, video_update, elapsed_time
209
-
210
- # def generate_vs(prompt, num_inference_steps, guidance_scale, threshold, gap, progress=gr.Progress(track_tqdm=True)):
211
- # # tensor = infer(prompt, num_inference_steps, guidance_scale, progress=progress)
212
- # threshold = [int(i) for i in threshold.split(",")]
213
- # gap = int(gap)
214
- # engine = load_model(enable_video_sys=True, pab_threshold=threshold, pab_gap=gap)
215
- # t = time()
216
- # video_path = generate(engine, prompt, num_inference_steps, guidance_scale)
217
- # elapsed_time = time() - t
218
- # video_update = gr.update(visible=True, value=video_path)
219
- # elapsed_time = gr.update(visible=True, value=f"{elapsed_time:.2f}s")
220
-
221
- # return video_path, video_update, elapsed_time
222
-
223
-
224
- # def enhance_prompt_func(prompt):
225
- # return convert_prompt(prompt, retry_times=1)
226
-
227
- # generate_button.click(
228
- # generate_vanilla,
229
- # inputs=[prompt, num_inference_steps, guidance_scale],
230
- # outputs=[video_output, download_video_button, elapsed_time],
231
- # )
232
-
233
- # generate_button_vs.click(
234
- # generate_vs,
235
- # inputs=[prompt, num_inference_steps, guidance_scale, pab_threshold, pab_gap],
236
- # outputs=[video_output_vs, download_video_button_vs, elapsed_time_vs],
237
- # )
238
-
239
- # enhance_button.click(enhance_prompt_func, inputs=[prompt], outputs=[prompt])
240
-
241
- # if __name__ == "__main__":
242
- # demo.launch()
243
-
244
-
245
-
246
  import gradio as gr
247
  from videosys import CogVideoConfig, VideoSysEngine
248
  from videosys.models.cogvideo.pipeline import CogVideoPABConfig
249
  import os
250
- import numpy as np
251
  import torch
252
  from openai import OpenAI
253
  from time import time
@@ -347,7 +101,6 @@ body {
347
  font-family: Arial, sans-serif;
348
  line-height: 1.6;
349
  color: #333;
350
- max-width: 1200px;
351
  margin: 0 auto;
352
  padding: 20px;
353
  }
@@ -369,13 +122,6 @@ body {
369
  min-width: 0;
370
  }
371
 
372
- .textbox, .number-input, button {
373
- width: 100%;
374
- padding: 10px;
375
- margin-bottom: 10px;
376
- border: 1px solid #ddd;
377
- border-radius: 4px;
378
- }
379
 
380
  button {
381
  background-color: #4CAF50;
@@ -417,15 +163,14 @@ with gr.Blocks(css=css) as demo:
417
  <div style="text-align: center; font-size: 32px; font-weight: bold; margin-bottom: 20px;">
418
  VideoSys Huggingface Space🤗
419
  </div>
420
- <div style="text-align: center;">
421
- <a href="https://github.com/NUS-HPC-AI-Lab/VideoSys">🌐 Github</a>
422
- </div>
423
- <div style="text-align: center; font-size: 15px; font-weight: bold; color: red; margin-bottom: 20px;">
424
  ⚠️ This demo is for academic research and experiential use only.
425
- Users should strictly adhere to local laws and ethics.
426
- </div>
427
- <div style="text-align: center; font-size: 15px; font-weight: bold; color: magenta; margin-bottom: 20px;">
428
- 💡 This demo only demonstrates single-device inference. To experience the full power of VideoSys, please deploy it with multiple devices.
429
  </div>
430
  """)
431
 
@@ -505,4 +250,4 @@ with gr.Blocks(css=css) as demo:
505
  enhance_button.click(enhance_prompt_func, inputs=[prompt], outputs=[prompt])
506
 
507
  if __name__ == "__main__":
508
- demo.launch()
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  import gradio as gr
2
  from videosys import CogVideoConfig, VideoSysEngine
3
  from videosys.models.cogvideo.pipeline import CogVideoPABConfig
4
  import os
 
5
  import torch
6
  from openai import OpenAI
7
  from time import time
 
101
  font-family: Arial, sans-serif;
102
  line-height: 1.6;
103
  color: #333;
 
104
  margin: 0 auto;
105
  padding: 20px;
106
  }
 
122
  min-width: 0;
123
  }
124
 
 
 
 
 
 
 
 
125
 
126
  button {
127
  background-color: #4CAF50;
 
163
  <div style="text-align: center; font-size: 32px; font-weight: bold; margin-bottom: 20px;">
164
  VideoSys Huggingface Space🤗
165
  </div>
166
+ <div style="text-align: center; font-size: 15px;">
167
+ 🌐 Github: <a href="https://github.com/NUS-HPC-AI-Lab/VideoSys">https://github.com/NUS-HPC-AI-Lab/VideoSys</a><br>
168
+
 
169
  ⚠️ This demo is for academic research and experiential use only.
170
+ Users should strictly adhere to local laws and ethics.<br>
171
+
172
+ 💡 This demo only demonstrates single-device inference. To experience the full power of VideoSys, please deploy it with multiple devices.<br><br>
173
+ </div>
174
  </div>
175
  """)
176
 
 
250
  enhance_button.click(enhance_prompt_func, inputs=[prompt], outputs=[prompt])
251
 
252
  if __name__ == "__main__":
253
+ demo.launch()