Aduc-sdr commited on
Commit
09b1b8e
·
verified ·
1 Parent(s): 642496b

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +23 -45
app.py CHANGED
@@ -11,25 +11,25 @@
11
  # // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
  # // See the License for the specific language governing permissions and
13
  # // limitations under the License.
14
- import os
15
- import torch
16
- import mediapy
17
- import sys
18
  import subprocess
19
- from einops import rearrange
20
- from omegaconf import OmegaConf
21
- print(os.getcwd())
22
- import datetime
23
- from tqdm import tqdm
24
- import gc
25
 
26
  # Clone the repository to ensure all files are available
 
27
  subprocess.run("git lfs install", shell=True, check=True)
28
- subprocess.run("git clone https://huggingface.co/spaces/ByteDance-Seed/SeedVR2-3B", shell=True, check=True)
29
- os.chdir('SeedVR2-3B')
 
30
 
 
 
 
 
 
 
31
 
32
- import os
33
  import torch
34
  import mediapy
35
  from einops import rearrange
@@ -92,8 +92,10 @@ subprocess.run(
92
  shell=True,
93
  )
94
 
95
- subprocess.run(shlex.split("pip install apex-0.1-cp310-cp310-linux_x86_64.whl"))
96
- print(f"✅ setup completed Apex")
 
 
97
 
98
 
99
  def configure_sequence_parallel(sp_size):
