harphool17 commited on
Commit
4648c99
Β·
verified Β·
1 Parent(s): f14f2c6

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +15 -14
app.py CHANGED
@@ -4,25 +4,26 @@ import time
4
  from huggingface_hub import hf_hub_download
5
 
6
  # ─────────────────────────────────────────────
7
- # MODEL LOADING (Runs once when server starts)
8
  # ─────────────────────────────────────────────
9
  print("Downloading your Full Custom Model from the Hub...")
10
- # Because you saved the full model, we just download your 2.5GB file!
11
  custom_model_path = hf_hub_download(repo_id="harphool17/parakeet-asr-adapter", filename="ASR-Adapter.nemo")
12
 
13
  print("Booting up the model engine...")
14
- # The 'restore_from' command automatically unpacks the .nemo file and loads everything inside.
15
  model = nemo_asr.models.EncDecRNNTBPEModel.restore_from(custom_model_path)
16
  model.eval()
17
 
18
  print("βœ… Custom Parakeet Engine Online! Server Ready.")
19
 
20
-
21
-
22
  # ─────────────────────────────────────────────
23
- # INFERENCE FUNCTION
24
  # ─────────────────────────────────────────────
25
- def transcribe_audio(audio_filepath):
 
 
 
26
  if audio_filepath is None:
27
  return "Please upload or record an audio file.", "0.00s"
28
 
@@ -47,7 +48,7 @@ def transcribe_audio(audio_filepath):
47
  return f"An error occurred: {str(e)}", "Error"
48
 
49
  # ─────────────────────────────────────────────
50
- # THE "PRO" DASHBOARD UI
51
  # ─────────────────────────────────────────────
52
  theme = gr.themes.Soft(
53
  primary_hue="indigo",
@@ -91,6 +92,7 @@ with gr.Blocks(theme=theme, title="Parakeet ASR") as demo:
91
  lines=8,
92
  placeholder="Your transcription will appear here..."
93
  )
 
94
  with gr.Row():
95
  metrics = gr.Textbox(label="Processing Time", value="0.00s", interactive=False)
96
 
@@ -103,16 +105,15 @@ with gr.Blocks(theme=theme, title="Parakeet ASR") as demo:
103
  )
104
 
105
  # ── EVENT WIRING ──
 
106
  submit_btn.click(
107
  fn=transcribe_audio,
108
- inputs=audio_upload,
109
- outputs=[output_text, metrics]
110
- )
111
- submit_btn.click(
112
- fn=transcribe_audio,
113
- inputs=audio_mic,
114
  outputs=[output_text, metrics]
115
  )
116
 
 
 
 
117
  if __name__ == "__main__":
118
  demo.launch()
 
4
  from huggingface_hub import hf_hub_download
5
 
6
  # ─────────────────────────────────────────────
7
+ # 1. MODEL LOADING (Runs once when server starts)
8
  # ─────────────────────────────────────────────
9
  print("Downloading your Full Custom Model from the Hub...")
10
+ # This safely pulls your 2.5GB model from your unlimited Model repository!
11
  custom_model_path = hf_hub_download(repo_id="harphool17/parakeet-asr-adapter", filename="ASR-Adapter.nemo")
12
 
13
  print("Booting up the model engine...")
14
+ # Unpacks the .nemo file and loads everything inside
15
  model = nemo_asr.models.EncDecRNNTBPEModel.restore_from(custom_model_path)
16
  model.eval()
17
 
18
  print("βœ… Custom Parakeet Engine Online! Server Ready.")
19
 
 
 
20
  # ─────────────────────────────────────────────
21
+ # 2. INFERENCE FUNCTION
22
  # ─────────────────────────────────────────────
23
+ def transcribe_audio(file_upload, mic_upload):
24
+ # Smartly pick whichever tab actually has audio in it
25
+ audio_filepath = file_upload if file_upload is not None else mic_upload
26
+
27
  if audio_filepath is None:
28
  return "Please upload or record an audio file.", "0.00s"
29
 
 
48
  return f"An error occurred: {str(e)}", "Error"
49
 
50
  # ─────────────────────────────────────────────
51
+ # 3. THE "PRO" DASHBOARD UI
52
  # ─────────────────────────────────────────────
53
  theme = gr.themes.Soft(
54
  primary_hue="indigo",
 
92
  lines=8,
93
  placeholder="Your transcription will appear here..."
94
  )
95
+
96
  with gr.Row():
97
  metrics = gr.Textbox(label="Processing Time", value="0.00s", interactive=False)
98
 
 
105
  )
106
 
107
  # ── EVENT WIRING ──
108
+ # Single click event that checks both inputs simultaneously to stop the ghost-click bug!
109
  submit_btn.click(
110
  fn=transcribe_audio,
111
+ inputs=[audio_upload, audio_mic],
 
 
 
 
 
112
  outputs=[output_text, metrics]
113
  )
114
 
115
+ # ─────────────────────────────────────────────
116
+ # 4. LAUNCH
117
+ # ─────────────────────────────────────────────
118
  if __name__ == "__main__":
119
  demo.launch()