Update app.py
Browse files
app.py
CHANGED
|
@@ -15,6 +15,7 @@ import gradio as gr
|
|
| 15 |
import traceback
|
| 16 |
from uuid import uuid4
|
| 17 |
import zipfile
|
|
|
|
| 18 |
|
| 19 |
# === Pre-flight Check: Install missing dependency if needed ===
|
| 20 |
try:
|
|
@@ -356,7 +357,7 @@ def process_file(fp, cfg, params):
|
|
| 356 |
res['messages'].append(f"❌ ERROR:\n{tb}")
|
| 357 |
return res
|
| 358 |
|
| 359 |
-
def gradio_process(input_mode, uploads, path_in,
|
| 360 |
out_fmt, sr, bd, ch, mp3_br,
|
| 361 |
norm, pan, seg, dur, tu, viz, zip_enable):
|
| 362 |
logs = []
|
|
@@ -366,10 +367,27 @@ def gradio_process(input_mode, uploads, path_in,
|
|
| 366 |
if input_mode == "Path" and path_in.strip():
|
| 367 |
logs.append(f"Mode: Path ➞ {path_in}")
|
| 368 |
inputs = get_all_audio_files(path_in.strip())
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 369 |
else:
|
| 370 |
logs.append(f"Mode: Upload ➞ {len(uploads) if uploads else 0} file(s)")
|
| 371 |
inputs = [f.name for f in uploads] if uploads else []
|
| 372 |
|
|
|
|
|
|
|
| 373 |
# List each input file's original details
|
| 374 |
logs.append("=== Original File Details ===")
|
| 375 |
for fp in inputs:
|
|
@@ -453,7 +471,6 @@ def gradio_process(input_mode, uploads, path_in,
|
|
| 453 |
# === Handle ZIP option ===
|
| 454 |
final_paths = output_paths
|
| 455 |
if zip_enable:
|
| 456 |
-
# Determine base name
|
| 457 |
if input_mode == "Path" and path_in.strip():
|
| 458 |
base = os.path.basename(path_in.rstrip("/"))
|
| 459 |
else:
|
|
@@ -492,13 +509,22 @@ with gr.Blocks(title="Audio Preprocessor", theme=gr.themes.Soft()) as demo:
|
|
| 492 |
|
| 493 |
with gr.Row():
|
| 494 |
with gr.Column(scale=2):
|
| 495 |
-
input_mode = gr.Radio(
|
|
|
|
|
|
|
|
|
|
|
|
|
| 496 |
file_uploader = gr.File(file_count="multiple", file_types=["audio"], label="Upload Audio Files")
|
| 497 |
path_text = gr.Textbox(placeholder="/path/to/dir", label="Or Enter Path", visible=False)
|
|
|
|
| 498 |
input_mode.change(
|
| 499 |
-
lambda m: (
|
|
|
|
|
|
|
|
|
|
|
|
|
| 500 |
inputs=[input_mode],
|
| 501 |
-
outputs=[file_uploader, path_text]
|
| 502 |
)
|
| 503 |
with gr.Column(scale=3):
|
| 504 |
gr.Markdown("### Output Settings")
|
|
@@ -536,7 +562,7 @@ with gr.Blocks(title="Audio Preprocessor", theme=gr.themes.Soft()) as demo:
|
|
| 536 |
process_btn.click(
|
| 537 |
fn=gradio_process,
|
| 538 |
inputs=[
|
| 539 |
-
input_mode, file_uploader, path_text,
|
| 540 |
out_fmt, sample_rate, bit_depth, channels, mp3_bitrate,
|
| 541 |
norm_profile, panning_option, segmentation, duration, time_unit, visualize, zip_enable
|
| 542 |
],
|
|
|
|
| 15 |
import traceback
|
| 16 |
from uuid import uuid4
|
| 17 |
import zipfile
|
| 18 |
+
import gdown # for Google Drive downloads
|
| 19 |
|
| 20 |
# === Pre-flight Check: Install missing dependency if needed ===
|
| 21 |
try:
|
|
|
|
| 357 |
res['messages'].append(f"❌ ERROR:\n{tb}")
|
| 358 |
return res
|
| 359 |
|
| 360 |
+
def gradio_process(input_mode, uploads, path_in, drive_url,
|
| 361 |
out_fmt, sr, bd, ch, mp3_br,
|
| 362 |
norm, pan, seg, dur, tu, viz, zip_enable):
|
| 363 |
logs = []
|
|
|
|
| 367 |
if input_mode == "Path" and path_in.strip():
|
| 368 |
logs.append(f"Mode: Path ➞ {path_in}")
|
| 369 |
inputs = get_all_audio_files(path_in.strip())
|
| 370 |
+
elif input_mode == "Google Drive URL" and drive_url.strip():
|
| 371 |
+
logs.append(f"Mode: Google Drive ➞ {drive_url}")
|
| 372 |
+
# download into a temp dir
|
| 373 |
+
gd_dir = tempfile.mkdtemp(prefix="gdrive_")
|
| 374 |
+
if "folders" in drive_url:
|
| 375 |
+
# folder share
|
| 376 |
+
gdown.download_folder(drive_url, output=gd_dir, quiet=False)
|
| 377 |
+
else:
|
| 378 |
+
# single file or zip
|
| 379 |
+
out_target = os.path.join(gd_dir, "downloaded")
|
| 380 |
+
gdown.download(drive_url, out_target, quiet=False)
|
| 381 |
+
if out_target.lower().endswith(".zip"):
|
| 382 |
+
with zipfile.ZipFile(out_target, "r") as zf:
|
| 383 |
+
zf.extractall(gd_dir)
|
| 384 |
+
inputs = get_all_audio_files(gd_dir)
|
| 385 |
else:
|
| 386 |
logs.append(f"Mode: Upload ➞ {len(uploads) if uploads else 0} file(s)")
|
| 387 |
inputs = [f.name for f in uploads] if uploads else []
|
| 388 |
|
| 389 |
+
# ... rest of processing unchanged ...
|
| 390 |
+
|
| 391 |
# List each input file's original details
|
| 392 |
logs.append("=== Original File Details ===")
|
| 393 |
for fp in inputs:
|
|
|
|
| 471 |
# === Handle ZIP option ===
|
| 472 |
final_paths = output_paths
|
| 473 |
if zip_enable:
|
|
|
|
| 474 |
if input_mode == "Path" and path_in.strip():
|
| 475 |
base = os.path.basename(path_in.rstrip("/"))
|
| 476 |
else:
|
|
|
|
| 509 |
|
| 510 |
with gr.Row():
|
| 511 |
with gr.Column(scale=2):
|
| 512 |
+
input_mode = gr.Radio(
|
| 513 |
+
["Upload", "Path", "Google Drive URL"],
|
| 514 |
+
value="Upload",
|
| 515 |
+
label="Input Method"
|
| 516 |
+
)
|
| 517 |
file_uploader = gr.File(file_count="multiple", file_types=["audio"], label="Upload Audio Files")
|
| 518 |
path_text = gr.Textbox(placeholder="/path/to/dir", label="Or Enter Path", visible=False)
|
| 519 |
+
drive_url = gr.Textbox(placeholder="https://drive.google.com/...", label="Google Drive URL", visible=False)
|
| 520 |
input_mode.change(
|
| 521 |
+
lambda m: (
|
| 522 |
+
gr.update(visible=(m=="Upload")),
|
| 523 |
+
gr.update(visible=(m=="Path")),
|
| 524 |
+
gr.update(visible=(m=="Google Drive URL"))
|
| 525 |
+
),
|
| 526 |
inputs=[input_mode],
|
| 527 |
+
outputs=[file_uploader, path_text, drive_url]
|
| 528 |
)
|
| 529 |
with gr.Column(scale=3):
|
| 530 |
gr.Markdown("### Output Settings")
|
|
|
|
| 562 |
process_btn.click(
|
| 563 |
fn=gradio_process,
|
| 564 |
inputs=[
|
| 565 |
+
input_mode, file_uploader, path_text, drive_url,
|
| 566 |
out_fmt, sample_rate, bit_depth, channels, mp3_bitrate,
|
| 567 |
norm_profile, panning_option, segmentation, duration, time_unit, visualize, zip_enable
|
| 568 |
],
|