Spaces:
Running on Zero
Running on Zero
Move login button into tab container and force activate
Browse files
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.
|
| 1401 |
-
gr.
|
| 1402 |
-
|
| 1403 |
-
|
| 1404 |
-
|
| 1405 |
-
|
| 1406 |
-
|
| 1407 |
-
|
| 1408 |
-
|
| 1409 |
-
|
| 1410 |
-
|
| 1411 |
-
|
| 1412 |
-
|
| 1413 |
-
|
| 1414 |
-
|
| 1415 |
-
|
| 1416 |
-
|
| 1417 |
-
|
| 1418 |
-
|
| 1419 |
-
|
| 1420 |
-
|
| 1421 |
-
|
| 1422 |
-
|
| 1423 |
-
|
| 1424 |
-
|
| 1425 |
-
|
| 1426 |
-
|
| 1427 |
-
|
| 1428 |
-
|
| 1429 |
-
|
| 1430 |
-
|
| 1431 |
-
|
| 1432 |
-
|
| 1433 |
-
|
| 1434 |
-
|
| 1435 |
-
|
| 1436 |
-
|
| 1437 |
-
|
| 1438 |
-
|
| 1439 |
-
|
| 1440 |
-
|
| 1441 |
-
|
| 1442 |
-
|
| 1443 |
-
|
| 1444 |
-
|
| 1445 |
-
|
| 1446 |
-
|
| 1447 |
-
|
| 1448 |
-
|
| 1449 |
-
|
| 1450 |
-
|
| 1451 |
-
|
| 1452 |
-
|
| 1453 |
-
|
| 1454 |
-
|
| 1455 |
-
|
| 1456 |
-
|
| 1457 |
-
|
| 1458 |
-
|
| 1459 |
-
|
| 1460 |
-
|
| 1461 |
-
|
| 1462 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1463 |
|
| 1464 |
-
|
| 1465 |
-
|
| 1466 |
-
|
| 1467 |
-
|
| 1468 |
-
|
| 1469 |
-
|
| 1470 |
-
|
| 1471 |
-
|
| 1472 |
-
|
| 1473 |
-
|
| 1474 |
-
|
| 1475 |
-
|
| 1476 |
-
|
| 1477 |
-
|
| 1478 |
-
|
| 1479 |
-
|
| 1480 |
-
|
| 1481 |
-
|
| 1482 |
-
|
| 1483 |
-
|
| 1484 |
-
|
| 1485 |
-
|
| 1486 |
-
|
| 1487 |
-
|
| 1488 |
-
|
| 1489 |
-
|
| 1490 |
-
|
| 1491 |
-
|
| 1492 |
-
|
| 1493 |
-
|
| 1494 |
-
|
| 1495 |
-
|
| 1496 |
-
|
| 1497 |
-
|
| 1498 |
-
|
| 1499 |
-
|
| 1500 |
-
|
| 1501 |
-
|
| 1502 |
-
|
| 1503 |
-
|
| 1504 |
-
|
| 1505 |
-
|
| 1506 |
-
|
| 1507 |
-
|
| 1508 |
-
|
| 1509 |
-
|
| 1510 |
-
|
| 1511 |
-
|
| 1512 |
-
|
| 1513 |
-
|
| 1514 |
-
|
| 1515 |
-
|
| 1516 |
-
|
| 1517 |
-
|
| 1518 |
-
|
| 1519 |
-
|
| 1520 |
-
|
| 1521 |
-
|
| 1522 |
-
|
| 1523 |
-
|
| 1524 |
-
|
| 1525 |
-
|
| 1526 |
-
|
| 1527 |
-
|
| 1528 |
-
|
| 1529 |
-
|
| 1530 |
-
|
| 1531 |
-
|
| 1532 |
-
|
| 1533 |
-
|
| 1534 |
-
|
| 1535 |
-
|
| 1536 |
-
|
| 1537 |
-
|
| 1538 |
-
|
| 1539 |
-
|
| 1540 |
-
|
| 1541 |
-
|
| 1542 |
-
|
| 1543 |
-
|
| 1544 |
-
|
| 1545 |
-
|
| 1546 |
-
|
| 1547 |
-
|
| 1548 |
-
|
| 1549 |
-
|
| 1550 |
-
|
| 1551 |
-
|
| 1552 |
-
|
| 1553 |
-
|
| 1554 |
-
|
| 1555 |
-
|
| 1556 |
-
|
| 1557 |
-
|
| 1558 |
-
|
| 1559 |
-
|
| 1560 |
-
|
| 1561 |
-
|
| 1562 |
-
|
| 1563 |
-
|
| 1564 |
-
|
| 1565 |
-
|
| 1566 |
-
|
| 1567 |
-
|
| 1568 |
-
|
| 1569 |
-
|
| 1570 |
|
| 1571 |
-
|
| 1572 |
-
|
| 1573 |
-
|
| 1574 |
-
|
| 1575 |
-
|
| 1576 |
-
|
| 1577 |
-
|
| 1578 |
-
|
| 1579 |
-
|
| 1580 |
-
|
| 1581 |
-
|
| 1582 |
-
|
| 1583 |
-
|
| 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()
|