WeichenFan commited on
Commit
df015e0
·
1 Parent(s): 4a40efc

update demo

Browse files
Files changed (1) hide show
  1. app.py +6 -107
app.py CHANGED
@@ -18,81 +18,14 @@ login(token=os.getenv('HF_TOKEN'))
18
 
19
  dtype = torch.float16
20
  device = "cuda" if torch.cuda.is_available() else "cpu"
21
- pipe = VchitectXLPipeline("Vchitect-XL/Vchitect-XL-2B",device)
22
- #VchitectXLPipeline.from_pretrained("THUDM/CogVideoX-2b", torch_dtype=dtype).to(device)
23
- #
24
  os.makedirs("./output", exist_ok=True)
25
  os.makedirs("./gradio_tmp", exist_ok=True)
26
 
27
- 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.
28
- 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.
29
- There are a few rules to follow:
30
- You will only ever output a single video description per user request.
31
- When modifications are requested , you should not simply make the description longer . You should refactor the entire description to integrate the suggestions.
32
- 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.
33
- Video descriptions must have the same num of words as examples below. Extra words will be ignored.
34
- """
35
-
36
-
37
- # def convert_prompt(prompt: str, retry_times: int = 3) -> str:
38
- # if not os.environ.get("OPENAI_API_KEY"):
39
- # return prompt
40
- # client = OpenAI()
41
- # text = prompt.strip()
42
-
43
- # for i in range(retry_times):
44
- # response = client.chat.completions.create(
45
- # messages=[
46
- # {"role": "system", "content": sys_prompt},
47
- # {
48
- # "role": "user",
49
- # "content": 'Create an imaginative video descriptive caption or modify an earlier caption for the user input : "a girl is on the beach"',
50
- # },
51
- # {
52
- # "role": "assistant",
53
- # "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.",
54
- # },
55
- # {
56
- # "role": "user",
57
- # "content": 'Create an imaginative video descriptive caption or modify an earlier caption for the user input : "A man jogging on a football field"',
58
- # },
59
- # {
60
- # "role": "assistant",
61
- # "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.",
62
- # },
63
- # {
64
- # "role": "user",
65
- # "content": 'Create an imaginative video descriptive caption or modify an earlier caption for the user input : " A woman is dancing, HD footage, close-up"',
66
- # },
67
- # {
68
- # "role": "assistant",
69
- # "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.",
70
- # },
71
- # {
72
- # "role": "user",
73
- # "content": f'Create an imaginative video descriptive caption or modify an earlier caption in ENGLISH for the user input: "{text}"',
74
- # },
75
- # ],
76
- # model="glm-4-0520",
77
- # temperature=0.01,
78
- # top_p=0.7,
79
- # stream=False,
80
- # max_tokens=250,
81
- # )
82
- # if response.choices:
83
- # return response.choices[0].message.content
84
- # return prompt
85
-
86
  @spaces.GPU(duration=120)
87
  def infer(prompt: str, num_inference_steps: int, guidance_scale: float, progress=gr.Progress(track_tqdm=True)):
88
  torch.cuda.empty_cache()
89
- # video = pipe(
90
- # prompt=prompt,
91
- # num_videos_per_prompt=1,
92
- # num_inference_steps=num_inference_steps,
93
- # num_frames=49,
94
- # guidance_scale=guidance_scale,
95
- # ).frames[0]
96
  with torch.cuda.amp.autocast(dtype=torch.bfloat16):
97
  video = pipe(
98
  prompt,
@@ -170,9 +103,9 @@ with gr.Blocks() as demo:
170
  # "Increasing the number of inference steps will produce more detailed videos, but it will slow down the process.<br>"
171
  # "50 steps are recommended for most cases.<br>"
172
  # "For the 5B model, 50 steps will take approximately 350 seconds.")
173
- with gr.Row():
174
- num_inference_steps = gr.Number(label="Inference Steps", value=100)
175
- guidance_scale = gr.Number(label="Guidance Scale", value=7.5)
176
  generate_button = gr.Button("🎬 Generate Video")
177
 
178
  with gr.Column():
@@ -181,41 +114,7 @@ with gr.Blocks() as demo:
181
  download_video_button = gr.File(label="📥 Download Video", visible=False)
182
  download_gif_button = gr.File(label="📥 Download GIF", visible=False)
183
 
184
- # gr.Markdown("""
185
- # <table border="0" style="width: 100%; text-align: left; margin-top: 20px;">
186
- # <div style="text-align: center; font-size: 24px; font-weight: bold; margin-bottom: 20px;">
187
- # Demo Videos with 50 Inference Steps and 6.0 Guidance Scale.
188
- # </div>
189
- # <tr>
190
- # <td style="width: 25%; vertical-align: top; font-size: 0.8em;">
191
- # <p>A detailed wooden toy ship with intricately carved masts and sails is seen gliding smoothly over a plush, blue carpet that mimics the waves of the sea. The ship's hull is painted a rich brown, with tiny windows. The carpet, soft and textured, provides a perfect backdrop, resembling an oceanic expanse. Surrounding the ship are various other toys and children's items, hinting at a playful environment. The scene captures the innocence and imagination of childhood, with the toy ship's journey symbolizing endless adventures in a whimsical, indoor setting.</p>
192
- # </td>
193
- # <td style="width: 25%; vertical-align: top;">
194
- # <video src="https://github.com/user-attachments/assets/ea3af39a-3160-4999-90ec-2f7863c5b0e9" width="100%" controls autoplay></video>
195
- # </td>
196
- # <td style="width: 25%; vertical-align: top; font-size: 0.8em;">
197
- # <p>The camera follows behind a white vintage SUV with a black roof rack as it speeds up a steep dirt road surrounded by pine trees on a steep mountain slope, dust kicks up from its tires, the sunlight shines on the SUV as it speeds along the dirt road, casting a warm glow over the scene. The dirt road curves gently into the distance, with no other cars or vehicles in sight. The trees on either side of the road are redwoods, with patches of greenery scattered throughout. The car is seen from the rear following the curve with ease, making it seem as if it is on a rugged drive through the rugged terrain. The dirt road itself is surrounded by steep hills and mountains, with a clear blue sky above with wispy clouds.</p>
198
- # </td>
199
- # <td style="width: 25%; vertical-align: top;">
200
- # <video src="https://github.com/user-attachments/assets/9de41efd-d4d1-4095-aeda-246dd834e91d" width="100%" controls autoplay></video>
201
- # </td>
202
- # </tr>
203
- # <tr>
204
- # <td style="width: 25%; vertical-align: top; font-size: 0.8em;">
205
- # <p>A street artist, clad in a worn-out denim jacket and a colorful bandana, stands before a vast concrete wall in the heart, holding a can of spray paint, spray-painting a colorful bird on a mottled wall.</p>
206
- # </td>
207
- # <td style="width: 25%; vertical-align: top;">
208
- # <video src="https://github.com/user-attachments/assets/941d6661-6a8d-4a1b-b912-59606f0b2841" width="100%" controls autoplay></video>
209
- # </td>
210
- # <td style="width: 25%; vertical-align: top; font-size: 0.8em;">
211
- # <p>In the haunting backdrop of a war-torn city, where ruins and crumbled walls tell a story of devastation, a poignant close-up frames a young girl. Her face is smudged with ash, a silent testament to the chaos around her. Her eyes glistening with a mix of sorrow and resilience, capturing the raw emotion of a world that has lost its innocence to the ravages of conflict.</p>
212
- # </td>
213
- # <td style="width: 25%; vertical-align: top;">
214
- # <video src="https://github.com/user-attachments/assets/938529c4-91ae-4f60-b96b-3c3947fa63cb" width="100%" controls autoplay></video>
215
- # </td>
216
- # </tr>
217
- # </table>
218
- # """)
219
 
