Spaces:
Running
on
Zero
Running
on
Zero
Update app.py
Browse files
app.py
CHANGED
@@ -222,19 +222,33 @@ class VibeVoiceDemo:
|
|
222 |
|
223 |
|
224 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
225 |
def load_example_scripts(self):
|
226 |
examples_dir = os.path.join(os.path.dirname(__file__), "text_examples")
|
227 |
self.example_scripts = []
|
228 |
if not os.path.exists(examples_dir):
|
229 |
return
|
230 |
-
|
231 |
-
|
|
|
|
|
232 |
for txt_file in txt_files:
|
233 |
try:
|
234 |
with open(os.path.join(examples_dir, txt_file), 'r', encoding='utf-8') as f:
|
235 |
script_content = f.read().strip()
|
236 |
if script_content:
|
237 |
-
self.
|
|
|
238 |
except Exception as e:
|
239 |
print(f"Error loading {txt_file}: {e}")
|
240 |
|
|
|
222 |
|
223 |
|
224 |
|
225 |
+
@staticmethod
|
226 |
+
def _infer_num_speakers_from_script(script: str) -> int:
|
227 |
+
"""
|
228 |
+
Infer number of speakers by counting distinct 'Speaker X:' tags in the script.
|
229 |
+
Robust to 0- or 1-indexed labels and repeated turns.
|
230 |
+
Falls back to 1 if none found.
|
231 |
+
"""
|
232 |
+
import re
|
233 |
+
ids = re.findall(r'(?mi)^\s*Speaker\s+(\d+)\s*:', script)
|
234 |
+
return len({int(x) for x in ids}) if ids else 1
|
235 |
+
|
236 |
def load_example_scripts(self):
|
237 |
examples_dir = os.path.join(os.path.dirname(__file__), "text_examples")
|
238 |
self.example_scripts = []
|
239 |
if not os.path.exists(examples_dir):
|
240 |
return
|
241 |
+
|
242 |
+
txt_files = sorted(
|
243 |
+
[f for f in os.listdir(examples_dir) if f.lower().endswith('.txt')]
|
244 |
+
)
|
245 |
for txt_file in txt_files:
|
246 |
try:
|
247 |
with open(os.path.join(examples_dir, txt_file), 'r', encoding='utf-8') as f:
|
248 |
script_content = f.read().strip()
|
249 |
if script_content:
|
250 |
+
num_speakers = self._infer_num_speakers_from_script(script_content)
|
251 |
+
self.example_scripts.append([num_speakers, script_content])
|
252 |
except Exception as e:
|
253 |
print(f"Error loading {txt_file}: {e}")
|
254 |
|