Kquan commited on
Commit
6af24e4
Β·
verified Β·
1 Parent(s): 2692919

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +4 -9
app.py CHANGED
@@ -8,17 +8,14 @@ pipeline = Pipeline.from_pretrained(
8
  "pyannote/speaker-diarization-community-1", token=os.getenv('HF_TOKEN')
9
  )
10
 
11
- def diarize(audio_file):
12
  """
13
  Perform speaker diarization on uploaded audio file.
14
  """
15
- # Save uploaded audio to temp file
16
- with tempfile.NamedTemporaryFile(delete=False, suffix=".wav") as tmp:
17
- tmp.write(audio_file.read())
18
- tmp_path = tmp.name
19
 
20
  # Run diarization
21
- diarization = pipeline(tmp_path)
22
 
23
  # Collect readable results
24
  results = []
@@ -27,8 +24,6 @@ def diarize(audio_file):
27
  f"{speaker}: {turn.start:.1f}s β†’ {turn.end:.1f}s"
28
  )
29
 
30
- # Clean up
31
- os.remove(tmp_path)
32
 
33
  return "\n".join(results)
34
 
@@ -36,7 +31,7 @@ def diarize(audio_file):
36
  # πŸŽ›οΈ Gradio interface
37
  demo = gr.Interface(
38
  fn=diarize,
39
- inputs=gr.Audio(type="file", label="Upload Audio (.wav)"),
40
  outputs=gr.Textbox(label="Speaker Segments"),
41
  title="πŸŽ™οΈ Speaker Diarization Demo",
42
  description="Upload an audio file and detect who speaks when using Pyannote Audio."
 
8
  "pyannote/speaker-diarization-community-1", token=os.getenv('HF_TOKEN')
9
  )
10
 
11
+ def diarize(audio_file_path):
12
  """
13
  Perform speaker diarization on uploaded audio file.
14
  """
15
+
 
 
 
16
 
17
  # Run diarization
18
+ diarization = pipeline(audio_file_path)
19
 
20
  # Collect readable results
21
  results = []
 
24
  f"{speaker}: {turn.start:.1f}s β†’ {turn.end:.1f}s"
25
  )
26
 
 
 
27
 
28
  return "\n".join(results)
29
 
 
31
  # πŸŽ›οΈ Gradio interface
32
  demo = gr.Interface(
33
  fn=diarize,
34
+ inputs=gr.Audio(type="filepath", label="Upload Audio (.wav)"),
35
  outputs=gr.Textbox(label="Speaker Segments"),
36
  title="πŸŽ™οΈ Speaker Diarization Demo",
37
  description="Upload an audio file and detect who speaks when using Pyannote Audio."