Update app.py
Browse files
app.py
CHANGED
|
@@ -1,14 +1,33 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
-
import tempfile
|
| 3 |
import os
|
|
|
|
|
|
|
| 4 |
from nemo.collections.asr.models import ASRModel
|
| 5 |
|
| 6 |
-
# Define the model name (using the original author's repo or your fork)
|
| 7 |
MODEL_NAME = "trysem/stt_ml_fastconformer_ctc_med_punct"
|
| 8 |
|
| 9 |
-
print(
|
| 10 |
-
#
|
| 11 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 12 |
model.eval()
|
| 13 |
print("Model loaded successfully!")
|
| 14 |
|
|
@@ -16,12 +35,9 @@ def transcribe(audio_path):
|
|
| 16 |
if not audio_path:
|
| 17 |
return "Please upload or record audio."
|
| 18 |
|
| 19 |
-
# NeMo expects a list of paths for transcription
|
| 20 |
try:
|
| 21 |
-
# Transcribe returns a tuple, we want the first element (the text)
|
| 22 |
transcription = model.transcribe(paths2audio_files=[audio_path])[0]
|
| 23 |
|
| 24 |
-
# If it's a batch of 1, extract the single string
|
| 25 |
if isinstance(transcription, list):
|
| 26 |
return transcription[0]
|
| 27 |
return transcription
|
|
@@ -49,5 +65,4 @@ with gr.Blocks(title="Malayalam FastConformer ASR") as demo:
|
|
| 49 |
)
|
| 50 |
|
| 51 |
if __name__ == "__main__":
|
| 52 |
-
# 0.0.0.0 is required for Docker containers to expose the port correctly
|
| 53 |
demo.launch(server_name="0.0.0.0", server_port=7860)
|
|
|
|
| 1 |
import gradio as gr
|
|
|
|
| 2 |
import os
|
| 3 |
+
from huggingface_hub import snapshot_download
|
| 4 |
+
from omegaconf import OmegaConf
|
| 5 |
from nemo.collections.asr.models import ASRModel
|
| 6 |
|
|
|
|
| 7 |
MODEL_NAME = "trysem/stt_ml_fastconformer_ctc_med_punct"
|
| 8 |
|
| 9 |
+
print("1. Downloading unzipped model files from Hugging Face...")
|
| 10 |
+
# snapshot_download pulls the raw files (model_config.yaml, model_weights.ckpt) into the cache
|
| 11 |
+
model_dir = snapshot_download(repo_id=MODEL_NAME)
|
| 12 |
+
|
| 13 |
+
print("2. Patching the configuration in memory...")
|
| 14 |
+
config_path = os.path.join(model_dir, "model_config.yaml")
|
| 15 |
+
config = OmegaConf.load(config_path)
|
| 16 |
+
|
| 17 |
+
# Allow structural modifications to the config object
|
| 18 |
+
OmegaConf.set_struct(config, False)
|
| 19 |
+
|
| 20 |
+
# Remove the 'future' PyTorch SDPA keys that NeMo 1.23.0 doesn't recognize
|
| 21 |
+
if 'encoder' in config:
|
| 22 |
+
config.encoder.pop('use_pytorch_sdpa', None)
|
| 23 |
+
config.encoder.pop('use_pytorch_sdpa_backends', None)
|
| 24 |
+
|
| 25 |
+
print("3. Restoring model with patched config (this may take a moment)...")
|
| 26 |
+
# Inject our patched config directly into the restore_from method!
|
| 27 |
+
model = ASRModel.restore_from(
|
| 28 |
+
restore_path=model_dir,
|
| 29 |
+
override_config_path=config
|
| 30 |
+
)
|
| 31 |
model.eval()
|
| 32 |
print("Model loaded successfully!")
|
| 33 |
|
|
|
|
| 35 |
if not audio_path:
|
| 36 |
return "Please upload or record audio."
|
| 37 |
|
|
|
|
| 38 |
try:
|
|
|
|
| 39 |
transcription = model.transcribe(paths2audio_files=[audio_path])[0]
|
| 40 |
|
|
|
|
| 41 |
if isinstance(transcription, list):
|
| 42 |
return transcription[0]
|
| 43 |
return transcription
|
|
|
|
| 65 |
)
|
| 66 |
|
| 67 |
if __name__ == "__main__":
|
|
|
|
| 68 |
demo.launch(server_name="0.0.0.0", server_port=7860)
|