voidash commited on
Commit
b8d8ebe
·
verified ·
1 Parent(s): 145c9e7

auto-transcribe on stop_recording: submitting mid-recording silently sent nothing

Browse files
Files changed (1) hide show
  1. app.py +50 -23
app.py CHANGED
@@ -15,6 +15,22 @@ MODEL = EncDecHybridRNNTCTCBPEModel.restore_from(_path, map_location="cpu")
15
  MODEL.eval()
16
  print("model preloaded", flush=True)
17
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
18
 
19
  def get_model():
20
  return MODEL
@@ -59,7 +75,9 @@ def _prepare(path):
59
 
60
  def transcribe(audio_path):
61
  if not audio_path:
62
- return "(no audio)"
 
 
63
  audio_path, duration = _prepare(audio_path)
64
  if duration is not None and duration > 60:
65
  return "Please keep clips under 60 seconds for this CPU demo."
@@ -69,28 +87,37 @@ def transcribe(audio_path):
69
  return " ".join(t for t in text.split() if t != "<breath>") or "(no speech detected)"
70
 
71
 
72
- examples = [[f"examples/{f}"] for f in sorted(os.listdir("examples"))] \
73
- if os.path.isdir("examples") else None
74
-
75
- demo = gr.Interface(
76
- fn=transcribe,
77
- inputs=gr.Audio(sources=["microphone", "upload"], type="filepath",
78
- label="Nepali speech (mic or file, ≤60 s)"),
79
- outputs=gr.Textbox(label="Transcript (Devanagari)", rtl=False),
80
- title="NepaliConformer — Nepali ASR for real telephone calls",
81
- description=(
82
- "121M Conformer trained on ~1,655 h of conversational Nepali. "
83
- "**33.8% WER on real call-center audio** (NepTel benchmark) where Whisper-large-v3 "
84
- "zero-shot scores ~99%. Honest limitations and the full benchmark: "
85
- "[github.com/Ampixa/nepaliconformer](https://github.com/Ampixa/nepaliconformer). "
86
- "CPU demo — a 30 s clip takes roughly 10-20 s. Example clips are real call-center "
87
- "audio (CC-BY-4.0, © InfoBayAI)."
88
- ),
89
- examples=examples,
90
- cache_examples=False,
91
- flagging_mode="never",
92
- article="Demo stuck or mic blocked? [Open the demo full-screen](https://voidash-nepaliconformer.hf.space) \u00b7 Model downloads and usage: [github.com/Ampixa/nepaliconformer](https://github.com/Ampixa/nepaliconformer#download--run)",
93
- )
 
 
 
 
 
 
 
 
 
94
 
95
  if __name__ == "__main__":
96
  demo.launch(ssr_mode=False, show_error=True)
 
15
  MODEL.eval()
16
  print("model preloaded", flush=True)
17
 
18
+ DESCRIPTION = (
19
+ "121M Conformer trained on ~1,655 h of conversational Nepali. "
20
+ "**33.8% WER on real call-center audio** (NepTel benchmark) where Whisper-large-v3 "
21
+ "zero-shot scores ~99%. Honest limitations and the full benchmark: "
22
+ "[github.com/Ampixa/nepaliconformer](https://github.com/Ampixa/nepaliconformer). "
23
+ "CPU demo — a 30 s clip takes roughly 10-20 s. Example clips are real call-center "
24
+ "audio (CC-BY-4.0, © InfoBayAI)."
25
+ )
26
+
27
+ ARTICLE = (
28
+ "Recording transcribes itself as soon as you press ⏹ stop. "
29
+ "Mic blocked? [Open the demo full-screen](https://voidash-nepaliconformer.hf.space) · "
30
+ "Model downloads and usage: "
31
+ "[github.com/Ampixa/nepaliconformer](https://github.com/Ampixa/nepaliconformer#download--run)"
32
+ )
33
+
34
 
35
  def get_model():
36
  return MODEL
 
75
 
76
  def transcribe(audio_path):
77
  if not audio_path:
78
+ # Most often: the user pressed Transcribe while the mic was still recording,
79
+ # so no file exists yet.
80
+ return "Press ⏹ stop to finish the recording — it transcribes automatically."
81
  audio_path, duration = _prepare(audio_path)
82
  if duration is not None and duration > 60:
83
  return "Please keep clips under 60 seconds for this CPU demo."
 
87
  return " ".join(t for t in text.split() if t != "<breath>") or "(no speech detected)"
88
 
89
 
90
+ example_files = [[f"examples/{f}"] for f in sorted(os.listdir("examples"))] \
91
+ if os.path.isdir("examples") else []
92
+
93
+ with gr.Blocks(title="NepaliConformer — Nepali ASR for real telephone calls") as demo:
94
+ gr.Markdown("# NepaliConformer — Nepali ASR for real telephone calls")
95
+ gr.Markdown(DESCRIPTION)
96
+ with gr.Row():
97
+ with gr.Column():
98
+ audio_in = gr.Audio(
99
+ sources=["microphone", "upload"], type="filepath",
100
+ label="Nepali speech (mic or file, ≤60 s)",
101
+ )
102
+ with gr.Row():
103
+ clear_btn = gr.Button("Clear")
104
+ submit_btn = gr.Button("Transcribe", variant="primary")
105
+ with gr.Column():
106
+ text_out = gr.Textbox(label="Transcript (Devanagari)", lines=6)
107
+
108
+ # Transcribe as soon as the recording stops or a file lands: waiting for an explicit
109
+ # Transcribe click made the demo look broken for anyone who never pressed stop.
110
+ audio_in.stop_recording(transcribe, audio_in, text_out)
111
+ audio_in.upload(transcribe, audio_in, text_out)
112
+ submit_btn.click(transcribe, audio_in, text_out)
113
+ clear_btn.click(lambda: (None, ""), None, [audio_in, text_out])
114
+
115
+ if example_files:
116
+ gr.Examples(
117
+ examples=example_files, inputs=audio_in, outputs=text_out,
118
+ fn=transcribe, cache_examples=False,
119
+ )
120
+ gr.Markdown(ARTICLE)
121
 
122
  if __name__ == "__main__":
123
  demo.launch(ssr_mode=False, show_error=True)