Spaces:
Build error
Build error
Update app.py
Browse files
app.py
CHANGED
|
@@ -17,7 +17,6 @@ from PIL import Image
|
|
| 17 |
import zipfile
|
| 18 |
import datetime
|
| 19 |
import librosa
|
| 20 |
-
import joblib
|
| 21 |
import warnings
|
| 22 |
from faster_whisper import WhisperModel
|
| 23 |
from mutagen.mp3 import MP3
|
|
@@ -267,7 +266,7 @@ def batch_process_audio(files, selected_effects, isolate_vocals, preset_name, ex
|
|
| 267 |
except Exception as e:
|
| 268 |
return None, f"❌ Batch processing failed: {str(e)}"
|
| 269 |
|
| 270 |
-
# ===
|
| 271 |
whisper_model = WhisperModel("base")
|
| 272 |
|
| 273 |
def transcribe_audio(audio_path):
|
|
@@ -353,10 +352,42 @@ def mix_tracks(track1, track2, volume_offset=0):
|
|
| 353 |
|
| 354 |
# === Voice Style Transfer (Dummy) ===
|
| 355 |
def apply_style_transfer(audio_path, mood="Happy"):
|
| 356 |
-
# Replace with real model later
|
| 357 |
return audio_path
|
| 358 |
|
| 359 |
-
# ===
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 360 |
effect_options = [
|
| 361 |
"Noise Reduction",
|
| 362 |
"Compress Dynamic Range",
|
|
@@ -436,13 +467,13 @@ with gr.Blocks(title="AI Audio Studio", css="style.css") as demo:
|
|
| 436 |
clear_btn=None
|
| 437 |
)
|
| 438 |
|
| 439 |
-
# --- Transcribe & Edit
|
| 440 |
with gr.Tab("📝 Transcribe & Edit"):
|
| 441 |
gr.Interface(
|
| 442 |
fn=transcribe_audio,
|
| 443 |
inputs=gr.Audio(label="Upload Audio", type="filepath"),
|
| 444 |
outputs=gr.Textbox(label="Transcribed Text", lines=10),
|
| 445 |
-
title="Transcribe Spoken Content",
|
| 446 |
description="Convert voice to text and edit it before exporting again."
|
| 447 |
)
|
| 448 |
|
|
@@ -473,58 +504,50 @@ with gr.Blocks(title="AI Audio Studio", css="style.css") as demo:
|
|
| 473 |
)
|
| 474 |
|
| 475 |
# --- Voice Cloning (Dummy) ===
|
| 476 |
-
def clone_voice(*args):
|
| 477 |
-
return "⚠️ Voice cloning requires additional setup"
|
| 478 |
-
|
| 479 |
with gr.Tab("🎭 Voice Cloning (Dubbing)"):
|
| 480 |
gr.Interface(
|
| 481 |
-
fn=
|
| 482 |
inputs=[
|
| 483 |
gr.File(label="Source Voice Clip"),
|
| 484 |
-
gr.
|
| 485 |
-
gr.Textbox(label="Text to Clone", lines=5)
|
| 486 |
],
|
| 487 |
-
outputs=gr.Audio(label="
|
| 488 |
-
title="Replace
|
| 489 |
description="Clone voice from source to target speaker using AI"
|
| 490 |
)
|
| 491 |
|
| 492 |
# --- Auto-Save / Resume Sessions ===
|
| 493 |
-
session_state = gr.State()
|
| 494 |
-
|
| 495 |
-
def auto_save_session(audio, preset, effects):
|
| 496 |
-
return {"audio": audio, "preset": preset, "effects": effects}
|
| 497 |
-
|
| 498 |
-
def auto_load_session(session):
|
| 499 |
-
if session and "audio" in session:
|
| 500 |
-
return session["audio"], session["preset"], session["effects"]
|
| 501 |
-
return None, None, None
|
| 502 |
-
|
| 503 |
with gr.Tab("🧾 Auto-Save & Resume"):
|
| 504 |
-
gr.
|
| 505 |
-
|
| 506 |
-
|
| 507 |
-
|
| 508 |
-
|
| 509 |
-
|
| 510 |
-
|
| 511 |
-
|
| 512 |
-
|
| 513 |
-
|
| 514 |
-
|
| 515 |
-
)
|
| 516 |
-
|
| 517 |
-
|
| 518 |
-
|
| 519 |
-
|
| 520 |
-
|
| 521 |
-
|
| 522 |
-
|
| 523 |
-
|
| 524 |
-
|
| 525 |
-
|
| 526 |
-
|
| 527 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 528 |
)
|
| 529 |
|
| 530 |
# --- VAD – Detect & Remove Silence ===
|
|
@@ -547,7 +570,7 @@ with gr.Blocks(title="AI Audio Studio", css="style.css") as demo:
|
|
| 547 |
fn=save_project,
|
| 548 |
inputs=[
|
| 549 |
gr.File(label="Original Audio"),
|
| 550 |
-
gr.Dropdown(choices=preset_names, label="Used Preset", value=preset_names[0]),
|
| 551 |
gr.CheckboxGroup(choices=effect_options, label="Applied Effects")
|
| 552 |
],
|
| 553 |
outputs=gr.File(label="Project File (.aiproj)"),
|
|
@@ -577,10 +600,10 @@ with gr.Blocks(title="AI Audio Studio", css="style.css") as demo:
|
|
| 577 |
],
|
| 578 |
outputs=gr.File(label="Mixed Output"),
|
| 579 |
title="Overlay Two Tracks",
|
| 580 |
-
description="Mix or subtract two audio files."
|
| 581 |
)
|
| 582 |
|
| 583 |
-
# --- Voice Style Transfer
|
| 584 |
with gr.Tab("🧠 Voice Style Transfer"):
|
| 585 |
gr.Interface(
|
| 586 |
fn=apply_style_transfer,
|
|
@@ -593,4 +616,17 @@ with gr.Blocks(title="AI Audio Studio", css="style.css") as demo:
|
|
| 593 |
description="Shift the emotional style of any voice clip."
|
| 594 |
)
|
| 595 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 596 |
demo.launch()
|
|
|
|
| 17 |
import zipfile
|
| 18 |
import datetime
|
| 19 |
import librosa
|
|
|
|
| 20 |
import warnings
|
| 21 |
from faster_whisper import WhisperModel
|
| 22 |
from mutagen.mp3 import MP3
|
|
|
|
| 266 |
except Exception as e:
|
| 267 |
return None, f"❌ Batch processing failed: {str(e)}"
|
| 268 |
|
| 269 |
+
# === Transcribe & Edit Tab ===
|
| 270 |
whisper_model = WhisperModel("base")
|
| 271 |
|
| 272 |
def transcribe_audio(audio_path):
|
|
|
|
| 352 |
|
| 353 |
# === Voice Style Transfer (Dummy) ===
|
| 354 |
def apply_style_transfer(audio_path, mood="Happy"):
|
|
|
|
| 355 |
return audio_path
|
| 356 |
|
| 357 |
+
# === Load Custom Plugins ===
|
| 358 |
+
def load_plugin(plugin_file, audio_file):
|
| 359 |
+
try:
|
| 360 |
+
from importlib.util import spec_from_file_location, module_from_spec
|
| 361 |
+
spec = spec_from_file_location("plugin", plugin_file.name)
|
| 362 |
+
plugin = module_from_spec(spec)
|
| 363 |
+
spec.loader.exec_module(plugin)
|
| 364 |
+
|
| 365 |
+
# Run plugin
|
| 366 |
+
audio = AudioSegment.from_file(audio_file)
|
| 367 |
+
processed = plugin.process(audio)
|
| 368 |
+
|
| 369 |
+
out_path = os.path.join(tempfile.gettempdir(), "plugin_output.wav")
|
| 370 |
+
processed.export(out_path, format="wav")
|
| 371 |
+
return out_path
|
| 372 |
+
except Exception as e:
|
| 373 |
+
return f"⚠️ Plugin error: {str(e)}"
|
| 374 |
+
|
| 375 |
+
# === Auto-Save / Resume Session Handling ===
|
| 376 |
+
session_state = gr.State()
|
| 377 |
+
|
| 378 |
+
def save_or_resume_session(audio, preset, effects, action="save"):
|
| 379 |
+
if action == "save":
|
| 380 |
+
return {"audio": audio, "preset": preset, "effects": effects}, None, None, None
|
| 381 |
+
elif action == "load" and audio is not None:
|
| 382 |
+
return (
|
| 383 |
+
None,
|
| 384 |
+
audio.get("audio"),
|
| 385 |
+
audio.get("preset"),
|
| 386 |
+
audio.get("effects")
|
| 387 |
+
)
|
| 388 |
+
return None, None, None, None
|
| 389 |
+
|
| 390 |
+
# === UI ===
|
| 391 |
effect_options = [
|
| 392 |
"Noise Reduction",
|
| 393 |
"Compress Dynamic Range",
|
|
|
|
| 467 |
clear_btn=None
|
| 468 |
)
|
| 469 |
|
| 470 |
+
# --- Transcribe & Edit ---
|
| 471 |
with gr.Tab("📝 Transcribe & Edit"):
|
| 472 |
gr.Interface(
|
| 473 |
fn=transcribe_audio,
|
| 474 |
inputs=gr.Audio(label="Upload Audio", type="filepath"),
|
| 475 |
outputs=gr.Textbox(label="Transcribed Text", lines=10),
|
| 476 |
+
title="Transcribe & Edit Spoken Content",
|
| 477 |
description="Convert voice to text and edit it before exporting again."
|
| 478 |
)
|
| 479 |
|
|
|
|
| 504 |
)
|
| 505 |
|
| 506 |
# --- Voice Cloning (Dummy) ===
|
|
|
|
|
|
|
|
|
|
| 507 |
with gr.Tab("🎭 Voice Cloning (Dubbing)"):
|
| 508 |
gr.Interface(
|
| 509 |
+
fn=apply_style_transfer,
|
| 510 |
inputs=[
|
| 511 |
gr.File(label="Source Voice Clip"),
|
| 512 |
+
gr.Radio(["Happy", "Sad", "Angry", "Calm"], label="Choose Tone")
|
|
|
|
| 513 |
],
|
| 514 |
+
outputs=gr.Audio(label="Stylized Output", type="filepath"),
|
| 515 |
+
title="Replace Voice Using AI",
|
| 516 |
description="Clone voice from source to target speaker using AI"
|
| 517 |
)
|
| 518 |
|
| 519 |
# --- Auto-Save / Resume Sessions ===
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 520 |
with gr.Tab("🧾 Auto-Save & Resume"):
|
| 521 |
+
gr.Markdown("Save your current session and come back later.")
|
| 522 |
+
|
| 523 |
+
action_radio = gr.Radio(["save", "load"], label="Action", value="save")
|
| 524 |
+
audio_input = gr.Audio(label="Upload or Load Audio", type="filepath")
|
| 525 |
+
preset_dropdown = gr.Dropdown(choices=preset_names, label="Used Preset", value=preset_names[0] if preset_names else None)
|
| 526 |
+
effect_checkbox = gr.CheckboxGroup(choices=effect_options, label="Applied Effects")
|
| 527 |
+
save_btn = gr.Button("Save or Load Session")
|
| 528 |
+
|
| 529 |
+
session_data = gr.State()
|
| 530 |
+
|
| 531 |
+
loaded_audio = gr.Audio(label="Loaded Audio", type="filepath")
|
| 532 |
+
loaded_preset = gr.Dropdown(choices=preset_names, label="Loaded Preset")
|
| 533 |
+
loaded_effects = gr.CheckboxGroup(choices=effect_options, label="Loaded Effects")
|
| 534 |
+
|
| 535 |
+
def handle_action(audio, preset, effects, action):
|
| 536 |
+
if action == "save":
|
| 537 |
+
return {"audio": audio, "preset": preset, "effects": effects}, None, None, None
|
| 538 |
+
elif action == "load" and isinstance(audio, dict):
|
| 539 |
+
return (
|
| 540 |
+
None,
|
| 541 |
+
audio.get("audio"),
|
| 542 |
+
audio.get("preset"),
|
| 543 |
+
audio.get("effects")
|
| 544 |
+
)
|
| 545 |
+
return None, None, None, None
|
| 546 |
+
|
| 547 |
+
save_btn.click(
|
| 548 |
+
fn=handle_action,
|
| 549 |
+
inputs=[audio_input, preset_dropdown, effect_checkbox, action_radio],
|
| 550 |
+
outputs=[session_data, loaded_audio, loaded_preset, loaded_effects]
|
| 551 |
)
|
| 552 |
|
| 553 |
# --- VAD – Detect & Remove Silence ===
|
|
|
|
| 570 |
fn=save_project,
|
| 571 |
inputs=[
|
| 572 |
gr.File(label="Original Audio"),
|
| 573 |
+
gr.Dropdown(choices=preset_names, label="Used Preset", value=preset_names[0] if preset_names else None),
|
| 574 |
gr.CheckboxGroup(choices=effect_options, label="Applied Effects")
|
| 575 |
],
|
| 576 |
outputs=gr.File(label="Project File (.aiproj)"),
|
|
|
|
| 600 |
],
|
| 601 |
outputs=gr.File(label="Mixed Output"),
|
| 602 |
title="Overlay Two Tracks",
|
| 603 |
+
description="Mix, blend, or subtract two audio files."
|
| 604 |
)
|
| 605 |
|
| 606 |
+
# --- Voice Style Transfer ===
|
| 607 |
with gr.Tab("🧠 Voice Style Transfer"):
|
| 608 |
gr.Interface(
|
| 609 |
fn=apply_style_transfer,
|
|
|
|
| 616 |
description="Shift the emotional style of any voice clip."
|
| 617 |
)
|
| 618 |
|
| 619 |
+
# --- Custom Effect Plugin System ===
|
| 620 |
+
with gr.Tab("🧩 Load Custom Effect"):
|
| 621 |
+
gr.Interface(
|
| 622 |
+
fn=load_plugin,
|
| 623 |
+
inputs=[
|
| 624 |
+
gr.File(label="Upload .py plugin"),
|
| 625 |
+
gr.Audio(label="Upload Audio", type="filepath")
|
| 626 |
+
],
|
| 627 |
+
outputs=gr.Audio(label="Processed Output", type="filepath"),
|
| 628 |
+
title="Run Your Own Python Effect",
|
| 629 |
+
description="Upload a .py file with a 'process' function"
|
| 630 |
+
)
|
| 631 |
+
|
| 632 |
demo.launch()
|