Spaces:
Sleeping
Sleeping
Upload 2 files
Browse files- app.py +28 -19
- requirements.txt +3 -1
app.py
CHANGED
|
@@ -1,34 +1,43 @@
|
|
|
|
|
| 1 |
import gradio as gr
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2 |
import torchaudio
|
| 3 |
-
from speechbrain.inference.enhance import Denoise
|
| 4 |
|
| 5 |
-
|
| 6 |
-
denoiser = Denoise.from_hparams(
|
| 7 |
-
source="speechbrain/denoise",
|
| 8 |
-
savedir="denoise_model"
|
| 9 |
-
)
|
| 10 |
|
| 11 |
def enhance_vo(file, denoise_strength):
|
| 12 |
-
#
|
| 13 |
-
|
|
|
|
| 14 |
|
| 15 |
-
|
| 16 |
-
|
| 17 |
|
| 18 |
-
#
|
| 19 |
-
|
| 20 |
-
|
|
|
|
|
|
|
| 21 |
|
| 22 |
-
#
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 23 |
output = output / output.abs().max()
|
| 24 |
|
| 25 |
-
# Save
|
| 26 |
output_path = "enhanced_output.wav"
|
| 27 |
-
torchaudio.save(output_path, output,
|
| 28 |
|
| 29 |
return output_path
|
| 30 |
|
| 31 |
-
# Gradio app
|
| 32 |
interface = gr.Interface(
|
| 33 |
fn=enhance_vo,
|
| 34 |
inputs=[
|
|
@@ -36,8 +45,8 @@ interface = gr.Interface(
|
|
| 36 |
gr.Slider(0, 100, value=100, label="Noise Reduction Strength (%)")
|
| 37 |
],
|
| 38 |
outputs=gr.Audio(type="filepath", label="Enhanced Audio (WAV)"),
|
| 39 |
-
title="VO
|
| 40 |
-
description="Upload
|
| 41 |
)
|
| 42 |
|
| 43 |
interface.launch()
|
|
|
|
| 1 |
+
|
| 2 |
import gradio as gr
|
| 3 |
+
import requests
|
| 4 |
+
import soundfile as sf
|
| 5 |
+
import io
|
| 6 |
+
import torch
|
| 7 |
import torchaudio
|
|
|
|
| 8 |
|
| 9 |
+
API_URL = "https://hf.space/embed/akhaliq/denoise-audio/+/api/predict"
|
|
|
|
|
|
|
|
|
|
|
|
|
| 10 |
|
| 11 |
def enhance_vo(file, denoise_strength):
|
| 12 |
+
# Step 1: Read audio and send to remote model
|
| 13 |
+
with open(file, "rb") as f:
|
| 14 |
+
response = requests.post(API_URL, files={"data": f})
|
| 15 |
|
| 16 |
+
if response.status_code != 200:
|
| 17 |
+
raise Exception("Denoising model failed to process audio.")
|
| 18 |
|
| 19 |
+
# Step 2: Get denoised audio back
|
| 20 |
+
response_data = response.json()
|
| 21 |
+
url = response_data["data"][0]["url"]
|
| 22 |
+
audio_response = requests.get(url)
|
| 23 |
+
denoised_bytes = io.BytesIO(audio_response.content)
|
| 24 |
|
| 25 |
+
# Step 3: Load both original and denoised audio
|
| 26 |
+
orig_waveform, sr = torchaudio.load(file)
|
| 27 |
+
denoised_waveform, _ = torchaudio.load(denoised_bytes)
|
| 28 |
+
|
| 29 |
+
# Step 4: Blend based on slider value
|
| 30 |
+
blend_ratio = denoise_strength / 100.0
|
| 31 |
+
output = (1 - blend_ratio) * orig_waveform + blend_ratio * denoised_waveform
|
| 32 |
output = output / output.abs().max()
|
| 33 |
|
| 34 |
+
# Step 5: Save to file
|
| 35 |
output_path = "enhanced_output.wav"
|
| 36 |
+
torchaudio.save(output_path, output, sr)
|
| 37 |
|
| 38 |
return output_path
|
| 39 |
|
| 40 |
+
# Gradio app UI
|
| 41 |
interface = gr.Interface(
|
| 42 |
fn=enhance_vo,
|
| 43 |
inputs=[
|
|
|
|
| 45 |
gr.Slider(0, 100, value=100, label="Noise Reduction Strength (%)")
|
| 46 |
],
|
| 47 |
outputs=gr.Audio(type="filepath", label="Enhanced Audio (WAV)"),
|
| 48 |
+
title="Adobe-style VO Enhancer (Online Model)",
|
| 49 |
+
description="Upload VO audio (MP3/WAV), adjust slider, and download cleaned WAV file."
|
| 50 |
)
|
| 51 |
|
| 52 |
interface.launch()
|
requirements.txt
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
|
|
| 1 |
gradio
|
|
|
|
| 2 |
torchaudio
|
| 3 |
-
|
|
|
|
| 1 |
+
|
| 2 |
gradio
|
| 3 |
+
requests
|
| 4 |
torchaudio
|
| 5 |
+
soundfile
|