Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -20,17 +20,22 @@ except Exception as e:
|
|
20 |
# ืคืื ืงืฆืื ืืืืืื ืืืืจืื
|
21 |
def diarize(audio):
|
22 |
try:
|
23 |
-
#
|
24 |
-
|
|
|
|
|
25 |
|
26 |
# ืขืืืื ืืืืืื ืขื pyannote
|
27 |
-
diarization = pipeline(
|
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="
|
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."
|