Spaces:
Running
on
Zero
Running
on
Zero
Remove static label text in TTS demo and update label formatting
Browse files
app.py
CHANGED
@@ -279,11 +279,11 @@ with gr.Blocks(title="Kokoro TTS Demo", css="""
|
|
279 |
|
280 |
def update_chapters(book_name):
|
281 |
if not book_name:
|
282 |
-
return gr.update(choices=[], value=None), "", '<div class="token-label"
|
283 |
# Find the corresponding book file
|
284 |
book_file = next((book['value'] for book in books if book['label'] == book_name), None)
|
285 |
if not book_file:
|
286 |
-
return gr.update(choices=[], value=None), "", '<div class="token-label"
|
287 |
book_path = os.path.join("texts/processed", book_file)
|
288 |
book_title, chapters = get_book_info(book_path)
|
289 |
# Create simple choices list of chapter titles
|
@@ -293,18 +293,18 @@ with gr.Blocks(title="Kokoro TTS Demo", css="""
|
|
293 |
if initial_text:
|
294 |
tokens = count_tokens(initial_text)
|
295 |
time_estimate = math.ceil(tokens / 150 / 10) * 10
|
296 |
-
label = f'<div class="token-label"
|
297 |
else:
|
298 |
-
label = '<div class="token-label"
|
299 |
return gr.update(choices=chapter_choices, value=chapter_choices[0] if chapter_choices else None), initial_text, label
|
300 |
|
301 |
def load_chapter_text(book_name, chapter_title):
|
302 |
if not book_name or not chapter_title:
|
303 |
-
return "", '<div class="token-label"
|
304 |
# Find the corresponding book file
|
305 |
book_file = next((book['value'] for book in books if book['label'] == book_name), None)
|
306 |
if not book_file:
|
307 |
-
return "", '<div class="token-label"
|
308 |
book_path = os.path.join("texts/processed", book_file)
|
309 |
# Get all chapters and find the one matching the title
|
310 |
_, chapters = get_book_info(book_path)
|
@@ -313,8 +313,8 @@ with gr.Blocks(title="Kokoro TTS Demo", css="""
|
|
313 |
text = get_chapter_text(book_path, ch['id'])
|
314 |
tokens = count_tokens(text)
|
315 |
time_estimate = math.ceil(tokens / 150 / 10) * 10
|
316 |
-
return text, f'<div class="token-label">
|
317 |
-
return "", '<div class="token-label"
|
318 |
|
319 |
# Set up event handlers for book/chapter selection
|
320 |
book_dropdown.change(
|
@@ -339,12 +339,12 @@ with gr.Blocks(title="Kokoro TTS Demo", css="""
|
|
339 |
|
340 |
def load_text_from_file(file_bytes):
|
341 |
if file_bytes is None:
|
342 |
-
return None, '<div class="token-label"
|
343 |
try:
|
344 |
text = file_bytes.decode('utf-8')
|
345 |
tokens = count_tokens(text)
|
346 |
time_estimate = math.ceil(tokens / 150 / 10) * 10 # Round up to nearest 10 seconds
|
347 |
-
return text, f'<div class="token-label"
|
348 |
except Exception as e:
|
349 |
raise gr.Error(f"Failed to read file: {str(e)}")
|
350 |
|
|
|
279 |
|
280 |
def update_chapters(book_name):
|
281 |
if not book_name:
|
282 |
+
return gr.update(choices=[], value=None), "", '<div class="token-label"></div>'
|
283 |
# Find the corresponding book file
|
284 |
book_file = next((book['value'] for book in books if book['label'] == book_name), None)
|
285 |
if not book_file:
|
286 |
+
return gr.update(choices=[], value=None), "", '<div class="token-label"></div>'
|
287 |
book_path = os.path.join("texts/processed", book_file)
|
288 |
book_title, chapters = get_book_info(book_path)
|
289 |
# Create simple choices list of chapter titles
|
|
|
293 |
if initial_text:
|
294 |
tokens = count_tokens(initial_text)
|
295 |
time_estimate = math.ceil(tokens / 150 / 10) * 10
|
296 |
+
label = f'<div class="token-label"><span class="token-count">({tokens} tokens, ~{time_estimate}s generation time)</span></div>'
|
297 |
else:
|
298 |
+
label = '<div class="token-label"></div>'
|
299 |
return gr.update(choices=chapter_choices, value=chapter_choices[0] if chapter_choices else None), initial_text, label
|
300 |
|
301 |
def load_chapter_text(book_name, chapter_title):
|
302 |
if not book_name or not chapter_title:
|
303 |
+
return "", '<div class="token-label"></div>'
|
304 |
# Find the corresponding book file
|
305 |
book_file = next((book['value'] for book in books if book['label'] == book_name), None)
|
306 |
if not book_file:
|
307 |
+
return "", '<div class="token-label"></div>'
|
308 |
book_path = os.path.join("texts/processed", book_file)
|
309 |
# Get all chapters and find the one matching the title
|
310 |
_, chapters = get_book_info(book_path)
|
|
|
313 |
text = get_chapter_text(book_path, ch['id'])
|
314 |
tokens = count_tokens(text)
|
315 |
time_estimate = math.ceil(tokens / 150 / 10) * 10
|
316 |
+
return text, f'<div class="token-label"> <span class="token-count">({tokens} tokens, ~{time_estimate}s generation time)</span></div>'
|
317 |
+
return "", '<div class="token-label"></div>'
|
318 |
|
319 |
# Set up event handlers for book/chapter selection
|
320 |
book_dropdown.change(
|
|
|
339 |
|
340 |
def load_text_from_file(file_bytes):
|
341 |
if file_bytes is None:
|
342 |
+
return None, '<div class="token-label"></div>'
|
343 |
try:
|
344 |
text = file_bytes.decode('utf-8')
|
345 |
tokens = count_tokens(text)
|
346 |
time_estimate = math.ceil(tokens / 150 / 10) * 10 # Round up to nearest 10 seconds
|
347 |
+
return text, f'<div class="token-label"><span class="token-count">({tokens} tokens, ~{time_estimate}s generation time)</span></div>'
|
348 |
except Exception as e:
|
349 |
raise gr.Error(f"Failed to read file: {str(e)}")
|
350 |
|