Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,57 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
import os
|
| 3 |
+
from huggingface_hub import hf_hub_download
|
| 4 |
+
from audio_separator.separator import Separator
|
| 5 |
+
|
| 6 |
+
# --- Configuration ---
|
| 7 |
+
# REPO_ID: The repository containing the model weights
|
| 8 |
+
REPO_ID = "anvuew/dereverb_room"
|
| 9 |
+
|
| 10 |
+
# MODEL_FILENAME: specific .ckpt or .pth file in that repo
|
| 11 |
+
# IMPORTANT: Check the repo and replace this with the actual filename
|
| 12 |
+
MODEL_FILENAME = "dereverb_room_anvuew_sdr_13.7432.ckpt"
|
| 13 |
+
|
| 14 |
+
# CONFIG_FILENAME: specific .yaml file in that repo
|
| 15 |
+
# IMPORTANT: Check the repo and replace this with the actual filename
|
| 16 |
+
CONFIG_FILENAME = "dereverb_room_anvuew.yaml"
|
| 17 |
+
# ---------------------
|
| 18 |
+
|
| 19 |
+
def inference(audio_path):
|
| 20 |
+
if not audio_path:
|
| 21 |
+
return None
|
| 22 |
+
|
| 23 |
+
print("Downloading model files if missing...")
|
| 24 |
+
model_path = hf_hub_download(repo_id=REPO_ID, filename=MODEL_FILENAME)
|
| 25 |
+
config_path = hf_hub_download(repo_id=REPO_ID, filename=CONFIG_FILENAME)
|
| 26 |
+
|
| 27 |
+
print("Initializing separator...")
|
| 28 |
+
# Initialize the separator with the specifically downloaded model and config
|
| 29 |
+
separator = Separator(
|
| 30 |
+
model_file_path=model_path,
|
| 31 |
+
config_file_path=config_path,
|
| 32 |
+
output_dir=".",
|
| 33 |
+
output_format="FLAC"
|
| 34 |
+
)
|
| 35 |
+
|
| 36 |
+
print("Starting inference...")
|
| 37 |
+
# The model works by separating 'reverb' from the audio.
|
| 38 |
+
# We want the audio *without* reverb, which is usually the primary stem.
|
| 39 |
+
output_files = separator.separate(audio_path)
|
| 40 |
+
|
| 41 |
+
print(f"Separation complete. Outputs: {output_files}")
|
| 42 |
+
# Return the first output file (usually the dereverbed/clean audio)
|
| 43 |
+
return output_files[0]
|
| 44 |
+
|
| 45 |
+
# Create Gradio Interface
|
| 46 |
+
with gr.Blocks(title="Dereverb Room Web UI") as demo:
|
| 47 |
+
gr.Markdown("# Dereverb Room Inference")
|
| 48 |
+
gr.Markdown(f"Inference using model from [{REPO_ID}](https://huggingface.co/{REPO_ID})")
|
| 49 |
+
|
| 50 |
+
with gr.Row():
|
| 51 |
+
input_audio = gr.Audio(label="Upload Audio", type="filepath")
|
| 52 |
+
output_audio = gr.Audio(label="Dereverbed Audio", type="filepath", interactive=False)
|
| 53 |
+
|
| 54 |
+
process_btn = gr.Button("Remove Reverb")
|
| 55 |
+
process_btn.click(fn=inference, inputs=input_audio, outputs=output_audio)
|
| 56 |
+
|
| 57 |
+
demo.launch()
|