Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -37,20 +37,22 @@ os.makedirs(AUDIO_DIR, exist_ok=True)
|
|
37 |
audio_cache = {}
|
38 |
|
39 |
def load_chatterbox_model():
|
40 |
-
"""Try multiple ways to load ChatterboxTTS"""
|
41 |
global MODEL, CHATTERBOX_AVAILABLE
|
42 |
|
43 |
-
# Method 1: Try
|
44 |
try:
|
45 |
from chatterbox.src.chatterbox.tts import ChatterboxTTS
|
46 |
-
logger.info("β
Found ChatterboxTTS in chatterbox.src.chatterbox.tts")
|
47 |
MODEL = ChatterboxTTS.from_pretrained(DEVICE)
|
48 |
CHATTERBOX_AVAILABLE = True
|
49 |
return True
|
50 |
except ImportError as e:
|
51 |
-
logger.warning(f"Method 1 failed: {e}")
|
|
|
|
|
52 |
|
53 |
-
# Method 2: Try
|
54 |
try:
|
55 |
from chatterbox.tts import ChatterboxTTS
|
56 |
logger.info("β
Found ChatterboxTTS in chatterbox.tts")
|
@@ -59,58 +61,77 @@ def load_chatterbox_model():
|
|
59 |
return True
|
60 |
except ImportError as e:
|
61 |
logger.warning(f"Method 2 failed: {e}")
|
|
|
|
|
62 |
|
63 |
-
# Method 3: Try
|
64 |
try:
|
65 |
-
|
66 |
-
|
67 |
-
|
|
|
|
|
|
|
|
|
|
|
68 |
CHATTERBOX_AVAILABLE = True
|
69 |
return True
|
70 |
except ImportError as e:
|
71 |
logger.warning(f"Method 3 failed: {e}")
|
|
|
|
|
72 |
|
73 |
-
# Method 4: Try
|
74 |
try:
|
75 |
-
import
|
76 |
-
|
77 |
-
|
78 |
-
|
79 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
80 |
except ImportError as e:
|
81 |
logger.warning(f"Method 4 failed: {e}")
|
|
|
|
|
82 |
|
83 |
-
# Method 5:
|
84 |
try:
|
85 |
-
import
|
86 |
-
|
87 |
-
|
88 |
-
|
89 |
-
|
90 |
-
|
91 |
-
|
92 |
-
|
93 |
-
|
94 |
-
|
95 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
96 |
except Exception as e:
|
97 |
-
logger.warning(f"
|
98 |
|
99 |
-
#
|
100 |
-
|
101 |
-
|
102 |
-
|
103 |
-
|
104 |
-
"./src/chatterbox/tts.py"
|
105 |
-
]
|
106 |
-
|
107 |
-
existing_files = [loc for loc in possible_locations if os.path.exists(loc)]
|
108 |
-
if existing_files:
|
109 |
-
logger.error(f"β Found ChatterboxTTS files at {existing_files} but couldn't import!")
|
110 |
-
logger.error("π‘ Check your file structure and __init__.py files")
|
111 |
-
else:
|
112 |
-
logger.error("β No ChatterboxTTS files found!")
|
113 |
-
logger.error("π‘ Upload your ChatterboxTTS package to the Space")
|
114 |
|
115 |
return False
|
116 |
|
@@ -453,26 +474,20 @@ def create_gradio_interface():
|
|
453 |
gr.Markdown("""
|
454 |
### π¨ Currently Using Fallback Model
|
455 |
|
456 |
-
You're hearing beep sounds because the real ChatterboxTTS isn't loaded.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
457 |
|
458 |
-
|
459 |
-
2. **Ensure proper file structure**: `chatterbox/src/chatterbox/tts.py`
|
460 |
-
3. **Add `__init__.py` files** in each directory
|
461 |
-
4. **Restart the Space** after uploading
|
462 |
|
463 |
-
|
464 |
-
```
|
465 |
-
your-space/
|
466 |
-
βββ app.py
|
467 |
-
βββ requirements.txt
|
468 |
-
βββ chatterbox/
|
469 |
-
βββ __init__.py
|
470 |
-
βββ src/
|
471 |
-
βββ __init__.py
|
472 |
-
βββ chatterbox/
|
473 |
-
βββ __init__.py
|
474 |
-
βββ tts.py
|
475 |
-
```
|
476 |
""")
|
477 |
|
478 |
with gr.Row():
|
|
|
37 |
audio_cache = {}
|
38 |
|
39 |
def load_chatterbox_model():
|
40 |
+
"""Try multiple ways to load ChatterboxTTS from Resemble AI"""
|
41 |
global MODEL, CHATTERBOX_AVAILABLE
|
42 |
|
43 |
+
# Method 1: Try Resemble AI ChatterboxTTS (most likely)
|
44 |
try:
|
45 |
from chatterbox.src.chatterbox.tts import ChatterboxTTS
|
46 |
+
logger.info("β
Found Resemble AI ChatterboxTTS in chatterbox.src.chatterbox.tts")
|
47 |
MODEL = ChatterboxTTS.from_pretrained(DEVICE)
|
48 |
CHATTERBOX_AVAILABLE = True
|
49 |
return True
|
50 |
except ImportError as e:
|
51 |
+
logger.warning(f"Method 1 (Resemble AI standard path) failed: {e}")
|
52 |
+
except Exception as e:
|
53 |
+
logger.warning(f"Method 1 failed with error: {e}")
|
54 |
|
55 |
+
# Method 2: Try alternative import path for Resemble AI repo
|
56 |
try:
|
57 |
from chatterbox.tts import ChatterboxTTS
|
58 |
logger.info("β
Found ChatterboxTTS in chatterbox.tts")
|
|
|
61 |
return True
|
62 |
except ImportError as e:
|
63 |
logger.warning(f"Method 2 failed: {e}")
|
64 |
+
except Exception as e:
|
65 |
+
logger.warning(f"Method 2 failed with error: {e}")
|
66 |
|
67 |
+
# Method 3: Try direct chatterbox import
|
68 |
try:
|
69 |
+
import chatterbox
|
70 |
+
if hasattr(chatterbox, 'ChatterboxTTS'):
|
71 |
+
MODEL = chatterbox.ChatterboxTTS.from_pretrained(DEVICE)
|
72 |
+
elif hasattr(chatterbox, 'tts') and hasattr(chatterbox.tts, 'ChatterboxTTS'):
|
73 |
+
MODEL = chatterbox.tts.ChatterboxTTS.from_pretrained(DEVICE)
|
74 |
+
else:
|
75 |
+
raise ImportError("ChatterboxTTS not found in chatterbox module")
|
76 |
+
logger.info("β
Found ChatterboxTTS via direct import")
|
77 |
CHATTERBOX_AVAILABLE = True
|
78 |
return True
|
79 |
except ImportError as e:
|
80 |
logger.warning(f"Method 3 failed: {e}")
|
81 |
+
except Exception as e:
|
82 |
+
logger.warning(f"Method 3 failed with error: {e}")
|
83 |
|
84 |
+
# Method 4: Try exploring the installed package
|
85 |
try:
|
86 |
+
import chatterbox
|
87 |
+
import inspect
|
88 |
+
|
89 |
+
# Log what's available in the chatterbox package
|
90 |
+
logger.info(f"Chatterbox module path: {chatterbox.__file__}")
|
91 |
+
logger.info(f"Chatterbox contents: {dir(chatterbox)}")
|
92 |
+
|
93 |
+
# Try to find ChatterboxTTS class anywhere in the module
|
94 |
+
for name, obj in inspect.getmembers(chatterbox):
|
95 |
+
if name == 'ChatterboxTTS' or (inspect.isclass(obj) and 'TTS' in name):
|
96 |
+
logger.info(f"Found potential TTS class: {name}")
|
97 |
+
MODEL = obj.from_pretrained(DEVICE)
|
98 |
+
CHATTERBOX_AVAILABLE = True
|
99 |
+
return True
|
100 |
+
|
101 |
+
raise ImportError("ChatterboxTTS class not found in chatterbox package")
|
102 |
+
|
103 |
except ImportError as e:
|
104 |
logger.warning(f"Method 4 failed: {e}")
|
105 |
+
except Exception as e:
|
106 |
+
logger.warning(f"Method 4 failed with error: {e}")
|
107 |
|
108 |
+
# Method 5: Check if the GitHub repo was installed correctly
|
109 |
try:
|
110 |
+
import pkg_resources
|
111 |
+
try:
|
112 |
+
pkg_resources.get_distribution('chatterbox')
|
113 |
+
logger.info("β
Chatterbox package is installed")
|
114 |
+
except pkg_resources.DistributionNotFound:
|
115 |
+
logger.warning("β Chatterbox package not found in installed packages")
|
116 |
+
|
117 |
+
# Try to import and inspect what we got
|
118 |
+
import chatterbox
|
119 |
+
chatterbox_path = chatterbox.__path__[0] if hasattr(chatterbox, '__path__') else str(chatterbox.__file__)
|
120 |
+
logger.info(f"Chatterbox installed at: {chatterbox_path}")
|
121 |
+
|
122 |
+
# List all available modules/classes
|
123 |
+
import pkgutil
|
124 |
+
for importer, modname, ispkg in pkgutil.walk_packages(chatterbox.__path__, chatterbox.__name__ + "."):
|
125 |
+
logger.info(f"Available module: {modname}")
|
126 |
+
|
127 |
except Exception as e:
|
128 |
+
logger.warning(f"Package inspection failed: {e}")
|
129 |
|
130 |
+
# If we get here, the GitHub repo might have a different structure
|
131 |
+
logger.error("β Could not load ChatterboxTTS from Resemble AI repository")
|
132 |
+
logger.error("π‘ The GitHub repo might have a different structure than expected")
|
133 |
+
logger.error("π Repository: https://github.com/resemble-ai/chatterbox.git")
|
134 |
+
logger.error("π Check the repo's README for correct import instructions")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
135 |
|
136 |
return False
|
137 |
|
|
|
474 |
gr.Markdown("""
|
475 |
### π¨ Currently Using Fallback Model
|
476 |
|
477 |
+
You're hearing beep sounds because the real ChatterboxTTS isn't loaded.
|
478 |
+
|
479 |
+
**The Resemble AI ChatterboxTTS from GitHub should auto-install from requirements.txt.**
|
480 |
+
|
481 |
+
If you're still seeing this message:
|
482 |
+
|
483 |
+
1. **Check build logs** for any installation errors
|
484 |
+
2. **Verify requirements.txt** contains: `git+https://github.com/resemble-ai/chatterbox.git`
|
485 |
+
3. **Restart the Space** if needed
|
486 |
+
4. **Check logs** for import errors
|
487 |
|
488 |
+
π GitHub repo being used: https://github.com/resemble-ai/chatterbox.git
|
|
|
|
|
|
|
489 |
|
490 |
+
If the GitHub installation fails, you can alternatively upload the package manually.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
491 |
""")
|
492 |
|
493 |
with gr.Row():
|