cronos3k commited on
Commit
d7efb89
Β·
verified Β·
1 Parent(s): df04009

fix: upgrade to Gradio 5.25.0 to resolve HfFolder import error with transformers 5.x

Browse files
Files changed (3) hide show
  1. README.md +1 -1
  2. requirements.txt +2 -2
  3. spaces_app.py +56 -57
README.md CHANGED
@@ -4,7 +4,7 @@ emoji: 🐱
4
  colorFrom: purple
5
  colorTo: pink
6
  sdk: gradio
7
- sdk_version: "4.44.0"
8
  app_file: spaces_app.py
9
  pinned: false
10
  license: apache-2.0
 
4
  colorFrom: purple
5
  colorTo: pink
6
  sdk: gradio
7
+ sdk_version: "5.25.0"
8
  app_file: spaces_app.py
9
  pinned: false
10
  license: apache-2.0
requirements.txt CHANGED
@@ -7,6 +7,6 @@ soundfile>=0.12.0
7
  numpy>=1.24.0
8
  einops>=0.8.0
9
  faster-whisper>=1.0.0
10
- gradio>=4.0.0
11
- huggingface-hub>=0.24.0,<0.25.0
12
  tqdm>=4.65.0
 
7
  numpy>=1.24.0
8
  einops>=0.8.0
9
  faster-whisper>=1.0.0
10
+ gradio>=5.0.0
11
+ huggingface-hub>=1.3.0
12
  tqdm>=4.65.0
spaces_app.py CHANGED
@@ -1,57 +1,56 @@
1
- """
2
- HuggingFace Spaces entry point for LongCat-AudioDiT Enhanced.
3
-
4
- Handles:
5
- - /tmp storage for outputs, models, voices (Spaces has no persistent /app writes)
6
- - HF_HOME β†’ /tmp so model cache lands in writable space
7
- - GPU detection and graceful CPU fallback
8
- - Gradio theme passed to launch() (Gradio 6 compat)
9
- """
10
-
11
- import os
12
- import sys
13
- from pathlib import Path
14
-
15
- # ── Redirect HF cache + all writable dirs to /tmp ────────────────────────────
16
- os.environ["HF_HOME"] = "/tmp/hf_home"
17
- os.environ["TRANSFORMERS_CACHE"] = "/tmp/hf_home/transformers"
18
- os.environ["HF_DATASETS_CACHE"] = "/tmp/hf_home/datasets"
19
-
20
- for d in ["/tmp/hf_home", "/tmp/audiodit_outputs", "/tmp/audiodit_voices"]:
21
- Path(d).mkdir(parents=True, exist_ok=True)
22
-
23
- # ── Patch app constants before import ────────────────────────────────────────
24
- import app as _app
25
- import voice_library as _vl
26
- import whisper_helper as _wh
27
-
28
- _app.OUTPUT_DIR = Path("/tmp/audiodit_outputs")
29
-
30
- # Patch voice library to store in /tmp
31
- _vl.VOICES_DIR = Path("/tmp/audiodit_voices")
32
- _vl.LIBRARY_FILE = Path("/tmp/audiodit_voices/library.json")
33
- _vl.VOICES_DIR.mkdir(parents=True, exist_ok=True)
34
- _vl._library = None # reset singleton so it picks up patched paths
35
-
36
- # Patch Whisper download root
37
- _orig_wh_init = _wh.WhisperHelper.__init__
38
- def _patched_wh_init(self, model_size="turbo", device="auto", compute_type="auto", download_root=None):
39
- _orig_wh_init(self, model_size=model_size, device=device, compute_type=compute_type,
40
- download_root=download_root or "/tmp/hf_home/whisper")
41
- _wh.WhisperHelper.__init__ = _patched_wh_init
42
-
43
- # ── Launch ───────────────────────────────────────────────────────────────────
44
- import torch
45
- import gradio as gr
46
-
47
- device = "cuda" if torch.cuda.is_available() else "cpu"
48
- print(f"[Spaces] device={device} CUDA={torch.cuda.is_available()}")
49
-
50
- demo = _app.build_ui(default_device=device)
51
- demo.launch(
52
- server_name="0.0.0.0",
53
- server_port=int(os.environ.get("PORT", 7860)),
54
- share=False,
55
- show_error=True,
56
- theme=gr.themes.Soft(),
57
- )
 
1
+ """
2
+ HuggingFace Spaces entry point for LongCat-AudioDiT Enhanced.
3
+
4
+ Handles:
5
+ - /tmp storage for outputs, models, voices (Spaces has no persistent /app writes)
6
+ - HF_HOME β†’ /tmp so model cache lands in writable space
7
+ - GPU detection and graceful CPU fallback
8
+ - Gradio theme passed to launch() (Gradio 6 compat)
9
+ """
10
+
11
+ import os
12
+ import sys
13
+ from pathlib import Path
14
+
15
+ # ── Redirect HF cache + all writable dirs to /tmp ────────────────────────────
16
+ os.environ["HF_HOME"] = "/tmp/hf_home"
17
+ os.environ["TRANSFORMERS_CACHE"] = "/tmp/hf_home/transformers"
18
+ os.environ["HF_DATASETS_CACHE"] = "/tmp/hf_home/datasets"
19
+
20
+ for d in ["/tmp/hf_home", "/tmp/audiodit_outputs", "/tmp/audiodit_voices"]:
21
+ Path(d).mkdir(parents=True, exist_ok=True)
22
+
23
+ # ── Patch app constants before import ────────────────────────────────────────
24
+ import app as _app
25
+ import voice_library as _vl
26
+ import whisper_helper as _wh
27
+
28
+ _app.OUTPUT_DIR = Path("/tmp/audiodit_outputs")
29
+
30
+ # Patch voice library to store in /tmp
31
+ _vl.VOICES_DIR = Path("/tmp/audiodit_voices")
32
+ _vl.LIBRARY_FILE = Path("/tmp/audiodit_voices/library.json")
33
+ _vl.VOICES_DIR.mkdir(parents=True, exist_ok=True)
34
+ _vl._library = None # reset singleton so it picks up patched paths
35
+
36
+ # Patch Whisper download root
37
+ _orig_wh_init = _wh.WhisperHelper.__init__
38
+ def _patched_wh_init(self, model_size="turbo", device="auto", compute_type="auto", download_root=None):
39
+ _orig_wh_init(self, model_size=model_size, device=device, compute_type=compute_type,
40
+ download_root=download_root or "/tmp/hf_home/whisper")
41
+ _wh.WhisperHelper.__init__ = _patched_wh_init
42
+
43
+ # ── Launch ───────────────────────────────────────────────────────────────────
44
+ import torch
45
+ import gradio as gr
46
+
47
+ device = "cuda" if torch.cuda.is_available() else "cpu"
48
+ print(f"[Spaces] device={device} CUDA={torch.cuda.is_available()}")
49
+
50
+ demo = _app.build_ui(default_device=device)
51
+ demo.launch(
52
+ server_name="0.0.0.0",
53
+ server_port=int(os.environ.get("PORT", 7860)),
54
+ share=False,
55
+ show_error=True,
56
+ )