Reza2kn commited on
Commit
f812300
·
verified ·
1 Parent(s): 1fbcd6e

Move login button into tab container and force activate

Browse files
Files changed (1) hide show
  1. app.py +191 -183
app.py CHANGED
@@ -13,6 +13,7 @@ from pathlib import Path
13
  from typing import List, Optional, Tuple
14
 
15
  import gradio as gr
 
16
  import librosa
17
  import numpy as np
18
  import soundfile as sf
@@ -1397,191 +1398,198 @@ with gr.Blocks(title="Representation Chizzler") as demo:
1397
  "denoising. Use the Single File tab for ad-hoc processing or the Dataset tab "
1398
  "to clean and publish a dataset to the Hugging Face Hub."
1399
  )
1400
- with gr.Row():
1401
- gr.LoginButton()
1402
-
1403
- with gr.Tab("Single File"):
1404
- audio_input = gr.Audio(label="Upload Audio File", type="filepath")
1405
- vad_slider = gr.Slider(
1406
- minimum=0.1,
1407
- maximum=0.9,
1408
- value=0.5,
1409
- step=0.1,
1410
- label="VAD Threshold (higher = stricter voice detection)",
1411
- )
1412
- gap_slider = gr.Slider(
1413
- minimum=1.0,
1414
- maximum=10.0,
1415
- value=4.0,
1416
- step=0.5,
1417
- label="Max Silence Gap (seconds)",
1418
- )
1419
- normalize_checkbox = gr.Checkbox(
1420
- label="Normalize volume", value=True
1421
- )
1422
- target_db_slider = gr.Slider(
1423
- minimum=-35.0,
1424
- maximum=-10.0,
1425
- value=DEFAULT_TARGET_DBFS,
1426
- step=1.0,
1427
- label="Target loudness (dBFS)",
1428
- )
1429
- max_boost_slider = gr.Slider(
1430
- minimum=0.0,
1431
- maximum=30.0,
1432
- value=DEFAULT_MAX_BOOST_DB,
1433
- step=1.0,
1434
- label="Max boost (dB)",
1435
- )
1436
- max_atten_slider = gr.Slider(
1437
- minimum=0.0,
1438
- maximum=20.0,
1439
- value=DEFAULT_MAX_ATTEN_DB,
1440
- step=1.0,
1441
- label="Max attenuation (dB)",
1442
- )
1443
- run_button = gr.Button("Process Audio")
1444
- original_audio = gr.Audio(label="Original Audio")
1445
- vad_audio = gr.Audio(label="VAD Processed (Speech Only)")
1446
- denoised_audio = gr.Audio(label="Final Denoised")
1447
- details_box = gr.Textbox(label="Processing Details", lines=10)
1448
-
1449
- run_button.click(
1450
- fn=gradio_single_file,
1451
- inputs=[
1452
- audio_input,
1453
- vad_slider,
1454
- gap_slider,
1455
- normalize_checkbox,
1456
- target_db_slider,
1457
- max_boost_slider,
1458
- max_atten_slider,
1459
- ],
1460
- outputs=[original_audio, vad_audio, denoised_audio, details_box],
1461
- concurrency_limit=1,
1462
- )
 
 
 
 
 
 
 
1463
 
