Delik commited on
Commit
fc03567
1 Parent(s): 76a53fa

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +15 -4
app.py CHANGED
@@ -3,11 +3,19 @@ import os
3
  from pyannote.audio import Pipeline
4
 
5
  # instantiate the pipeline
6
- pipeline = Pipeline.from_pretrained(
7
- "pyannote/speaker-diarization-3.1",
8
- use_auth_token=os.environ["api"])
 
 
 
 
 
9
 
10
  def process_audio(audio):
 
 
 
11
  # Read the uploaded audio file
12
  with open(audio, "rb") as f:
13
  audio_data = f.read()
@@ -17,7 +25,10 @@ def process_audio(audio):
17
  f.write(audio_data)
18
 
19
  # Use the diarization pipeline to process the audio
20
- diarization = pipeline("temp.wav")
 
 
 
21
 
22
  # Remove the temporary file
23
  os.remove("temp.wav")
 
3
  from pyannote.audio import Pipeline
4
 
5
  # instantiate the pipeline
6
+ try:
7
+ pipeline = Pipeline.from_pretrained(
8
+ "pyannote/speaker-diarization-3.1",
9
+ use_auth_token=os.environ["api"]
10
+ )
11
+ except Exception as e:
12
+ print(f"Error initializing pipeline: {e}")
13
+ pipeline = None
14
 
15
  def process_audio(audio):
16
+ if pipeline is None:
17
+ return "Error: Pipeline not initialized"
18
+
19
  # Read the uploaded audio file
20
  with open(audio, "rb") as f:
21
  audio_data = f.read()
 
25
  f.write(audio_data)
26
 
27
  # Use the diarization pipeline to process the audio
28
+ try:
29
+ diarization = pipeline("temp.wav")
30
+ except Exception as e:
31
+ return f"Error processing audio: {e}"
32
 
33
  # Remove the temporary file
34
  os.remove("temp.wav")