Spaces:
Build error
Build error
update load model function
Browse files
app.py
CHANGED
@@ -34,23 +34,25 @@ def load_models(hf_token):
|
|
34 |
"""Load all required models"""
|
35 |
global whisper_model, diarization_pipeline, med_ner
|
36 |
|
37 |
-
|
38 |
-
|
39 |
-
|
40 |
-
|
41 |
-
|
42 |
-
|
43 |
-
diarization_pipeline
|
44 |
-
|
45 |
-
|
46 |
-
|
47 |
-
|
48 |
-
|
49 |
-
|
50 |
-
med_ner
|
51 |
-
|
52 |
-
|
53 |
-
|
|
|
|
|
54 |
def convert_audio_to_wav(input_file):
|
55 |
"""Convert any audio file to 16kHz WAV format"""
|
56 |
audio = AudioSegment.from_file(input_file)
|
|
|
34 |
"""Load all required models"""
|
35 |
global whisper_model, diarization_pipeline, med_ner
|
36 |
|
37 |
+
try:
|
38 |
+
# Load Whisper
|
39 |
+
if whisper_model is None:
|
40 |
+
whisper_model = whisper.load_model(WHISPER_MODEL_SIZE, device="cuda" if torch.cuda.is_available() else "cpu")
|
41 |
+
|
42 |
+
# Load Diarization
|
43 |
+
if diarization_pipeline is None:
|
44 |
+
diarization_pipeline = Pipeline.from_pretrained(
|
45 |
+
"pyannote/speaker-diarization-3.1",
|
46 |
+
use_auth_token=hf_token
|
47 |
+
)
|
48 |
+
|
49 |
+
# Load Medical NER
|
50 |
+
if med_ner is None:
|
51 |
+
med_ner = hf_pipeline("ner", model=MEDICAL_NER_MODEL, aggregation_strategy="simple")
|
52 |
+
|
53 |
+
return "Models loaded successfully", None # Return tuple matching expected outputs
|
54 |
+
except Exception as e:
|
55 |
+
return f"Error loading models: {str(e)}", None
|
56 |
def convert_audio_to_wav(input_file):
|
57 |
"""Convert any audio file to 16kHz WAV format"""
|
58 |
audio = AudioSegment.from_file(input_file)
|