fbnnb commited on
Commit
25cf627
·
verified ·
1 Parent(s): 0fe1e7c

Update gradio_app.py

Browse files
Files changed (1) hide show
  1. gradio_app.py +30 -27
gradio_app.py CHANGED
@@ -28,6 +28,36 @@ from huggingface_hub import snapshot_download
28
  import os
29
 
30
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
31
  def extract_frames(video_path):
32
  # 動画ファイルを読み込む
33
  cap = cv2.VideoCapture(video_path)
@@ -213,33 +243,6 @@ def get_image(image, prompt, steps=50, cfg_scale=7.5, eta=1.0, fs=3, seed=123, i
213
 
214
 
215
  # @spaces.GPU
216
- def download_model():
217
- REPO_ID = 'Doubiiu/ToonCrafter'
218
- filename_list = ['model.ckpt']
219
- if not os.path.exists('./checkpoints/tooncrafter_'+str(resolution[1])+'_interp_v1/'):
220
- os.makedirs('./checkpoints/tooncrafter_'+str(resolution[1])+'_interp_v1/')
221
- for filename in filename_list:
222
- local_file = os.path.join('./checkpoints/tooncrafter_'+str(resolution[1])+'_interp_v1/', filename)
223
- if not os.path.exists(local_file):
224
- hf_hub_download(repo_id=REPO_ID, filename=filename, local_dir='./checkpoints/tooncrafter_'+str(resolution[1])+'_interp_v1/', local_dir_use_symlinks=False)
225
- print("downloaded")
226
-
227
-
228
- def get_latent_z_with_hidden_states(model, videos):
229
- b, c, t, h, w = videos.shape
230
- x = rearrange(videos, 'b c t h w -> (b t) c h w')
231
- encoder_posterior, hidden_states = model.first_stage_model.encode(x, return_hidden_states=True)
232
-
233
- hidden_states_first_last = []
234
- ### use only the first and last hidden states
235
- for hid in hidden_states:
236
- hid = rearrange(hid, '(b t) c h w -> b c t h w', t=t)
237
- hid_new = torch.cat([hid[:, :, 0:1], hid[:, :, -1:]], dim=2)
238
- hidden_states_first_last.append(hid_new)
239
-
240
- z = model.get_first_stage_encoding(encoder_posterior).detach()
241
- z = rearrange(z, '(b t) c h w -> b c t h w', b=b, t=t)
242
- return z, hidden_states_first_last
243
 
244
 
245
 
 
28
  import os
29
 
30
 
31
+ def download_model():
32
+ REPO_ID = 'Doubiiu/ToonCrafter'
33
+ filename_list = ['model.ckpt']
34
+ if not os.path.exists('./checkpoints/tooncrafter_'+str(resolution[1])+'_interp_v1/'):
35
+ os.makedirs('./checkpoints/tooncrafter_'+str(resolution[1])+'_interp_v1/')
36
+ for filename in filename_list:
37
+ local_file = os.path.join('./checkpoints/tooncrafter_'+str(resolution[1])+'_interp_v1/', filename)
38
+ if not os.path.exists(local_file):
39
+ hf_hub_download(repo_id=REPO_ID, filename=filename, local_dir='./checkpoints/tooncrafter_'+str(resolution[1])+'_interp_v1/', local_dir_use_symlinks=False)
40
+ print("downloaded")
41
+
42
+
43
+ def get_latent_z_with_hidden_states(model, videos):
44
+ b, c, t, h, w = videos.shape
45
+ x = rearrange(videos, 'b c t h w -> (b t) c h w')
46
+ encoder_posterior, hidden_states = model.first_stage_model.encode(x, return_hidden_states=True)
47
+
48
+ hidden_states_first_last = []
49
+ ### use only the first and last hidden states
50
+ for hid in hidden_states:
51
+ hid = rearrange(hid, '(b t) c h w -> b c t h w', t=t)
52
+ hid_new = torch.cat([hid[:, :, 0:1], hid[:, :, -1:]], dim=2)
53
+ hidden_states_first_last.append(hid_new)
54
+
55
+ z = model.get_first_stage_encoding(encoder_posterior).detach()
56
+ z = rearrange(z, '(b t) c h w -> b c t h w', b=b, t=t)
57
+ return z, hidden_states_first_last
58
+
59
+
60
+
61
  def extract_frames(video_path):
62
  # 動画ファイルを読み込む
63
  cap = cv2.VideoCapture(video_path)
 
243
 
244
 
245
  # @spaces.GPU
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
246
 
247
 
248