Update app.py
Browse files
app.py
CHANGED
|
@@ -8,26 +8,26 @@ ASR_MODEL_ID = "facebook/seamless-m4t-v2-large"
|
|
| 8 |
HF_TOKEN = os.getenv("HF_TOKEN")
|
| 9 |
DEVICE = "cuda" if torch.cuda.is_available() else "cpu"
|
| 10 |
|
| 11 |
-
print("🔹 Loading processor...")
|
| 12 |
processor = AutoProcessor.from_pretrained(
|
| 13 |
ASR_MODEL_ID,
|
| 14 |
token=HF_TOKEN
|
| 15 |
)
|
| 16 |
|
| 17 |
-
print("🔹 Loading ASR model...")
|
| 18 |
asr_model = SeamlessM4Tv2ForSpeechToText.from_pretrained(
|
| 19 |
ASR_MODEL_ID,
|
| 20 |
token=HF_TOKEN
|
| 21 |
).to(DEVICE)
|
| 22 |
|
| 23 |
asr_model.eval()
|
| 24 |
-
print("✅ ASR model loaded")
|
| 25 |
|
| 26 |
-
def transcribe_audio(
|
| 27 |
-
if
|
| 28 |
return "No audio provided."
|
| 29 |
|
| 30 |
-
speech, sr =
|
|
|
|
|
|
|
|
|
|
| 31 |
|
| 32 |
inputs = processor(
|
| 33 |
audios=speech,
|
|
@@ -56,10 +56,9 @@ def transcribe_audio(audio_path):
|
|
| 56 |
|
| 57 |
demo = gr.Interface(
|
| 58 |
fn=transcribe_audio,
|
| 59 |
-
inputs=gr.Audio(type="
|
| 60 |
outputs=gr.Textbox(label="Transcription"),
|
| 61 |
title="HealthAtlas ASR Service",
|
| 62 |
-
description="Speech → Text (SeamlessM4T v2)"
|
| 63 |
)
|
| 64 |
|
| 65 |
if __name__ == "__main__":
|
|
|
|
| 8 |
HF_TOKEN = os.getenv("HF_TOKEN")
|
| 9 |
DEVICE = "cuda" if torch.cuda.is_available() else "cpu"
|
| 10 |
|
|
|
|
| 11 |
processor = AutoProcessor.from_pretrained(
|
| 12 |
ASR_MODEL_ID,
|
| 13 |
token=HF_TOKEN
|
| 14 |
)
|
| 15 |
|
|
|
|
| 16 |
asr_model = SeamlessM4Tv2ForSpeechToText.from_pretrained(
|
| 17 |
ASR_MODEL_ID,
|
| 18 |
token=HF_TOKEN
|
| 19 |
).to(DEVICE)
|
| 20 |
|
| 21 |
asr_model.eval()
|
|
|
|
| 22 |
|
| 23 |
+
def transcribe_audio(audio):
|
| 24 |
+
if audio is None:
|
| 25 |
return "No audio provided."
|
| 26 |
|
| 27 |
+
speech, sr = audio
|
| 28 |
+
|
| 29 |
+
if sr != 16000:
|
| 30 |
+
speech = librosa.resample(speech, sr, 16000)
|
| 31 |
|
| 32 |
inputs = processor(
|
| 33 |
audios=speech,
|
|
|
|
| 56 |
|
| 57 |
demo = gr.Interface(
|
| 58 |
fn=transcribe_audio,
|
| 59 |
+
inputs=gr.Audio(type="numpy", label="Upload Speech"),
|
| 60 |
outputs=gr.Textbox(label="Transcription"),
|
| 61 |
title="HealthAtlas ASR Service",
|
|
|
|
| 62 |
)
|
| 63 |
|
| 64 |
if __name__ == "__main__":
|