Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -2,24 +2,32 @@ from pyannote.audio import Pipeline
|
|
2 |
import gradio as gr
|
3 |
import os
|
4 |
|
5 |
-
#
|
6 |
hf_token = os.getenv("HF_TOKEN")
|
|
|
|
|
7 |
|
8 |
-
#
|
9 |
-
|
10 |
-
|
11 |
-
|
12 |
-
|
|
|
|
|
|
|
13 |
|
14 |
# ืคืื ืงืฆืื ืืืืืื ืืืืจืื
|
15 |
def diarize(audio):
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
|
|
|
|
|
|
|
21 |
|
22 |
-
# ืืืฉืง ืืฉืชืืฉ
|
23 |
interface = gr.Interface(
|
24 |
fn=diarize,
|
25 |
inputs="audio",
|
|
|
2 |
import gradio as gr
|
3 |
import os
|
4 |
|
5 |
+
# ืืขื ืืช ื-Token
|
6 |
hf_token = os.getenv("HF_TOKEN")
|
7 |
+
if not hf_token:
|
8 |
+
raise ValueError("HF_TOKEN is missing. Set it in the Secrets section.")
|
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:
|
17 |
+
raise RuntimeError(f"Failed to load the pipeline: {e}")
|
18 |
|
19 |
# ืคืื ืงืฆืื ืืืืืื ืืืืจืื
|
20 |
def diarize(audio):
|
21 |
+
try:
|
22 |
+
diarization = pipeline(audio)
|
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",
|