boheng.xie commited on
Commit
a042391
·
1 Parent(s): 1cbb6a8

modify: change for space.GPU

Browse files
Files changed (2) hide show
  1. app.py +28 -3
  2. requirements.txt +0 -1
app.py CHANGED
@@ -6,16 +6,41 @@ import cv2
6
  import zipfile
7
  from utils import process_video, get_npy_files, get_frame_count, process_image
8
  from infer_script import run_inference
9
- import huggingface_hub.spaces as spaces
10
  import time
11
  import datetime
12
  import shutil
 
13
 
14
  import imageio
15
  from media_pipe.draw_util import FaceMeshVisualizer
16
 
17
  from download_models import download
18
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
19
  # Download models and check for exists
20
  download()
21
 
@@ -170,7 +195,6 @@ def preview_crop(image_path, npy_file, video_path, expand_x, expand_y, offset_x,
170
  else:
171
  return None,None, "Failed to generate crop preview"
172
 
173
- @spaces.GPU
174
  def generate_video(input_img, should_crop_face, expand_x, expand_y, offset_x, offset_y, input_video_type, input_video, input_npy_select, input_npy, input_video_frames,
175
  settings_steps, settings_cfg_scale, settings_seed, resolution_w, resolution_h,
176
  model_step, custom_output_path, use_custom_fps, output_fps, callback_steps, context_frames, context_stride, context_overlap, context_batch_size, anomaly_action,intropolate_factor):
@@ -234,7 +258,8 @@ def generate_video(input_img, should_crop_face, expand_x, expand_y, offset_x, of
234
  context_overlap=context_overlap,
235
  context_batch_size=context_batch_size,
236
  anomaly_action=anomaly_action,
237
- interpolation_factor=intropolate_factor
 
238
  )
239
 
240
 
 
6
  import zipfile
7
  from utils import process_video, get_npy_files, get_frame_count, process_image
8
  from infer_script import run_inference
 
9
  import time
10
  import datetime
11
  import shutil
12
+ import torch
13
 
14
  import imageio
15
  from media_pipe.draw_util import FaceMeshVisualizer
16
 
17
  from download_models import download
18
 
19
+ def check_gpu():
20
+ if torch.cuda.is_available():
21
+ device_name = torch.cuda.get_device_name(0)
22
+ print(f"使用 GPU: {device_name}")
23
+ return "cuda"
24
+ else:
25
+ print("GPU 不可用,使用 CPU")
26
+ return "cpu"
27
+
28
+ # 设置全局设备
29
+ DEVICE = check_gpu()
30
+
31
+ try:
32
+ from huggingface_hub import spaces
33
+ HAS_SPACES = True
34
+ except ImportError:
35
+ print("Warning: huggingface_hub.spaces module not available, GPU acceleration features may be limited")
36
+ HAS_SPACES = False
37
+
38
+ # 创建一个替代装饰器
39
+ class SpacesMock:
40
+ def GPU(self, func):
41
+ return func
42
+ spaces = SpacesMock()
43
+
44
  # Download models and check for exists
45
  download()
46
 
 
195
  else:
196
  return None,None, "Failed to generate crop preview"
197
 
 
198
  def generate_video(input_img, should_crop_face, expand_x, expand_y, offset_x, offset_y, input_video_type, input_video, input_npy_select, input_npy, input_video_frames,
199
  settings_steps, settings_cfg_scale, settings_seed, resolution_w, resolution_h,
200
  model_step, custom_output_path, use_custom_fps, output_fps, callback_steps, context_frames, context_stride, context_overlap, context_batch_size, anomaly_action,intropolate_factor):
 
258
  context_overlap=context_overlap,
259
  context_batch_size=context_batch_size,
260
  anomaly_action=anomaly_action,
261
+ interpolation_factor=intropolate_factor,
262
+ device=DEVICE
263
  )
264
 
265
 
requirements.txt CHANGED
@@ -24,7 +24,6 @@ protobuf==4.25.3
24
  xformers==0.0.23
25
  gradio
26
  scikit-image
27
- huggingface_hub==0.20.0
28
  # extra dependencies
29
  torch==2.1.1
30
  torchaudio==2.1.1
 
24
  xformers==0.0.23
25
  gradio
26
  scikit-image
 
27
  # extra dependencies
28
  torch==2.1.1
29
  torchaudio==2.1.1