yasserrmd commited on
Commit
7655cbd
·
verified ·
1 Parent(s): a6b8545

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +10 -237
app.py CHANGED
@@ -234,55 +234,23 @@ class VibeVoiceDemo:
234
 
235
 
236
  def load_example_scripts(self):
237
- """Load example scripts from the text_examples directory."""
238
  examples_dir = os.path.join(os.path.dirname(__file__), "text_examples")
239
  self.example_scripts = []
240
-
241
- # Check if text_examples directory exists
242
  if not os.path.exists(examples_dir):
243
- print(f"Warning: text_examples directory not found at {examples_dir}")
244
  return
245
-
246
- # Get all .txt files in the text_examples directory
247
- txt_files = sorted([f for f in os.listdir(examples_dir)
248
- if f.lower().endswith('.txt') and os.path.isfile(os.path.join(examples_dir, f))])
249
-
250
- for txt_file in txt_files:
251
- file_path = os.path.join(examples_dir, txt_file)
252
-
253
- import re
254
- # Check if filename contains a time pattern like "45min", "90min", etc.
255
- time_pattern = re.search(r'(\d+)min', txt_file.lower())
256
- if time_pattern:
257
- minutes = int(time_pattern.group(1))
258
- if minutes > 15:
259
- print(f"Skipping {txt_file}: duration {minutes} minutes exceeds 15-minute limit")
260
- continue
261
 
 
 
 
 
262
  try:
263
- with open(file_path, 'r', encoding='utf-8') as f:
264
  script_content = f.read().strip()
265
-
266
- # Remove empty lines and lines with only whitespace
267
- script_content = '\n'.join(line for line in script_content.split('\n') if line.strip())
268
-
269
- if not script_content:
270
- continue
271
-
272
- # Parse the script to determine number of speakers
273
- num_speakers = self._get_num_speakers_from_script(script_content)
274
-
275
- # Add to examples list as [num_speakers, script_content]
276
- self.example_scripts.append([num_speakers, script_content])
277
- print(f"Loaded example: {txt_file} with {num_speakers} speakers")
278
-
279
  except Exception as e:
280
- print(f"Error loading example script {txt_file}: {e}")
281
-
282
- if self.example_scripts:
283
- print(f"Successfully loaded {len(self.example_scripts)} example scripts")
284
- else:
285
- print("No example scripts were loaded")
286
 
287
 
288
  def convert_to_16_bit_wav(data):
@@ -295,202 +263,7 @@ def convert_to_16_bit_wav(data):
295
 
296
 
297
  def create_demo_interface(demo_instance: VibeVoiceDemo):
