Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,11 +1,11 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
-
from transformers import AutoModelForCTC, AutoFeatureExtractor
|
| 3 |
import torch
|
| 4 |
import librosa
|
| 5 |
import re
|
| 6 |
|
| 7 |
print("Loading MedASR model...")
|
| 8 |
-
|
|
|
|
| 9 |
model = AutoModelForCTC.from_pretrained("google/medasr", trust_remote_code=True)
|
| 10 |
print("MedASR loaded!")
|
| 11 |
|
|
@@ -20,11 +20,11 @@ def transcribe(audio_path):
|
|
| 20 |
return "No audio provided"
|
| 21 |
try:
|
| 22 |
speech, sr = librosa.load(audio_path, sr=16000)
|
| 23 |
-
inputs =
|
| 24 |
with torch.no_grad():
|
| 25 |
logits = model(**inputs).logits
|
| 26 |
ids = torch.argmax(logits, dim=-1)
|
| 27 |
-
raw =
|
| 28 |
return clean_transcription(raw)
|
| 29 |
except Exception as e:
|
| 30 |
return f"Error: {str(e)}"
|
|
|
|
| 1 |
import gradio as gr
|
|
|
|
| 2 |
import torch
|
| 3 |
import librosa
|
| 4 |
import re
|
| 5 |
|
| 6 |
print("Loading MedASR model...")
|
| 7 |
+
from transformers import AutoModelForCTC, AutoProcessor
|
| 8 |
+
processor = AutoProcessor.from_pretrained("google/medasr", trust_remote_code=True)
|
| 9 |
model = AutoModelForCTC.from_pretrained("google/medasr", trust_remote_code=True)
|
| 10 |
print("MedASR loaded!")
|
| 11 |
|
|
|
|
| 20 |
return "No audio provided"
|
| 21 |
try:
|
| 22 |
speech, sr = librosa.load(audio_path, sr=16000)
|
| 23 |
+
inputs = processor(speech, sampling_rate=16000, return_tensors="pt", padding=True)
|
| 24 |
with torch.no_grad():
|
| 25 |
logits = model(**inputs).logits
|
| 26 |
ids = torch.argmax(logits, dim=-1)
|
| 27 |
+
raw = processor.batch_decode(ids)[0]
|
| 28 |
return clean_transcription(raw)
|
| 29 |
except Exception as e:
|
| 30 |
return f"Error: {str(e)}"
|