Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -1,16 +1,17 @@
|
|
1 |
-
from pyannote.audio import Pipeline
|
2 |
-
import gradio as gr
|
3 |
import os
|
|
|
|
|
|
|
4 |
|
5 |
-
#
|
6 |
hf_token = os.getenv("HF_TOKEN")
|
7 |
if not hf_token:
|
8 |
-
raise ValueError("HF_TOKEN is missing.
|
9 |
|
10 |
-
#
|
11 |
try:
|
12 |
pipeline = Pipeline.from_pretrained(
|
13 |
-
"pyannote/speaker-diarization",
|
14 |
use_auth_token=hf_token
|
15 |
)
|
16 |
except Exception as e:
|
@@ -19,21 +20,36 @@ except Exception as e:
|
|
19 |
# ืคืื ืงืฆืื ืืืืืื ืืืืจืื
|
20 |
def diarize(audio):
|
21 |
try:
|
22 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
23 |
result = []
|
24 |
for turn, _, speaker in diarization.itertracks(yield_label=True):
|
25 |
result.append(f"{speaker}: {turn.start:.1f}s - {turn.end:.1f}s")
|
|
|
|
|
|
|
|
|
26 |
return "\n".join(result)
|
|
|
27 |
except Exception as e:
|
28 |
return f"Error during diarization: {e}"
|
29 |
|
30 |
-
# ืืืฉืง
|
31 |
interface = gr.Interface(
|
32 |
-
fn=diarize,
|
33 |
-
inputs="audio",
|
34 |
-
outputs="text",
|
35 |
title="Speaker Diarization",
|
36 |
-
description="Upload an audio file to detect speakers and their timestamps."
|
37 |
)
|
38 |
|
39 |
-
|
|
|
|
|
|
|
|
|
|
1 |
import os
|
2 |
+
import tempfile
|
3 |
+
import gradio as gr
|
4 |
+
from pyannote.audio import Pipeline
|
5 |
|
6 |
+
# ืฉืืืคืช Hugging Face Token ืื-Secret
|
7 |
hf_token = os.getenv("HF_TOKEN")
|
8 |
if not hf_token:
|
9 |
+
raise ValueError("HF_TOKEN is missing. Please set it in the Secrets section.")
|
10 |
|
11 |
+
# ืืขืื ืช ืืืื pyannote ืืืืืื ืืืืจืื
|
12 |
try:
|
13 |
pipeline = Pipeline.from_pretrained(
|
14 |
+
"pyannote/speaker-diarization",
|
15 |
use_auth_token=hf_token
|
16 |
)
|
17 |
except Exception as e:
|
|
|
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:
|
42 |
return f"Error during diarization: {e}"
|
43 |
|
44 |
+
# ืืฆืืจืช ืืืฉืง Gradio
|
45 |
interface = gr.Interface(
|
46 |
+
fn=diarize,
|
47 |
+
inputs="audio",
|
48 |
+
outputs="text",
|
49 |
title="Speaker Diarization",
|
50 |
+
description="Upload an audio file (WAV, MP3, etc.) to detect speakers and their timestamps."
|
51 |
)
|
52 |
|
53 |
+
# ืืคืขืืช ืืืืฉืง
|
54 |
+
if __name__ == "__main__":
|
55 |
+
interface.launch()
|