1464
- with gr.Tab("Dataset to Hub"):
1465
- dataset_id_input = gr.Textbox(
1466
- label="Dataset ID or URL",
1467
- value="https://huggingface.co/datasets/MohammadGholizadeh/fleurs-farsi",
1468
- )
1469
- config_input = gr.Textbox(label="Config (optional)", value="")
1470
- split_input = gr.Textbox(label="Split (optional, or 'all')", value="dev")
1471
- audio_column_input = gr.Textbox(
1472
- label="Audio column (optional, auto-detect if empty)", value=""
1473
- )
1474
- output_repo_input = gr.Textbox(
1475
- label="Output dataset repo (optional)", value=""
1476
- )
1477
- private_checkbox = gr.Checkbox(label="Create private repo", value=False)
1478
- max_examples_input = gr.Number(
1479
- label="Max examples per split (optional)", value=None
1480
- )
1481
- resume_checkbox = gr.Checkbox(
1482
- label="Resume from cached shards", value=True
1483
- )
1484
- auto_resume_checkbox = gr.Checkbox(
1485
- label="Auto-resume on ZeroGPU preemption",
1486
- value=DEFAULT_AUTO_RESUME,
1487
- )
1488
- cache_to_hub_checkbox = gr.Checkbox(
1489
- label="Cache shards on Hub (recommended for ZeroGPU)",
1490
- value=DEFAULT_CACHE_TO_HUB,
1491
- )
1492
- shard_size_input = gr.Number(
1493
- label="Shard size (examples)", value=25
1494
- )
1495
- max_shards_input = gr.Number(
1496
- label="Max shards per run (ZeroGPU: 1-5, 0 = no limit)",
1497
- value=DEFAULT_MAX_SHARDS_PER_RUN,
1498
- )
1499
- vad_slider_ds = gr.Slider(
1500
- minimum=0.1,
1501
- maximum=0.9,
1502
- value=0.5,
1503
- step=0.1,
1504
- label="VAD Threshold",
1505
- )
1506
- gap_slider_ds = gr.Slider(
1507
- minimum=1.0,
1508
- maximum=10.0,
1509
- value=4.0,
1510
- step=0.5,
1511
- label="Max Silence Gap (seconds)",
1512
- )
1513
- normalize_checkbox_ds = gr.Checkbox(
1514
- label="Normalize volume", value=True
1515
- )
1516
- target_db_slider_ds = gr.Slider(
1517
- minimum=-35.0,
1518
- maximum=-10.0,
1519
- value=DEFAULT_TARGET_DBFS,
1520
- step=1.0,
1521
- label="Target loudness (dBFS)",
1522
- )
1523
- max_boost_slider_ds = gr.Slider(
1524
- minimum=0.0,
1525
- maximum=30.0,
1526
- value=DEFAULT_MAX_BOOST_DB,
1527
- step=1.0,
1528
- label="Max boost (dB)",
1529
- )
1530
- max_atten_slider_ds = gr.Slider(
1531
- minimum=0.0,
1532
- maximum=20.0,
1533
- value=DEFAULT_MAX_ATTEN_DB,
1534
- step=1.0,
1535
- label="Max attenuation (dB)",
1536
- )
1537
- process_button = gr.Button(
1538
- "Process/Resume Dataset (cache & push when complete)"
1539
- )
1540
- assemble_button = gr.Button(
1541
- "Assemble & Push Cached Dataset"
1542
- )
1543
- status_box = gr.Textbox(label="Status", lines=6)
1544
-
1545
- process_button.click(
1546
- fn=process_dataset_and_push,
1547
- inputs=[
1548
- dataset_id_input,
1549
- config_input,
1550
- split_input,
1551
- audio_column_input,
1552
- output_repo_input,
1553
- private_checkbox,
1554
- vad_slider_ds,
1555
- gap_slider_ds,
1556
- normalize_checkbox_ds,
1557
- target_db_slider_ds,
1558
- max_boost_slider_ds,
1559
- max_atten_slider_ds,
1560
- max_examples_input,
1561
- resume_checkbox,
1562
- auto_resume_checkbox,
1563
- shard_size_input,
1564
- cache_to_hub_checkbox,
1565
- max_shards_input,
1566
- ],
1567
- outputs=[status_box],
1568
- concurrency_limit=1,
1569
- )
1570
 
1571
- assemble_button.click(
1572
- fn=assemble_cached_dataset_and_push,
1573
- inputs=[
1574
- dataset_id_input,
1575
- config_input,
1576
- split_input,
1577
- audio_column_input,
1578
- output_repo_input,
1579
- private_checkbox,
1580
- cache_to_hub_checkbox,
1581
- ],
1582
- outputs=[status_box],
1583
- concurrency_limit=1,
1584
- )
1585
 
1586
 
1587
  demo.queue()
 
13
  from typing import List, Optional, Tuple
14
 
15
  import gradio as gr
16
+ from gradio.context import get_blocks_context
17
  import librosa
