Spaces:
Runtime error
Runtime error
Update app.py
Browse files
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 |
-
#
|
| 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 |
-
#
|
| 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(
|
|
|
|
|
|
|
|
|
|
| 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()
|