jacky3102 commited on
Commit
e25c372
·
verified ·
1 Parent(s): 5fe3ad9

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +11 -17
app.py CHANGED
@@ -3,7 +3,7 @@ import sys
3
  import subprocess
4
  from pathlib import Path
5
 
6
- # Hugging Face Spaces / CPU-only environment setup
7
  os.environ["CUDA_VISIBLE_DEVICES"] = ""
8
  os.environ["GRADIO_SERVER_NAME"] = "0.0.0.0"
9
  os.environ["GRADIO_SERVER_PORT"] = "7860"
@@ -16,33 +16,27 @@ def run(cmd, cwd=None):
16
  print(">>>", " ".join(map(str, cmd)), flush=True)
17
  subprocess.check_call(cmd, cwd=cwd)
18
 
19
- # 1. Clone repository into /app/rvc if it doesn't exist
20
  if not (RVC_DIR / "infer-web.py").exists():
21
- run([
22
- "git", "clone", "--depth", "1",
23
- "https://github.com/RVC-Project/Retrieval-based-Voice-Conversion-WebUI.git",
24
- str(RVC_DIR)
25
- ])
26
-
27
- # 2. Append RVC directory to sys.path and set working directory to /app/rvc
28
- if str(RVC_DIR) not in sys.path:
29
- sys.path.insert(0, str(RVC_DIR))
30
  os.chdir(RVC_DIR)
31
 
32
- # 3. Download assets using explicit path
33
  hubert = RVC_DIR / "assets" / "hubert" / "hubert_base.pt"
34
  rmvpe = RVC_DIR / "assets" / "rmvpe" / "rmvpe.pt"
35
 
36
  if not hubert.exists() or not rmvpe.exists():
37
  downloader = RVC_DIR / "tools" / "download_models.py"
38
  if downloader.exists():
39
- run([sys.executable, str(downloader)])
40
 
41
- # 4. Launch infer-web.py using absolute path without passing redundant cwd
42
- infer_script = RVC_DIR / "infer-web.py"
43
  run([
44
  sys.executable,
45
- str(infer_script),
46
  "--pycmd", sys.executable,
47
  "--port", "7860",
48
- ])
 
3
  import subprocess
4
  from pathlib import Path
5
 
6
+ # Environment flags for Hugging Face Spaces CPU runtime
7
  os.environ["CUDA_VISIBLE_DEVICES"] = ""
8
  os.environ["GRADIO_SERVER_NAME"] = "0.0.0.0"
9
  os.environ["GRADIO_SERVER_PORT"] = "7860"
 
16
  print(">>>", " ".join(map(str, cmd)), flush=True)
17
  subprocess.check_call(cmd, cwd=cwd)
18
 
19
+ # Ensure RVC directory exists
20
  if not (RVC_DIR / "infer-web.py").exists():
21
+ raise FileNotFoundError(f"RVC directory not found at {RVC_DIR}")
22
+
23
+ # Set Python execution context to RVC root
24
+ sys.path.insert(0, str(RVC_DIR))
 
 
 
 
 
25
  os.chdir(RVC_DIR)
26
 
27
+ # Download required model assets if missing
28
  hubert = RVC_DIR / "assets" / "hubert" / "hubert_base.pt"
29
  rmvpe = RVC_DIR / "assets" / "rmvpe" / "rmvpe.pt"
30
 
31
  if not hubert.exists() or not rmvpe.exists():
32
  downloader = RVC_DIR / "tools" / "download_models.py"
33
  if downloader.exists():
34
+ run([sys.executable, str(downloader)], cwd=RVC_DIR)
35
 
36
+ # Start WebUI server
 
37
  run([
38
  sys.executable,
39
+ "infer-web.py",
40
  "--pycmd", sys.executable,
41
  "--port", "7860",
42
+ ], cwd=RVC_DIR)