testingfaces commited on
Commit
b14d6e4
Β·
verified Β·
1 Parent(s): 9c71dbc

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +137 -8
app.py CHANGED
@@ -15,13 +15,10 @@ import numpy as np
15
 
16
  print("ClearWave AI starting...")
17
 
18
- # ── Services ────────────────────────────────────────────────────────
19
- from services.denoiser import Denoiser
20
- from services.transcriber import Transcriber
21
- # βœ… FIX: Now using the full Translator class (NLLB-1.3B + Google fallback)
22
- # Previously app.py had its own inline translate() that only used
23
- # Google Translate and completely ignored translator.py
24
- from services.translator import Translator
25
 
26
  _denoiser = Denoiser()
27
  _transcriber = Transcriber()
@@ -133,4 +130,136 @@ with gr.Blocks(title="ClearWave AI", theme=gr.themes.Soft()) as demo:
133
  )
134
 
135
  print("ClearWave AI ready!")
136
- demo.launch()
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
15
 
16
  print("ClearWave AI starting...")
17
 
18
+ # ── Services (flat structure - all files in root) ────────────────────
19
+ from denoiser import Denoiser
20
+ from transcriber import Transcriber
21
+ from translator import Translator
 
 
 
22
 
23
  _denoiser = Denoiser()
24
  _transcriber = Transcriber()
 
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**")
224
+
225
+ with gr.Row():
226
+ with gr.Column(scale=1):
227
+ audio_in = gr.Audio(
228
+ label="Upload Audio",
229
+ type="filepath",
230
+ sources=["upload", "microphone"],
231
+ )
232
+ in_lang = gr.Dropdown(INPUT_LANGS, value="Auto Detect", label="Input Language")
233
+ out_lang = gr.Dropdown(OUTPUT_LANGS, value="Telugu", label="Output Language")
234
+ run_btn = gr.Button("Process Audio", variant="primary", size="lg")
235
+ status = gr.Markdown("Upload audio and click Process.")
236
+
237
+ with gr.Column(scale=2):
238
+ with gr.Tabs():
239
+ with gr.Tab("Text"):
240
+ with gr.Row():
241
+ with gr.Column():
242
+ gr.Markdown("#### Transcript")
243
+ transcript_out = gr.Markdown("...")
244
+ with gr.Column():
245
+ gr.Markdown("#### Translation")
246
+ translation_out = gr.Markdown("...")
247
+ with gr.Tab("Clean Audio"):
248
+ audio_out = gr.Audio(
249
+ label="Denoised",
250
+ type="filepath",
251
+ interactive=False,
252
+ )
253
+ with gr.Tab("Timings"):
254
+ timing_out = gr.Markdown("...")
255
+
256
+ run_btn.click(
257
+ fn=process,
258
+ inputs=[audio_in, in_lang, out_lang],
259
+ outputs=[audio_out, transcript_out, translation_out, timing_out, status],
260
+ show_progress=True,
261
+ api_name=False,
262
+ )
263
+
264
+ print("ClearWave AI ready!")
265
+ demo.launch()