marcosremar2 commited on
Commit
d8378cd
·
1 Parent(s): 1689179

Fix authentication error and add setup instructions

Browse files
Files changed (2) hide show
  1. SETUP_INSTRUCTIONS.md +24 -0
  2. app.py +19 -10
SETUP_INSTRUCTIONS.md ADDED
@@ -0,0 +1,24 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Setup Instructions
2
+
3
+ ## Required Steps:
4
+
5
+ 1. **Accept the pyannote model conditions**:
6
+ - Visit https://huggingface.co/pyannote/speaker-diarization-3.1
7
+ - Click "Agree and access repository" to accept the conditions
8
+
9
+ 2. **Create a Hugging Face token**:
10
+ - Go to https://huggingface.co/settings/tokens
11
+ - Create a new token with "read" permissions
12
+ - Copy the token
13
+
14
+ 3. **Add the token to your Space secrets**:
15
+ - Go to your Space settings: https://huggingface.co/spaces/marcosremar2/speaker-diarization-pyannote/settings
16
+ - Scroll to "Repository secrets" section
17
+ - Add a new secret:
18
+ - Name: `HF_TOKEN`
19
+ - Value: Your Hugging Face token
20
+ - Click "Save"
21
+
22
+ 4. **Restart the Space** after adding the token
23
+
24
+ The Space should now work correctly!
app.py CHANGED
@@ -7,21 +7,30 @@ import os
7
 
8
  # Login to Hugging Face if token is available
9
  hf_token = os.environ.get("HF_TOKEN")
10
- if hf_token:
11
- login(token=hf_token)
12
 
13
- # Initialize the pipeline
14
- pipeline = Pipeline.from_pretrained(
15
- "pyannote/speaker-diarization-3.1",
16
- use_auth_token=hf_token
17
- )
18
 
19
- # Send pipeline to GPU if available
20
- if torch.cuda.is_available():
21
- pipeline.to(torch.device("cuda"))
 
 
 
 
 
 
 
 
 
 
22
 
23
  def diarize_audio(audio_file):
24
  """Process audio file and return diarization results"""
 
 
 
25
  try:
26
  # Apply pretrained pipeline
27
  diarization = pipeline(audio_file)
 
7
 
8
  # Login to Hugging Face if token is available
9
  hf_token = os.environ.get("HF_TOKEN")
10
+ if not hf_token:
11
+ raise ValueError("HF_TOKEN environment variable is required. Please set it in the Space settings.")
12
 
13
+ login(token=hf_token)
 
 
 
 
14
 
15
+ # Initialize the pipeline
16
+ try:
17
+ pipeline = Pipeline.from_pretrained(
18
+ "pyannote/speaker-diarization-3.1",
19
+ use_auth_token=hf_token
20
+ )
21
+
22
+ # Send pipeline to GPU if available
23
+ if torch.cuda.is_available():
24
+ pipeline.to(torch.device("cuda"))
25
+ except Exception as e:
26
+ print(f"Error loading pipeline: {e}")
27
+ pipeline = None
28
 
29
  def diarize_audio(audio_file):
30
  """Process audio file and return diarization results"""
31
+ if pipeline is None:
32
+ return "Pipeline not loaded. Please ensure HF_TOKEN is set and you have access to pyannote/speaker-diarization-3.1"
33
+
34
  try:
35
  # Apply pretrained pipeline
36
  diarization = pipeline(audio_file)