testingfaces commited on
Commit
04aecbe
Β·
verified Β·
1 Parent(s): 01fc94b

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +22 -69
app.py CHANGED
@@ -1,102 +1,55 @@
1
  import gradio as gr
2
  import os
3
  import subprocess
4
- import logging
5
  from datetime import datetime
6
-
7
- # Import Departments
8
  from denoiser import Denoiser
9
  from transcriber import Transcriber
10
  from translator import Translator
11
 
12
- logging.basicConfig(level=logging.INFO)
13
- logger = logging.getLogger(__name__)
14
-
15
- # Initialize
16
  denoiser = Denoiser()
17
  transcriber = Transcriber()
18
  translator = Translator()
19
 
20
  def run_pipeline(audio_input, remove_fillers, remove_stutters, remove_silences, remove_breaths, remove_mouth, target_lang):
21
- if not audio_input:
22
- return None, "No audio detected. Please upload a file.", ""
23
-
24
- # Create job directory
25
- job_id = datetime.now().strftime("%Y%m%d_%H%M%S")
26
- output_dir = f"outputs/{job_id}"
27
- os.makedirs(output_dir, exist_ok=True)
28
 
29
  try:
30
- # 1. DENOISE & CLEAN (Handles WhatsApp/Any format)
31
- logger.info("[Pipeline] Step 1: Denoising & Studio Processing...")
32
- res = denoiser.process(
33
- audio_input, output_dir,
34
- fillers=remove_fillers, stutters=remove_stutters,
35
- long_silences=remove_silences, breath=remove_breaths,
36
- mouth_sounds=remove_mouth
37
- )
38
 
39
- # 2. TRANSCRIBE (Using the clean internal WAV)
40
- logger.info("[Pipeline] Step 2: Transcribing...")
41
- transcript_data = transcriber.transcribe(res['audio_path'])
42
- text = transcript_data['text']
43
-
44
- # Clean text fillers locally if requested
45
  if remove_fillers:
46
  text = denoiser.clean_transcript_fillers(text)
47
-
48
- # 3. TRANSLATE
49
- logger.info(f"[Pipeline] Step 3: Translating to {target_lang}...")
50
  translated = translator.translate(text, target_lang)
51
 
52
- # 4. FINAL EXPORT: Conversion to MP3
53
- final_mp3 = os.path.join(output_dir, "ClearWave_Studio_Final.mp3")
54
  subprocess.run([
55
  "ffmpeg", "-y", "-i", res['audio_path'],
56
  "-codec:a", "libmp3lame", "-qscale:a", "2", final_mp3
57
  ], check=True)
58
 
59
  return final_mp3, text, translated
60
-
61
  except Exception as e:
62
- logger.error(f"Pipeline Error: {e}")
63
- return None, f"Error: {str(e)}", ""
64
 
65
- # ══════════════════════════════════════════════════════════════════
66
- # GRADIO UI (Gradio 6.0)
67
- # ══════════════════════════════════════════════════════════════════
68
- with gr.Blocks(title="ClearWave AI Studio") as demo:
69
- gr.Markdown("# πŸŽ™οΈ ClearWave AI: WhatsApp to Studio MP3")
70
- gr.Markdown("Upload any audio (WhatsApp Voice Notes, M4A, WAV) and get a professional MP3.")
71
-
72
  with gr.Row():
73
  with gr.Column():
74
- audio_in = gr.Audio(label="Input Audio File", type="filepath")
75
- with gr.Group():
76
- gr.Markdown("### Processing Filters")
77
- f = gr.Checkbox(label="Remove Fillers", value=True)
78
- s = gr.Checkbox(label="Remove Stutters", value=True)
79
- z = gr.Checkbox(label="Remove Long Silences", value=True)
80
- b = gr.Checkbox(label="Remove Breaths", value=True)
81
- m = gr.Checkbox(label="Remove Mouth Noises", value=True)
82
-
83
- lang = gr.Dropdown(
84
- choices=["Hindi", "Telugu", "Spanish", "French", "German"],
85
- value="Hindi",
86
- label="Translation Language"
87
- )
88
- btn = gr.Button("✨ Generate Studio MP3", variant="primary")
89
-
90
  with gr.Column():
91
- audio_out = gr.Audio(label="Final Clean MP3", type="filepath")
92
- t_out = gr.Textbox(label="Transcript", lines=8)
93
- tr_out = gr.Textbox(label="Translation", lines=8)
94
 
95
- btn.click(
96
- fn=run_pipeline,
97
- inputs=[audio_in, f, s, z, b, m, lang],
98
- outputs=[audio_out, t_out, tr_out]
99
- )
100
 
101
- if __name__ == "__main__":
102
- demo.launch(theme=gr.themes.Soft())
 
1
  import gradio as gr
2
  import os
3
  import subprocess
 
4
  from datetime import datetime
 
 
5
  from denoiser import Denoiser
6
  from transcriber import Transcriber
7
  from translator import Translator
8
 
 
 
 
 
9
  denoiser = Denoiser()
10
  transcriber = Transcriber()
11
  translator = Translator()
12
 
13
  def run_pipeline(audio_input, remove_fillers, remove_stutters, remove_silences, remove_breaths, remove_mouth, target_lang):
14
+ if not audio_input: return None, "No audio detected.", ""
15
+
16
+ out_dir = f"outputs/{datetime.now().strftime('%H%M%S')}"
17
+ os.makedirs(out_dir, exist_ok=True)
 
 
 
18
 
19
  try:
20
+ # 1. Clean (Supports WhatsApp/Any via Denoiser pre-process)
21
+ res = denoiser.process(audio_input, out_dir, fillers=remove_fillers, stutters=remove_stutters)
 
 
 
 
 
 
22
 
23
+ # 2. Transcribe & Translate
24
+ text = transcriber.transcribe(res['audio_path'])['text']
 
 
 
 
25
  if remove_fillers:
26
  text = denoiser.clean_transcript_fillers(text)
 
 
 
27
  translated = translator.translate(text, target_lang)
28
 
29
+ # 3. Final MP3 Export
30
+ final_mp3 = os.path.join(out_dir, "ClearWave_Result.mp3")
31
  subprocess.run([
32
  "ffmpeg", "-y", "-i", res['audio_path'],
33
  "-codec:a", "libmp3lame", "-qscale:a", "2", final_mp3
34
  ], check=True)
35
 
36
  return final_mp3, text, translated
 
37
  except Exception as e:
38
+ return None, f"Error: {e}", ""
 
39
 
40
+ with gr.Blocks() as demo:
41
+ gr.Markdown("# πŸŽ™οΈ ClearWave: Any Format βž” Studio MP3")
 
 
 
 
 
42
  with gr.Row():
43
  with gr.Column():
44
+ audio_in = gr.Audio(label="Input (WhatsApp/WAV/AAC)", type="filepath")
45
+ f = gr.Checkbox(label="Remove Fillers", value=True)
46
+ lang = gr.Dropdown(choices=["Hindi", "Telugu", "Spanish"], value="Telugu", label="Translate to")
47
+ btn = gr.Button("Generate Professional MP3", variant="primary")
 
 
 
 
 
 
 
 
 
 
 
 
48
  with gr.Column():
49
+ audio_out = gr.Audio(label="Studio MP3 Output")
50
+ t_out = gr.Textbox(label="Transcript")
51
+ tr_out = gr.Textbox(label="Translation")
52
 
53
+ btn.click(run_pipeline, [audio_in, f, f, f, f, f, lang], [audio_out, t_out, tr_out])
 
 
 
 
54
 
55
+ demo.launch(theme=gr.themes.Soft())