Spaces:
Paused
Paused
Update app.py
Browse files
app.py
CHANGED
|
@@ -86,138 +86,6 @@ def process(audio_path, in_lang_label, out_lang_label, progress=gr.Progress()):
|
|
| 86 |
return None, f"Error: {e}", "", traceback.format_exc(), "Failed"
|
| 87 |
|
| 88 |
|
| 89 |
-
# ── UI ───────────────────────────────────────────────────────────────
|
| 90 |
-
with gr.Blocks(title="ClearWave AI", theme=gr.themes.Soft()) as demo:
|
| 91 |
-
gr.Markdown("# 🎵 ClearWave AI\n**Denoise · Transcribe · Translate**")
|
| 92 |
-
|
| 93 |
-
with gr.Row():
|
| 94 |
-
with gr.Column(scale=1):
|
| 95 |
-
audio_in = gr.Audio(
|
| 96 |
-
label="Upload Audio",
|
| 97 |
-
type="filepath",
|
| 98 |
-
sources=["upload", "microphone"],
|
| 99 |
-
)
|
| 100 |
-
in_lang = gr.Dropdown(INPUT_LANGS, value="Auto Detect", label="Input Language")
|
| 101 |
-
out_lang = gr.Dropdown(OUTPUT_LANGS, value="Telugu", label="Output Language")
|
| 102 |
-
run_btn = gr.Button("Process Audio", variant="primary", size="lg")
|
| 103 |
-
status = gr.Markdown("Upload audio and click Process.")
|
| 104 |
-
|
| 105 |
-
with gr.Column(scale=2):
|
| 106 |
-
with gr.Tabs():
|
| 107 |
-
with gr.Tab("Text"):
|
| 108 |
-
with gr.Row():
|
| 109 |
-
with gr.Column():
|
| 110 |
-
gr.Markdown("#### Transcript")
|
| 111 |
-
transcript_out = gr.Markdown("...")
|
| 112 |
-
with gr.Column():
|
| 113 |
-
gr.Markdown("#### Translation")
|
| 114 |
-
translation_out = gr.Markdown("...")
|
| 115 |
-
with gr.Tab("Clean Audio"):
|
| 116 |
-
audio_out = gr.Audio(
|
| 117 |
-
label="Denoised",
|
| 118 |
-
type="filepath",
|
| 119 |
-
interactive=False,
|
| 120 |
-
)
|
| 121 |
-
with gr.Tab("Timings"):
|
| 122 |
-
timing_out = gr.Markdown("...")
|
| 123 |
-
|
| 124 |
-
run_btn.click(
|
| 125 |
-
fn=process,
|
| 126 |
-
inputs=[audio_in, in_lang, out_lang],
|
| 127 |
-
outputs=[audio_out, transcript_out, translation_out, timing_out, status],
|
| 128 |
-
show_progress=True,
|
| 129 |
-
api_name=False,
|
| 130 |
-
)
|
| 131 |
-
|
| 132 |
-
print("ClearWave AI ready!")
|
| 133 |
-
demo.launch()import sys
|
| 134 |
-
import types
|
| 135 |
-
_a = types.ModuleType('audioop')
|
| 136 |
-
_a.ratecv = lambda *a, **k: (b'', 0)
|
| 137 |
-
sys.modules['audioop'] = _a
|
| 138 |
-
sys.modules['pyaudioop'] = _a
|
| 139 |
-
|
| 140 |
-
import gradio as gr
|
| 141 |
-
import os
|
| 142 |
-
import time
|
| 143 |
-
import tempfile
|
| 144 |
-
import shutil
|
| 145 |
-
import subprocess
|
| 146 |
-
import numpy as np
|
| 147 |
-
|
| 148 |
-
print("ClearWave AI starting...")
|
| 149 |
-
|
| 150 |
-
# ── Services (flat structure - all files in root) ────────────────────
|
| 151 |
-
from denoiser import Denoiser
|
| 152 |
-
from transcriber import Transcriber
|
| 153 |
-
from translator import Translator
|
| 154 |
-
|
| 155 |
-
_denoiser = Denoiser()
|
| 156 |
-
_transcriber = Transcriber()
|
| 157 |
-
_translator = Translator()
|
| 158 |
-
|
| 159 |
-
# ── Config ───────────────────────────────────────────────────────────
|
| 160 |
-
INPUT_LANGS = ["Auto Detect", "English", "Telugu", "Hindi", "Tamil", "Kannada"]
|
| 161 |
-
OUTPUT_LANGS = ["Telugu", "Hindi", "Tamil", "English", "Kannada"]
|
| 162 |
-
LANG_CODES = {
|
| 163 |
-
"Auto Detect": "auto",
|
| 164 |
-
"English": "en",
|
| 165 |
-
"Telugu": "te",
|
| 166 |
-
"Hindi": "hi",
|
| 167 |
-
"Tamil": "ta",
|
| 168 |
-
"Kannada": "kn",
|
| 169 |
-
}
|
| 170 |
-
|
| 171 |
-
# ── Pipeline ─────────────────────────────────────────────────────────
|
| 172 |
-
def process(audio_path, in_lang_label, out_lang_label, progress=gr.Progress()):
|
| 173 |
-
if audio_path is None:
|
| 174 |
-
return None, "Please upload audio.", "", "", "No audio"
|
| 175 |
-
|
| 176 |
-
in_lang = LANG_CODES.get(in_lang_label, "auto")
|
| 177 |
-
out_lang = LANG_CODES.get(out_lang_label, "te")
|
| 178 |
-
tmp = tempfile.mkdtemp()
|
| 179 |
-
t_total = time.time()
|
| 180 |
-
|
| 181 |
-
try:
|
| 182 |
-
# Dept 1 — Denoise
|
| 183 |
-
progress(0.1, desc="Dept 1: Denoising...")
|
| 184 |
-
t0 = time.time()
|
| 185 |
-
clean = _denoiser.process(audio_path, tmp)
|
| 186 |
-
t1 = time.time() - t0
|
| 187 |
-
|
| 188 |
-
# Dept 2 — Transcribe
|
| 189 |
-
progress(0.4, desc="Dept 2: Transcribing...")
|
| 190 |
-
t0 = time.time()
|
| 191 |
-
transcript, detected, tx_m = _transcriber.transcribe(clean, in_lang)
|
| 192 |
-
t2 = time.time() - t0
|
| 193 |
-
|
| 194 |
-
# Dept 3 — Translate
|
| 195 |
-
progress(0.75, desc="Dept 3: Translating...")
|
| 196 |
-
src = detected if in_lang == "auto" else in_lang
|
| 197 |
-
t0 = time.time()
|
| 198 |
-
translated, tr_m = _translator.translate(transcript, src, out_lang)
|
| 199 |
-
t3 = time.time() - t0
|
| 200 |
-
|
| 201 |
-
total = time.time() - t_total
|
| 202 |
-
progress(1.0, desc=f"Done in {total:.1f}s!")
|
| 203 |
-
|
| 204 |
-
timing = (
|
| 205 |
-
f"| Step | Time | Method |\n|---|---|---|\n"
|
| 206 |
-
f"| Denoise | {t1:.1f}s | noisereduce |\n"
|
| 207 |
-
f"| Transcribe | {t2:.1f}s | {tx_m} |\n"
|
| 208 |
-
f"| Translate | {t3:.1f}s | {tr_m} |\n"
|
| 209 |
-
f"| **Total** | **{total:.1f}s** | |"
|
| 210 |
-
)
|
| 211 |
-
|
| 212 |
-
out_audio = os.path.join(tmp, "output.wav")
|
| 213 |
-
shutil.copy(clean, out_audio)
|
| 214 |
-
return out_audio, transcript, translated, timing, f"Done in {total:.1f}s"
|
| 215 |
-
|
| 216 |
-
except Exception as e:
|
| 217 |
-
import traceback
|
| 218 |
-
return None, f"Error: {e}", "", traceback.format_exc(), "Failed"
|
| 219 |
-
|
| 220 |
-
|
| 221 |
# ── UI ───────────────────────────────────────────────────────────────
|
| 222 |
with gr.Blocks(title="ClearWave AI", theme=gr.themes.Soft()) as demo:
|
| 223 |
gr.Markdown("# 🎵 ClearWave AI\n**Denoise · Transcribe · Translate**")
|
|
|
|
| 86 |
return None, f"Error: {e}", "", traceback.format_exc(), "Failed"
|
| 87 |
|
| 88 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 89 |
# ── UI ───────────────────────────────────────────────────────────────
|
| 90 |
with gr.Blocks(title="ClearWave AI", theme=gr.themes.Soft()) as demo:
|
| 91 |
gr.Markdown("# 🎵 ClearWave AI\n**Denoise · Transcribe · Translate**")
|