yunusajib commited on
Commit
2613dcb
·
verified ·
1 Parent(s): e14a085

update load model function

Browse files
Files changed (1) hide show
  1. app.py +19 -17
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
- # Load Whisper (Speech-to-Text)
38
- if whisper_model is None:
39
- whisper_model = whisper.load_model(WHISPER_MODEL_SIZE, device="cuda" if torch.cuda.is_available() else "cpu")
40
-
41
- # Load Diarization
42
- if diarization_pipeline is None:
43
- diarization_pipeline = Pipeline.from_pretrained(
44
- "pyannote/speaker-diarization",
45
- use_auth_token=hf_token
46
- )
47
-
48
- # Load Medical NER
49
- if med_ner is None:
50
- med_ner = hf_pipeline("ner", model=MEDICAL_NER_MODEL, aggregation_strategy="simple")
51
-
52
- return "Models loaded successfully"
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)