Muhammadidrees commited on
Commit
2841184
·
verified ·
1 Parent(s): 29531a5

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +61 -31
app.py CHANGED
@@ -14,6 +14,43 @@ except Exception as e:
14
  print(f"GPU warmup failed: {e}")
15
  os.environ["GRADIO_TEMP_DIR"] = "./tmp"
16
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
17
  pipe,fantasytalking,wav2vec_processor,wav2vec = None,None,None,None
18
  @spaces.GPU(duration=1200)
19
  def generate_video(
@@ -28,42 +65,35 @@ def generate_video(
28
  inference_steps,
29
  seed,
30
  ):
31
- # Create the temp directory if it doesn't exist
32
- output_dir = Path("./output")
33
- output_dir.mkdir(parents=True, exist_ok=True)
34
 
35
- # Convert paths to absolute Path objects and normalize them
36
- print(image_path)
37
- image_path = Path(image_path).absolute().as_posix()
38
- audio_path = Path(audio_path).absolute().as_posix()
39
 
40
- # Parse the arguments
 
 
 
 
 
 
 
 
 
 
 
 
41
 
42
- args = create_args(
43
- image_path=image_path,
44
- audio_path=audio_path,
45
- prompt=prompt,
46
- output_dir=str(output_dir),
47
- audio_weight=audio_weight,
48
- prompt_cfg_scale=prompt_cfg_scale,
49
- audio_cfg_scale=audio_cfg_scale,
50
- image_size=image_size,
51
- max_num_frames=max_num_frames,
52
- inference_steps=inference_steps,
53
- seed=seed,
54
- )
55
 
56
- try:
57
- global pipe, fantasytalking, wav2vec_processor, wav2vec
58
- if pipe is None:
59
- pipe,fantasytalking,wav2vec_processor,wav2vec = load_models(args)
60
- output_path=main(
61
- args,pipe,fantasytalking,wav2vec_processor,wav2vec
62
- )
63
- return output_path # Ensure the output path is returned
64
  except Exception as e:
65
- print(f"Error during processing: {str(e)}")
66
- raise gr.Error(f"Error during processing: {str(e)}")
67
 
68
 
69
  def create_args(
 
14
  print(f"GPU warmup failed: {e}")
15
  os.environ["GRADIO_TEMP_DIR"] = "./tmp"
16
 
17
+ try:
18
+ # Define full dummy args with all attributes expected by load_models
19
+ class DummyArgs:
20
+ # Core model paths
21
+ wan_model_dir = "./models/Wan2.1-I2V-14B-720P"
22
+ fantasytalking_model_path = "./models/fantasytalking_model.ckpt"
23
+ wav2vec_model_dir = "./models/wav2vec2-base-960h"
24
+
25
+ # Required inference-related parameters
26
+ image_path = "./assets/images/woman.png"
27
+ audio_path = "./assets/audios/woman.wav"
28
+ prompt = "A woman is talking."
29
+ output_dir = "./output"
30
+ image_size = 512
31
+ audio_scale = 1.0
32
+ prompt_cfg_scale = 5.0
33
+ audio_cfg_scale = 5.0
34
+ max_num_frames = 81
35
+ inference_steps = 20
36
+ fps = 23
37
+ seed = 1111
38
+
39
+ # ✅ The missing one that caused your error:
40
+ num_persistent_param_in_dit = 7 * 10**9 # adjust if needed
41
+
42
+ # Preload models
43
+ print("🔄 Loading models into memory...")
44
+ args = DummyArgs()
45
+ pipe, fantasytalking, wav2vec_processor, wav2vec = load_models(args)
46
+ print("✅ Models loaded successfully.")
47
+
48
+ except Exception as e:
49
+ print(f"❌ Error loading models: {e}")
50
+ pipe = fantasytalking = wav2vec_processor = wav2vec = None
51
+ raise e # fail fast if model load fails
52
+
53
+
54
  pipe,fantasytalking,wav2vec_processor,wav2vec = None,None,None,None
55
  @spaces.GPU(duration=1200)
56
  def generate_video(
 
65
  inference_steps,
66
  seed,
67
  ):
68
+ try:
69
+ output_dir = Path("./output")
70
+ output_dir.mkdir(parents=True, exist_ok=True)
71
 
72
+ image_path = Path(image_path).absolute().as_posix()
73
+ audio_path = Path(audio_path).absolute().as_posix()
 
 
74
 
75
+ args = create_args(
76
+ image_path=image_path,
77
+ audio_path=audio_path,
78
+ prompt=prompt or "A person is talking.",
79
+ output_dir=str(output_dir),
80
+ audio_weight=audio_weight,
81
+ prompt_cfg_scale=prompt_cfg_scale,
82
+ audio_cfg_scale=audio_cfg_scale,
83
+ image_size=image_size,
84
+ max_num_frames=max_num_frames,
85
+ inference_steps=inference_steps,
86
+ seed=seed,
87
+ )
88
 
89
+ # Run inference using preloaded models
90
+ save_path = main(args, pipe, fantasytalking, wav2vec_processor, wav2vec)
91
+ print(f"✅ Video saved at {save_path}")
92
+ return save_path
 
 
 
 
 
 
 
 
 
93
 
 
 
 
 
 
 
 
 
94
  except Exception as e:
95
+ print(f"Error generating video: {e}")
96
+ return None
97
 
98
 
99
  def create_args(