18
  import numpy as np
19
  import soundfile as sf
 
1398
  "denoising. Use the Single File tab for ad-hoc processing or the Dataset tab "
1399
  "to clean and publish a dataset to the Hugging Face Hub."
1400
  )
1401
+ with gr.Column():
1402
+ with gr.Row():
1403
+ login_button = gr.LoginButton()
1404
+ if get_blocks_context() is None:
1405
+ try:
1406
+ login_button.activate()
1407
+ except Exception:
1408
+ pass
1409
+
1410
+ with gr.Tabs():
1411
+ with gr.Tab("Single File"):
1412
+ audio_input = gr.Audio(label="Upload Audio File", type="filepath")
1413
+ vad_slider = gr.Slider(
1414
+ minimum=0.1,
1415
+ maximum=0.9,
1416
+ value=0.5,
1417
+ step=0.1,
1418
+ label="VAD Threshold (higher = stricter voice detection)",
1419
+ )
1420
+ gap_slider = gr.Slider(
1421
+ minimum=1.0,
1422
+ maximum=10.0,
1423
+ value=4.0,
1424
+ step=0.5,
1425
+ label="Max Silence Gap (seconds)",
1426
+ )
1427
+ normalize_checkbox = gr.Checkbox(
1428
+ label="Normalize volume", value=True
1429
+ )
1430
+ target_db_slider = gr.Slider(
1431
+ minimum=-35.0,
1432
+ maximum=-10.0,
1433
+ value=DEFAULT_TARGET_DBFS,
1434
+ step=1.0,
1435
+ label="Target loudness (dBFS)",
1436
+ )
1437
+ max_boost_slider = gr.Slider(
1438
+ minimum=0.0,
1439
+ maximum=30.0,
1440
+ value=DEFAULT_MAX_BOOST_DB,
1441
+ step=1.0,
1442
+ label="Max boost (dB)",
1443
+ )
1444
+ max_atten_slider = gr.Slider(
1445
+ minimum=0.0,
1446
+ maximum=20.0,
1447
+ value=DEFAULT_MAX_ATTEN_DB,
1448
+ step=1.0,
1449
+ label="Max attenuation (dB)",
1450
+ )
1451
+ run_button = gr.Button("Process Audio")
1452
+ original_audio = gr.Audio(label="Original Audio")
1453
+ vad_audio = gr.Audio(label="VAD Processed (Speech Only)")
1454
+ denoised_audio = gr.Audio(label="Final Denoised")
1455
+ details_box = gr.Textbox(label="Processing Details", lines=10)
1456
+
1457
+ run_button.click(
1458
+ fn=gradio_single_file,
1459
+ inputs=[
1460
+ audio_input,
1461
+ vad_slider,
1462
+ gap_slider,
1463
+ normalize_checkbox,
1464
+ target_db_slider,
1465
+ max_boost_slider,
1466
+ max_atten_slider,
1467
+ ],
1468
+ outputs=[original_audio, vad_audio, denoised_audio, details_box],
1469
+ concurrency_limit=1,
1470
+ )
1471
 
