Update app.py
Browse files
app.py
CHANGED
|
@@ -1,8 +1,6 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
from transformers import pipeline
|
| 3 |
from rapidfuzz import process, fuzz
|
| 4 |
-
import soundfile as sf
|
| 5 |
-
import numpy as np
|
| 6 |
|
| 7 |
# Initialize ASR pipeline
|
| 8 |
asr = pipeline(
|
|
@@ -22,7 +20,6 @@ custom_vocab_map = {
|
|
| 22 |
def replace_fuzzy(text, vocab_map, threshold=85):
|
| 23 |
"""
|
| 24 |
Replace words/phrases in text using fuzzy matching with high threshold.
|
| 25 |
-
Supports multiple alternatives per word/phrase.
|
| 26 |
"""
|
| 27 |
for target, alternatives in vocab_map.items():
|
| 28 |
result = process.extractOne(text, alternatives, scorer=fuzz.partial_ratio)
|
|
@@ -39,12 +36,13 @@ def replace_fuzzy(text, vocab_map, threshold=85):
|
|
| 39 |
|
| 40 |
def transcribe(audio_file):
|
| 41 |
"""
|
| 42 |
-
|
| 43 |
"""
|
| 44 |
-
if
|
| 45 |
return "No audio input detected."
|
| 46 |
|
| 47 |
try:
|
|
|
|
| 48 |
result = asr(audio_file, chunk_length_s=30, stride_length_s=[5,5])
|
| 49 |
except Exception as e:
|
| 50 |
return f"ASR error: {e}"
|
|
@@ -59,8 +57,8 @@ iface = gr.Interface(
|
|
| 59 |
inputs=gr.Audio(type="filepath", label="Record or upload audio"),
|
| 60 |
outputs="text",
|
| 61 |
title="Persian ASR with High Accuracy Vocabulary",
|
| 62 |
-
description="""Speak in Persian or upload an audio file;
|
| 63 |
-
|
| 64 |
)
|
| 65 |
|
| 66 |
if __name__ == "__main__":
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
from transformers import pipeline
|
| 3 |
from rapidfuzz import process, fuzz
|
|
|
|
|
|
|
| 4 |
|
| 5 |
# Initialize ASR pipeline
|
| 6 |
asr = pipeline(
|
|
|
|
| 20 |
def replace_fuzzy(text, vocab_map, threshold=85):
|
| 21 |
"""
|
| 22 |
Replace words/phrases in text using fuzzy matching with high threshold.
|
|
|
|
| 23 |
"""
|
| 24 |
for target, alternatives in vocab_map.items():
|
| 25 |
result = process.extractOne(text, alternatives, scorer=fuzz.partial_ratio)
|
|
|
|
| 36 |
|
| 37 |
def transcribe(audio_file):
|
| 38 |
"""
|
| 39 |
+
audio_file: path to WAV file (Gradio mic or upload)
|
| 40 |
"""
|
| 41 |
+
if not audio_file:
|
| 42 |
return "No audio input detected."
|
| 43 |
|
| 44 |
try:
|
| 45 |
+
# Run ASR
|
| 46 |
result = asr(audio_file, chunk_length_s=30, stride_length_s=[5,5])
|
| 47 |
except Exception as e:
|
| 48 |
return f"ASR error: {e}"
|
|
|
|
| 57 |
inputs=gr.Audio(type="filepath", label="Record or upload audio"),
|
| 58 |
outputs="text",
|
| 59 |
title="Persian ASR with High Accuracy Vocabulary",
|
| 60 |
+
description="""Speak in Persian or upload an audio file; recognized words
|
| 61 |
+
are corrected using a custom high-accuracy vocabulary."""
|
| 62 |
)
|
| 63 |
|
| 64 |
if __name__ == "__main__":
|