@@ -225,7 +227,7 @@ def generation_loop(video_path='./test_videos', seed=666, fps_out=12, batch_size
225
  os.makedirs('output/', exist_ok=True)
226
 
227
  # get test prompts
228
- original_videos = [video_path.split('/')[-1]]
229
 
230
  # divide the prompts into different groups
231
  original_videos_group = original_videos
@@ -265,7 +267,7 @@ def generation_loop(video_path='./test_videos', seed=666, fps_out=12, batch_size
265
  if is_video:
266
  video = (
267
  read_video(
268
- os.path.join(video_path), output_format="TCHW"
269
  )[0]
270
  / 255.0
271
  )
@@ -274,24 +276,6 @@ def generation_loop(video_path='./test_videos', seed=666, fps_out=12, batch_size
274
  print(f"Read video size: {video.size()}")
275
  output_dir = 'output/' + str(uuid.uuid4()) + '.mp4'
276
  else:
277
- video_transform = Compose(
278
- [
279
- NaResize(
280
- resolution=(
281
- 2560 * 1440
282
- )
283
- ** 0.5,
284
- mode="area",
285
- # Upsample image, model only trained for high res.
286
- downsample_only=False,
287
- ),
288
- Lambda(lambda x: torch.clamp(x, 0.0, 1.0)),
289
- DivisibleCrop((16, 16)),
290
- Normalize(0.5, 0.5),
291
- Rearrange("t c h w -> c t h w"),
292
- ]
293
- )
294
-
295
  img = Image.open(video_path).convert("RGB")
296
  img_tensor = T.ToTensor()(img).unsqueeze(0) # (1, C, H, W)
297
  video = img_tensor.permute(0, 1, 2, 3) # (T=1, C, H, W)
@@ -304,12 +288,8 @@ def generation_loop(video_path='./test_videos', seed=666, fps_out=12, batch_size
304
  if is_video:
305
  cond_latents = [cut_videos(video, sp_size) for video in cond_latents]
306
 
307
- # runner.dit.to("cpu")
308
  print(f"Encoding videos: {list(map(lambda x: x.size(), cond_latents))}")
309
- # runner.vae.to(torch.device("cuda"))
310
  cond_latents = runner.vae_encode(cond_latents)
311
- # runner.vae.to("cpu")
312
- # runner.dit.to(torch.device("cuda"))
313
 
314
  for i, emb in enumerate(text_embeds["texts_pos"]):
315
  text_embeds["texts_pos"][i] = emb.to(torch.device("cuda"))
@@ -317,7 +297,6 @@ def generation_loop(video_path='./test_videos', seed=666, fps_out=12, batch_size
317
  text_embeds["texts_neg"][i] = emb.to(torch.device("cuda"))
318
 
319
  samples = generation_step(runner, text_embeds, cond_latents=cond_latents)
320
- # runner.dit.to("cpu")
321
  del cond_latents
322
 
323
  # dump samples to the output directory
@@ -353,7 +332,6 @@ def generation_loop(video_path='./test_videos', seed=666, fps_out=12, batch_size
353
  output_dir, sample, fps=fps_out
354
  )
355
 
356
- # print(f"Generated video size: {sample.shape}")
357
  gc.collect()
358
  torch.cuda.empty_cache()
359
  if is_image:
@@ -366,7 +344,7 @@ with gr.Blocks(title="SeedVR2: One-Step Video Restoration via Diffusion Adversar
366
  # Top logo and title
367
  gr.HTML("""
368
  <div style='text-align:center; margin-bottom: 10px;'>
369
- <img src='https://huggingface.co/ByteDance-Seed/SeedVR2-3B/resolve/main/assets/seedvr_logo.png' style='height:40px;' alt='SeedVR logo'/>
370
  </div>
371
  <p><b>Official Gradio demo</b> for
372
  <a href='https://github.com/ByteDance-Seed/SeedVR' target='_blank'>
@@ -392,9 +370,9 @@ with gr.Blocks(title="SeedVR2: One-Step Video Restoration via Diffusion Adversar
392
  # Examples
393
  gr.Examples(
394
  examples=[
395
- ["./01.mp4", 4, 24],
396
- ["./02.mp4", 4, 24],
397
- ["./03.mp4", 4, 24],
398
  ],
399
  inputs=[input_video, seed, fps]
400
  )
 
11
  # // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
  # // See the License for the specific language governing permissions and
13
  # // limitations under the License.
14
+ import spaces
 
 
 
15
  import subprocess
16
+ import os
17
+ import sys # <-- ADICIONADO PARA MANIPULAR O CAMINHO DO PYTHON
 
 
 
 
18
 
19
  # Clone the repository to ensure all files are available
20
+ # Make sure git-lfs is installed
21
  subprocess.run("git lfs install", shell=True, check=True)
22
+ # Clone the repository only if it doesn't exist
23
+ if not os.path.exists("SeedVR2-3B"):
24
+ subprocess.run("git clone https://huggingface.co/spaces/ByteDance-Seed/SeedVR2-3B", shell=True, check=True)
25
 
26
+ # Define the repository directory
27
+ repo_dir = 'SeedVR2-3B'
28
+ # Change the current working directory to the cloned repository
29
+ os.chdir(repo_dir)
30
+ # Add the repository directory to the Python path to allow imports
31
+ sys.path.insert(0, os.path.abspath('.')) # <-- CORREÇÃO PRINCIPAL AQUI
32
 
 
33
  import torch
34
  import mediapy
35
  from einops import rearrange
 
92
  shell=True,
93
  )
94
 
95
+ # Install apex from the local wheel file
96
+ if os.path.exists("apex-0.1-cp310-cp310-linux_x86_64.whl"):
97
+ subprocess.run(shlex.split("pip install apex-0.1-cp310-cp310-linux_x86_64.whl"))
98
+ print(f"✅ setup completed Apex")
99
 
100
 
101
  def configure_sequence_parallel(sp_size):
 
227
  os.makedirs('output/', exist_ok=True)
228
 
229
  # get test prompts
230
+ original_videos = [os.path.basename(video_path)]
231
 
232
  # divide the prompts into different groups
233
  original_videos_group = original_videos
 
267
  if is_video:
268
  video = (
269
  read_video(
270
+ video_path, output_format="TCHW"
271
  )[0]
272
  / 255.0
273
  )
 
276
  print(f"Read video size: {video.size()}")
277
  output_dir = 'output/' + str(uuid.uuid4()) + '.mp4'
278
  else:
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
279
  img = Image.open(video_path).convert("RGB")
280
  img_tensor = T.ToTensor()(img).unsqueeze(0) # (1, C, H, W)
281
  video = img_tensor.permute(0, 1, 2, 3) # (T=1, C, H, W)
 
288
  if is_video:
289
  cond_latents = [cut_videos(video, sp_size) for video in cond_latents]
290
 
 
291
  print(f"Encoding videos: {list(map(lambda x: x.size(), cond_latents))}")
 
292
  cond_latents = runner.vae_encode(cond_latents)
 
 
293
 
294
  for i, emb in enumerate(text_embeds["texts_pos"]):
295
  text_embeds["texts_pos"][i] = emb.to(torch.device("cuda"))
 
297
  text_embeds["texts_neg"][i] = emb.to(torch.device("cuda"))
298
 
299
  samples = generation_step(runner, text_embeds, cond_latents=cond_latents)
 
300
  del cond_latents
301
 
302
  # dump samples to the output directory
 
332
  output_dir, sample, fps=fps_out
333
  )
334
 
 
335
  gc.collect()
336
  torch.cuda.empty_cache()
337
  if is_image:
 
344
  # Top logo and title
345
  gr.HTML("""
346
  <div style='text-align:center; margin-bottom: 10px;'>
347
+ <img src='assets/seedvr_logo.png' style='height:40px;' alt='SeedVR logo'/>
348
  </div>
349
  <p><b>Official Gradio demo</b> for
350
  <a href='https://github.com/ByteDance-Seed/SeedVR' target='_blank'>
 
370
  # Examples
371
  gr.Examples(
372
  examples=[
373
+ ["01.mp4", 4, 24],
374
+ ["02.mp4", 4, 24],
375
+ ["03.mp4", 4, 24],
376
  ],
377
  inputs=[input_video, seed, fps]
378
  )