Update app.py
Browse files
app.py
CHANGED
@@ -1,5 +1,6 @@
|
|
1 |
import os
|
2 |
import tempfile
|
|
|
3 |
from subprocess import Popen, PIPE
|
4 |
import torch
|
5 |
import gradio as gr
|
@@ -58,17 +59,27 @@ def transcribe_audio(audio_path):
|
|
58 |
if not os.path.exists(audio_path):
|
59 |
raise FileNotFoundError(f"Audio file not found: {audio_path}")
|
60 |
|
61 |
-
# Read the audio file
|
62 |
-
|
63 |
-
|
64 |
-
|
65 |
-
|
66 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
67 |
result = whisper_pipeline(inputs, batch_size=BATCH_SIZE, return_timestamps=False)
|
68 |
return result["text"]
|
69 |
except Exception as e:
|
70 |
return f"Error during transcription: {e}"
|
71 |
|
|
|
72 |
# Classify the sentence to the correct SOAP section
|
73 |
def classify_sentence(sentence):
|
74 |
similarities = {section: util.pytorch_cos_sim(embedder.encode(sentence), soap_embeddings[section]) for section in soap_prompts.keys()}
|
|
|
1 |
import os
|
2 |
import tempfile
|
3 |
+
import numpy as np
|
4 |
from subprocess import Popen, PIPE
|
5 |
import torch
|
6 |
import gradio as gr
|
|
|
59 |
if not os.path.exists(audio_path):
|
60 |
raise FileNotFoundError(f"Audio file not found: {audio_path}")
|
61 |
|
62 |
+
# Read and process the audio file
|
63 |
+
audio_array = ffmpeg_read(audio_path, whisper_pipeline.feature_extractor.sampling_rate)
|
64 |
+
|
65 |
+
# Ensure audio data is a numpy array of type float32
|
66 |
+
if not isinstance(audio_array, np.ndarray):
|
67 |
+
raise TypeError("Audio data should be a numpy array.")
|
68 |
+
audio_array = audio_array.astype(np.float32)
|
69 |
+
|
70 |
+
# Create input dictionary for Whisper
|
71 |
+
inputs = {
|
72 |
+
"array": audio_array,
|
73 |
+
"sampling_rate": whisper_pipeline.feature_extractor.sampling_rate,
|
74 |
+
}
|
75 |
+
|
76 |
+
# Perform transcription
|
77 |
result = whisper_pipeline(inputs, batch_size=BATCH_SIZE, return_timestamps=False)
|
78 |
return result["text"]
|
79 |
except Exception as e:
|
80 |
return f"Error during transcription: {e}"
|
81 |
|
82 |
+
|
83 |
# Classify the sentence to the correct SOAP section
|
84 |
def classify_sentence(sentence):
|
85 |
similarities = {section: util.pytorch_cos_sim(embedder.encode(sentence), soap_embeddings[section]) for section in soap_prompts.keys()}
|