broadfield-dev commited on
Commit
21a831f
·
verified ·
1 Parent(s): 7d20e4c

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +42 -12
app.py CHANGED
@@ -1,9 +1,21 @@
1
  import os
2
  import subprocess
3
  import sys
 
 
4
 
5
- # --- 1. Clone the VibeVoice Repository ---
6
- # Check if the repository directory already exists
 
 
 
 
 
 
 
 
 
 
7
  repo_dir = "VibeVoice"
8
  if not os.path.exists(repo_dir):
9
  print("Cloning the VibeVoice repository...")
@@ -21,14 +33,11 @@ if not os.path.exists(repo_dir):
21
  else:
22
  print("Repository already exists. Skipping clone.")
23
 
24
- # --- 2. Install the Package ---
25
- # Navigate into the repository directory
26
  os.chdir(repo_dir)
27
  print(f"Changed directory to: {os.getcwd()}")
28
-
29
  print("Installing the VibeVoice package...")
30
  try:
31
- # Use pip to install the package in editable mode
32
  subprocess.run(
33
  [sys.executable, "-m", "pip", "install", "-e", "."],
34
  check=True,
@@ -40,13 +49,35 @@ except subprocess.CalledProcessError as e:
40
  print(f"Error installing package: {e.stderr}")
41
  sys.exit(1)
42
 
43
- # --- 3. Launch the Gradio Demo ---
44
- # Define the path to the demo script and the model to use
45
  demo_script_path = "demo/gradio_demo.py"
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
46
  model_id = "microsoft/VibeVoice-1.5B"
47
 
48
- # Construct the command to run the demo
49
- # The --share flag is necessary to make the Gradio app accessible within the Hugging Face Space environment
50
  command = [
51
  "python",
52
  demo_script_path,
@@ -56,6 +87,5 @@ command = [
56
  ]
57
 
58
  print(f"Launching Gradio demo with command: {' '.join(command)}")
59
- # Run the command. This will start the Gradio server and launch the demo.
60
- # The process will remain active, serving the web interface.
61
  subprocess.run(command)
 
1
  import os
2
  import subprocess
3
  import sys
4
+ import fileinput
5
+ import gradio as gr
6
 
7
+ # --- 1. Setup Environment ---
8
+ # Install ffmpeg if it's not already installed by packages.txt
9
+ print("Updating apt and installing ffmpeg...")
10
+ try:
11
+ subprocess.run(["apt-get", "update", "-y"], check=True)
12
+ subprocess.run(["apt-get", "install", "ffmpeg", "-y"], check=True)
13
+ print("ffmpeg installed successfully.")
14
+ except subprocess.CalledProcessError as e:
15
+ print(f"Error installing ffmpeg: {e.stderr}")
16
+ # Continue anyway, as it might be pre-installed
17
+
18
+ # --- 2. Clone the VibeVoice Repository ---
19
  repo_dir = "VibeVoice"
20
  if not os.path.exists(repo_dir):
21
  print("Cloning the VibeVoice repository...")
 
33
  else:
34
  print("Repository already exists. Skipping clone.")
35
 
36
+ # --- 3. Install the Package ---
 
37
  os.chdir(repo_dir)
38
  print(f"Changed directory to: {os.getcwd()}")
 
39
  print("Installing the VibeVoice package...")
40
  try:
 
41
  subprocess.run(
42
  [sys.executable, "-m", "pip", "install", "-e", "."],
43
  check=True,
 
49
  print(f"Error installing package: {e.stderr}")
50
  sys.exit(1)
51
 
52
+
53
+ # --- 4. Modify the demo script for CPU execution ---
54
  demo_script_path = "demo/gradio_demo.py"
55
+ print(f"Modifying {demo_script_path} for CPU execution...")
56
+
57
+ # Use fileinput to perform in-place replacement
58
+ with fileinput.FileInput(demo_script_path, inplace=True) as file:
59
+ for line in file:
60
+ # Change the model loading line to be CPU-compatible
61
+ if 'VibeVoiceForConditionalGenerationInference.from_pretrained(' in line:
62
+ print(' self.model = VibeVoiceForConditionalGenerationInference.from_pretrained(')
63
+ print(' self.model_path,')
64
+ print(' torch_dtype=torch.float32, # Use float32 for CPU')
65
+ print(' device_map="cpu",')
66
+ print(' )')
67
+ # Skip the next few lines of the original arguments
68
+ next(file, None)
69
+ next(file, None)
70
+ next(file, None)
71
+ else:
72
+ print(line, end='')
73
+
74
+ print("Script modified successfully.")
75
+
76
+
77
+ # --- 5. Launch the Gradio Demo ---
78
  model_id = "microsoft/VibeVoice-1.5B"
79
 
80
+ # Construct the command as specified in the README
 
81
  command = [
82
  "python",
83
  demo_script_path,
 
87
  ]
88
 
89
  print(f"Launching Gradio demo with command: {' '.join(command)}")
90
+ # This command will start the Gradio server
 
91
  subprocess.run(command)