Spaces:
Paused
Paused
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,44 +1,76 @@
|
|
| 1 |
-
|
| 2 |
-
|
| 3 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 4 |
|
| 5 |
-
|
| 6 |
-
|
| 7 |
-
|
| 8 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 9 |
|
| 10 |
try:
|
| 11 |
-
# 1.
|
| 12 |
-
# The new 'process' method handles everything via the Cleanvoice API
|
| 13 |
-
logger.info("[Pipeline] Step 1: Denoising & Studio Processing...")
|
| 14 |
res = denoiser.process(
|
| 15 |
-
audio_input,
|
| 16 |
fillers=remove_fillers,
|
| 17 |
stutters=remove_stutters,
|
| 18 |
-
long_silences=remove_silences,
|
| 19 |
breath=remove_breaths,
|
| 20 |
mouth_sounds=remove_mouth
|
| 21 |
)
|
| 22 |
|
| 23 |
-
# 2.
|
| 24 |
-
|
| 25 |
-
# Use the processed audio path returned by the denoiser
|
| 26 |
-
transcript_data = transcriber.transcribe(res['audio_path'])
|
| 27 |
-
text = transcript_data['text']
|
| 28 |
|
| 29 |
-
# 3.
|
| 30 |
-
|
| 31 |
-
translated = translator.translate(text, target_lang)
|
| 32 |
|
| 33 |
-
# 4.
|
| 34 |
-
final_mp3 = os.path.join(
|
| 35 |
subprocess.run([
|
| 36 |
"ffmpeg", "-y", "-i", res['audio_path'],
|
| 37 |
"-codec:a", "libmp3lame", "-qscale:a", "2", final_mp3
|
| 38 |
], check=True)
|
| 39 |
|
| 40 |
-
return final_mp3,
|
| 41 |
-
|
| 42 |
except Exception as e:
|
| 43 |
-
logger.error(f"Pipeline
|
| 44 |
-
return None, f"Error: {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
import os
|
| 3 |
+
import subprocess
|
| 4 |
+
import logging
|
| 5 |
+
from datetime import datetime
|
| 6 |
+
|
| 7 |
+
from denoiser import Denoiser
|
| 8 |
+
from transcriber import Transcriber
|
| 9 |
+
from translator import Translator
|
| 10 |
+
|
| 11 |
+
logging.basicConfig(level=logging.INFO)
|
| 12 |
+
logger = logging.getLogger(__name__)
|
| 13 |
|
| 14 |
+
denoiser = Denoiser()
|
| 15 |
+
transcriber = Transcriber()
|
| 16 |
+
translator = Translator()
|
| 17 |
+
|
| 18 |
+
def run_pipeline(audio_input, remove_fillers, remove_stutters, remove_silences, remove_breaths, remove_mouth, target_lang):
|
| 19 |
+
if not audio_input: return None, "Please upload a file.", ""
|
| 20 |
+
|
| 21 |
+
out_dir = f"outputs/{datetime.now().strftime('%H%M%S')}"
|
| 22 |
+
os.makedirs(out_dir, exist_ok=True)
|
| 23 |
|
| 24 |
try:
|
| 25 |
+
# 1. Clean Audio (API + WhatsApp pre-conversion)
|
|
|
|
|
|
|
| 26 |
res = denoiser.process(
|
| 27 |
+
audio_input, out_dir,
|
| 28 |
fillers=remove_fillers,
|
| 29 |
stutters=remove_stutters,
|
| 30 |
+
long_silences=remove_silences,
|
| 31 |
breath=remove_breaths,
|
| 32 |
mouth_sounds=remove_mouth
|
| 33 |
)
|
| 34 |
|
| 35 |
+
# 2. Transcribe
|
| 36 |
+
transcript = transcriber.transcribe(res['audio_path'])['text']
|
|
|
|
|
|
|
|
|
|
| 37 |
|
| 38 |
+
# 3. Translate
|
| 39 |
+
translated = translator.translate(transcript, target_lang)
|
|
|
|
| 40 |
|
| 41 |
+
# 4. Final MP3 Export
|
| 42 |
+
final_mp3 = os.path.join(out_dir, "ClearWave_Final.mp3")
|
| 43 |
subprocess.run([
|
| 44 |
"ffmpeg", "-y", "-i", res['audio_path'],
|
| 45 |
"-codec:a", "libmp3lame", "-qscale:a", "2", final_mp3
|
| 46 |
], check=True)
|
| 47 |
|
| 48 |
+
return final_mp3, transcript, translated
|
|
|
|
| 49 |
except Exception as e:
|
| 50 |
+
logger.error(f"Pipeline crashed: {e}")
|
| 51 |
+
return None, f"Error: {e}", ""
|
| 52 |
+
|
| 53 |
+
with gr.Blocks(title="ClearWave AI Studio") as demo:
|
| 54 |
+
gr.Markdown("# 🎙️ ClearWave AI Studio")
|
| 55 |
+
gr.Markdown("Transform WhatsApp audio into studio-quality MP3s.")
|
| 56 |
+
|
| 57 |
+
with gr.Row():
|
| 58 |
+
with gr.Column():
|
| 59 |
+
# Gradio 6.0: type="filepath" is essential for FFmpeg to find the file
|
| 60 |
+
audio_in = gr.Audio(label="Upload Audio", type="filepath")
|
| 61 |
+
with gr.Row():
|
| 62 |
+
f = gr.Checkbox(label="Fillers", value=True)
|
| 63 |
+
s = gr.Checkbox(label="Stutters", value=True)
|
| 64 |
+
z = gr.Checkbox(label="Silences", value=True)
|
| 65 |
+
lang = gr.Dropdown(choices=["Hindi", "Telugu", "Spanish"], value="Hindi", label="Translation")
|
| 66 |
+
btn = gr.Button("✨ Process to Studio MP3", variant="primary")
|
| 67 |
+
|
| 68 |
+
with gr.Column():
|
| 69 |
+
audio_out = gr.Audio(label="Cleaned MP3 Result")
|
| 70 |
+
# Removed show_copy_button to fix Gradio 6.0 error
|
| 71 |
+
t_out = gr.Textbox(label="Transcript", lines=5)
|
| 72 |
+
tr_out = gr.Textbox(label="Translation", lines=5)
|
| 73 |
+
|
| 74 |
+
btn.click(run_pipeline, [audio_in, f, s, z, f, f, lang], [audio_out, t_out, tr_out])
|
| 75 |
+
|
| 76 |
+
demo.launch()
|