298
- custom_css = """ /* Modern light theme with gradients */
299
- .gradio-container {
300
- background: linear-gradient(135deg, #f8fafc 0%, #e2e8f0 100%);
301
- font-family: 'SF Pro Display', -apple-system, BlinkMacSystemFont, sans-serif;
302
- }
303
-
304
- /* Header styling */
305
- .main-header {
306
- background: linear-gradient(90deg, #667eea 0%, #764ba2 100%);
307
- padding: 2rem;
308
- border-radius: 20px;
309
- margin-bottom: 2rem;
310
- text-align: center;
311
- box-shadow: 0 10px 40px rgba(102, 126, 234, 0.3);
312
- }
313
-
314
- .main-header h1 {
315
- color: white;
316
- font-size: 2.5rem;
317
- font-weight: 700;
318
- margin: 0;
319
- text-shadow: 0 2px 4px rgba(0,0,0,0.3);
320
- }
321
-
322
- .main-header p {
323
- color: rgba(255,255,255,0.9);
324
- font-size: 1.1rem;
325
- margin: 0.5rem 0 0 0;
326
- }
327
-
328
- /* Card styling */
329
- .settings-card, .generation-card {
330
- background: rgba(255, 255, 255, 0.8);
331
- backdrop-filter: blur(10px);
332
- border: 1px solid rgba(226, 232, 240, 0.8);
333
- border-radius: 16px;
334
- padding: 1.5rem;
335
- margin-bottom: 1rem;
336
- box-shadow: 0 8px 32px rgba(0, 0, 0, 0.1);
337
- }
338
-
339
- /* Speaker selection styling */
340
- .speaker-grid {
341
- display: grid;
342
- gap: 1rem;
343
- margin-bottom: 1rem;
344
- }
345
-
346
- .speaker-item {
347
- background: linear-gradient(135deg, #e2e8f0 0%, #cbd5e1 100%);
348
- border: 1px solid rgba(148, 163, 184, 0.4);
349
- border-radius: 12px;
350
- padding: 1rem;
351
- color: #374151;
352
- font-weight: 500;
353
- }
354
-
355
- /* Streaming indicator */
356
- .streaming-indicator {
357
- display: inline-block;
358
- width: 10px;
359
- height: 10px;
360
- background: #22c55e;
361
- border-radius: 50%;
362
- margin-right: 8px;
363
- animation: pulse 1.5s infinite;
364
- }
365
-
366
- @keyframes pulse {
367
- 0% { opacity: 1; transform: scale(1); }
368
- 50% { opacity: 0.5; transform: scale(1.1); }
369
- 100% { opacity: 1; transform: scale(1); }
370
- }
371
-
372
- /* Queue status styling */
373
- .queue-status {
374
- background: linear-gradient(135deg, #f0f9ff 0%, #e0f2fe 100%);
375
- border: 1px solid rgba(14, 165, 233, 0.3);
376
- border-radius: 8px;
377
- padding: 0.75rem;
378
- margin: 0.5rem 0;
379
- text-align: center;
380
- font-size: 0.9rem;
381
- color: #0369a1;
382
- }
383
-
384
- .generate-btn {
385
- background: linear-gradient(135deg, #059669 0%, #0d9488 100%);
386
- border: none;
387
- border-radius: 12px;
388
- padding: 1rem 2rem;
389
- color: white;
390
- font-weight: 600;
391
- font-size: 1.1rem;
392
- box-shadow: 0 4px 20px rgba(5, 150, 105, 0.4);
393
- transition: all 0.3s ease;
394
- }
395
-
396
- .generate-btn:hover {
397
- transform: translateY(-2px);
398
- box-shadow: 0 6px 25px rgba(5, 150, 105, 0.6);
399
- }
400
-
401
- .stop-btn {
402
- background: linear-gradient(135deg, #ef4444 0%, #dc2626 100%);
403
- border: none;
404
- border-radius: 12px;
405
- padding: 1rem 2rem;
406
- color: white;
407
- font-weight: 600;
408
- font-size: 1.1rem;
409
- box-shadow: 0 4px 20px rgba(239, 68, 68, 0.4);
410
- transition: all 0.3s ease;
411
- }
412
-
413
- .stop-btn:hover {
414
- transform: translateY(-2px);
415
- box-shadow: 0 6px 25px rgba(239, 68, 68, 0.6);
416
- }
417
-
418
- /* Audio player styling */
419
- .audio-output {
420
- background: linear-gradient(135deg, #f1f5f9 0%, #e2e8f0 100%);
421
- border-radius: 16px;
422
- padding: 1.5rem;
423
- border: 1px solid rgba(148, 163, 184, 0.3);
424
- }
425
-
426
- .complete-audio-section {
427
- margin-top: 1rem;
428
- padding: 1rem;
429
- background: linear-gradient(135deg, #f0fdf4 0%, #dcfce7 100%);
430
- border: 1px solid rgba(34, 197, 94, 0.3);
431
- border-radius: 12px;
432
- }
433
-
434
- /* Text areas */
435
- .script-input, .log-output {
436
- background: rgba(255, 255, 255, 0.9) !important;
437
- border: 1px solid rgba(148, 163, 184, 0.4) !important;
438
- border-radius: 12px !important;
439
- color: #1e293b !important;
440
- font-family: 'JetBrains Mono', monospace !important;
441
- }
442
-
443
- .script-input::placeholder {
444
- color: #64748b !important;
445
- }
446
-
447
- /* Sliders */
448
- .slider-container {
449
- background: rgba(248, 250, 252, 0.8);
450
- border: 1px solid rgba(226, 232, 240, 0.6);
451
- border-radius: 8px;
452
- padding: 1rem;
453
- margin: 0.5rem 0;
454
- }
455
-
456
- /* Labels and text */
457
- .gradio-container label {
458
- color: #374151 !important;
459
- font-weight: 600 !important;
460
- }
461
-
462
- .gradio-container .markdown {
463
- color: #1f2937 !important;
464
- }
465
-
466
- /* Responsive design */
467
- @media (max-width: 768px) {
468
- .main-header h1 { font-size: 2rem; }
469
- .settings-card, .generation-card { padding: 1rem; }
470
- }
471
-
472
- /* Random example button styling - more subtle professional color */
473
- .random-btn {
474
- background: linear-gradient(135deg, #64748b 0%, #475569 100%);
475
- border: none;
476
- border-radius: 12px;
477
- padding: 1rem 1.5rem;
478
- color: white;
479
- font-weight: 600;
480
- font-size: 1rem;
481
- box-shadow: 0 4px 20px rgba(100, 116, 139, 0.3);
482
- transition: all 0.3s ease;
483
- display: inline-flex;
484
- align-items: center;
485
- gap: 0.5rem;
486
- }
487
-
488
- .random-btn:hover {
489
- transform: translateY(-2px);
490
- box-shadow: 0 6px 25px rgba(100, 116, 139, 0.4);
491
- background: linear-gradient(135deg, #475569 0%, #334155 100%);
492
- }
493
- """
494
 
495
  with gr.Blocks(
496
  title="VibeVoice - AI Podcast Generator",
 
234
 
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
 
255
 
256
  def convert_to_16_bit_wav(data):
 
263
 
264
 
265
  def create_demo_interface(demo_instance: VibeVoiceDemo):
266
+ custom_css = """ """
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
267
 
268
  with gr.Blocks(
269
  title="VibeVoice - AI Podcast Generator",