1472
+ with gr.Tab("Dataset to Hub"):
1473
+ dataset_id_input = gr.Textbox(
1474
+ label="Dataset ID or URL",
1475
+ value="https://huggingface.co/datasets/MohammadGholizadeh/fleurs-farsi",
1476
+ )
1477
+ config_input = gr.Textbox(label="Config (optional)", value="")
1478
+ split_input = gr.Textbox(label="Split (optional, or 'all')", value="dev")
1479
+ audio_column_input = gr.Textbox(
1480
+ label="Audio column (optional, auto-detect if empty)", value=""
1481
+ )
1482
+ output_repo_input = gr.Textbox(
1483
+ label="Output dataset repo (optional)", value=""
1484
+ )
1485
+ private_checkbox = gr.Checkbox(label="Create private repo", value=False)
1486
+ max_examples_input = gr.Number(
1487
+ label="Max examples per split (optional)", value=None
1488
+ )
1489
+ resume_checkbox = gr.Checkbox(
1490
+ label="Resume from cached shards", value=True
1491
+ )
1492
+ auto_resume_checkbox = gr.Checkbox(
1493
+ label="Auto-resume on ZeroGPU preemption",
1494
+ value=DEFAULT_AUTO_RESUME,
1495
+ )
1496
+ cache_to_hub_checkbox = gr.Checkbox(
1497
+ label="Cache shards on Hub (recommended for ZeroGPU)",
1498
+ value=DEFAULT_CACHE_TO_HUB,
1499
+ )
1500
+ shard_size_input = gr.Number(
1501
+ label="Shard size (examples)", value=25
1502
+ )
1503
+ max_shards_input = gr.Number(
1504
+ label="Max shards per run (ZeroGPU: 1-5, 0 = no limit)",
1505
+ value=DEFAULT_MAX_SHARDS_PER_RUN,
1506
+ )
1507
+ vad_slider_ds = gr.Slider(
1508
+ minimum=0.1,
1509
+ maximum=0.9,
1510
+ value=0.5,
1511
+ step=0.1,
1512
+ label="VAD Threshold",
1513
+ )
1514
+ gap_slider_ds = gr.Slider(
1515
+ minimum=1.0,
1516
+ maximum=10.0,
1517
+ value=4.0,
1518
+ step=0.5,
1519
+ label="Max Silence Gap (seconds)",
1520
+ )
1521
+ normalize_checkbox_ds = gr.Checkbox(
1522
+ label="Normalize volume", value=True
1523
+ )
1524
+ target_db_slider_ds = gr.Slider(
1525
+ minimum=-35.0,
1526
+ maximum=-10.0,
1527
+ value=DEFAULT_TARGET_DBFS,
1528
+ step=1.0,
1529
+ label="Target loudness (dBFS)",
1530
+ )
1531
+ max_boost_slider_ds = gr.Slider(
1532
+ minimum=0.0,
1533
+ maximum=30.0,
1534
+ value=DEFAULT_MAX_BOOST_DB,
1535
+ step=1.0,
1536
+ label="Max boost (dB)",
1537
+ )
1538
+ max_atten_slider_ds = gr.Slider(
1539
+ minimum=0.0,
1540
+ maximum=20.0,
1541
+ value=DEFAULT_MAX_ATTEN_DB,
1542
+ step=1.0,
1543
+ label="Max attenuation (dB)",
1544
+ )
1545
+ process_button = gr.Button(
1546
+ "Process/Resume Dataset (cache & push when complete)"
1547
+ )
1548
+ assemble_button = gr.Button(
1549
+ "Assemble & Push Cached Dataset"
1550
+ )
1551
+ status_box = gr.Textbox(label="Status", lines=6)
1552
+
1553
+ process_button.click(
1554
+ fn=process_dataset_and_push,
1555
+ inputs=[
1556
+ dataset_id_input,
1557
+ config_input,
1558
+ split_input,
1559
+ audio_column_input,
1560
+ output_repo_input,
1561
+ private_checkbox,
1562
+ vad_slider_ds,
1563
+ gap_slider_ds,
1564
+ normalize_checkbox_ds,
1565
+ target_db_slider_ds,
1566
+ max_boost_slider_ds,
1567
+ max_atten_slider_ds,
1568
+ max_examples_input,
1569
+ resume_checkbox,
1570
+ auto_resume_checkbox,
1571
+ shard_size_input,
1572
+ cache_to_hub_checkbox,
1573
+ max_shards_input,
1574
+ ],
1575
+ outputs=[status_box],
1576
+ concurrency_limit=1,
1577
+ )
1578
 
1579
+ assemble_button.click(
1580
+ fn=assemble_cached_dataset_and_push,
1581
+ inputs=[
1582
+ dataset_id_input,
1583
+ config_input,
1584
+ split_input,
1585
+ audio_column_input,
1586
+ output_repo_input,
1587
+ private_checkbox,
1588
+ cache_to_hub_checkbox,
1589
+ ],
1590
+ outputs=[status_box],
1591
+ concurrency_limit=1,
1592
+ )
1593
 
1594
 
1595
  demo.queue()