Nitzantry1 commited on
Commit
4d2cffe
ยท
verified ยท
1 Parent(s): 1c24637

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +9 -4
app.py CHANGED
@@ -20,17 +20,22 @@ except Exception as e:
20
  # ืคื•ื ืงืฆื™ื” ืœื–ื™ื”ื•ื™ ื“ื•ื‘ืจื™ื
21
  def diarize(audio):
22
  try:
23
- # Gradio ืฉื•ืœื— tuple ื‘ืคื•ืจืžื˜ (ื ืชื™ื‘ ืงื•ื‘ืฅ, sample_rate)
24
- audio_file_path = audio[0] # ื”ื•ืฆืืช ื ืชื™ื‘ ื”ืงื•ื‘ืฅ ืžื”-`tuple`
 
 
25
 
26
  # ืขื™ื‘ื•ื“ ื”ืื•ื“ื™ื• ืขื pyannote
27
- diarization = pipeline(audio_file_path)
28
 
29
  # ืขื™ื‘ื•ื“ ื”ืชื•ืฆืื” ืœื–ื™ื”ื•ื™ ื“ื•ื‘ืจื™ื
30
  result = []
31
  for turn, _, speaker in diarization.itertracks(yield_label=True):
32
  result.append(f"{speaker}: {turn.start:.1f}s - {turn.end:.1f}s")
33
 
 
 
 
34
  return "\n".join(result)
35
 
36
  except Exception as e:
@@ -39,7 +44,7 @@ def diarize(audio):
39
  # ื™ืฆื™ืจืช ืžืžืฉืง Gradio
40
  interface = gr.Interface(
41
  fn=diarize,
42
- inputs="audio",
43
  outputs="text",
44
  title="Speaker Diarization",
45
  description="Upload an audio file (WAV, MP3, etc.) to detect speakers and their timestamps."
 
20
  # ืคื•ื ืงืฆื™ื” ืœื–ื™ื”ื•ื™ ื“ื•ื‘ืจื™ื
21
  def diarize(audio):
22
  try:
23
+ # ืฉืžื™ืจืช ื”ืื•ื“ื™ื• ืœืงื•ื‘ืฅ ื–ืžื ื™
24
+ with tempfile.NamedTemporaryFile(suffix=".wav", delete=False) as temp_audio:
25
+ temp_audio.write(audio.read())
26
+ temp_audio_path = temp_audio.name
27
 
28
  # ืขื™ื‘ื•ื“ ื”ืื•ื“ื™ื• ืขื pyannote
29
+ diarization = pipeline(temp_audio_path)
30
 
31
  # ืขื™ื‘ื•ื“ ื”ืชื•ืฆืื” ืœื–ื™ื”ื•ื™ ื“ื•ื‘ืจื™ื
32
  result = []
33
  for turn, _, speaker in diarization.itertracks(yield_label=True):
34
  result.append(f"{speaker}: {turn.start:.1f}s - {turn.end:.1f}s")
35
 
36
+ # ืžื—ื™ืงืช ื”ืงื•ื‘ืฅ ื”ื–ืžื ื™ ืœืื—ืจ ื”ืฉื™ืžื•ืฉ
37
+ os.remove(temp_audio_path)
38
+
39
  return "\n".join(result)
40
 
41
  except Exception as e:
 
44
  # ื™ืฆื™ืจืช ืžืžืฉืง Gradio
45
  interface = gr.Interface(
46
  fn=diarize,
47
+ inputs=gr.inputs.Audio(source="upload", type="file"),
48
  outputs="text",
49
  title="Speaker Diarization",
50
  description="Upload an audio file (WAV, MP3, etc.) to detect speakers and their timestamps."