220
 
221
  def generate(prompt, num_inference_steps, guidance_scale, model_choice, progress=gr.Progress(track_tqdm=True)):
 
18
 
19
  dtype = torch.float16
20
  device = "cuda" if torch.cuda.is_available() else "cpu"
21
+ pipe = VchitectXLPipeline("Vchitect/Vchitect-XL-2B",device)
22
+
 
23
  os.makedirs("./output", exist_ok=True)
24
  os.makedirs("./gradio_tmp", exist_ok=True)
25
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
26
  @spaces.GPU(duration=120)
27
  def infer(prompt: str, num_inference_steps: int, guidance_scale: float, progress=gr.Progress(track_tqdm=True)):
28
  torch.cuda.empty_cache()
 
 
 
 
 
 
 
29
  with torch.cuda.amp.autocast(dtype=torch.bfloat16):
30
  video = pipe(
31
  prompt,
 
103
  # "Increasing the number of inference steps will produce more detailed videos, but it will slow down the process.<br>"
104
  # "50 steps are recommended for most cases.<br>"
105
  # "For the 5B model, 50 steps will take approximately 350 seconds.")
106
+ # with gr.Row():
107
+ # num_inference_steps = gr.Number(label="Inference Steps", value=50)
108
+ # guidance_scale = gr.Number(label="Guidance Scale", value=7.5)
109
  generate_button = gr.Button("🎬 Generate Video")
110
 
111
  with gr.Column():
 
114
  download_video_button = gr.File(label="📥 Download Video", visible=False)
115
  download_gif_button = gr.File(label="📥 Download GIF", visible=False)
116
 
117
+
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
118
 
119
 
120
  def generate(prompt, num_inference_steps, guidance_scale, model_choice, progress=gr.Progress(track_tqdm=True)):