Mahmoud Elsamadony commited on
Commit
2d6ec47
·
1 Parent(s): 9749aa2
Files changed (1) hide show
  1. app.py +42 -5
app.py CHANGED
@@ -90,11 +90,48 @@ def _load_diarization_pipeline() -> Optional[Pipeline]:
90
 
91
  print("Loading diarization pipeline...")
92
  # Download the pipeline locally to avoid repeated API calls
93
- local_dir = _ensure_snapshot(DIARIZATION_REPO_ID, DIARIZATION_LOCAL_DIR)
94
- _diarization_pipeline = Pipeline.from_pretrained(
95
- local_dir,
96
- use_auth_token=HF_TOKEN # Note: newer versions use 'token' instead
97
- )
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
98
  _diarization_pipeline.to(torch.device("cpu"))
99
  return _diarization_pipeline
100
 
 
90
 
91
  print("Loading diarization pipeline...")
92
  # Download the pipeline locally to avoid repeated API calls
93
+ try:
94
+ local_dir = _ensure_snapshot(DIARIZATION_REPO_ID, DIARIZATION_LOCAL_DIR)
95
+ except Exception as e:
96
+ # snapshot_download failed (likely authentication or gating)
97
+ raise gr.Error(
98
+ f"Could not download '{DIARIZATION_REPO_ID}' to '{DIARIZATION_LOCAL_DIR}': {e}\n\n"
99
+ "Make sure your HF token has the required 'read' scope and that you have accepted "
100
+ "the model's terms at https://hf.co/models/pyannote/speaker-diarization-3.1. "
101
+ "Add the token as the 'HF_TOKEN' Space secret and restart the Space."
102
+ )
103
+
104
+ # Try loading the pipeline. Different pyannote versions accept either
105
+ # use_auth_token or token as the auth parameter.
106
+ try:
107
+ try:
108
+ _diarization_pipeline = Pipeline.from_pretrained(
109
+ local_dir, use_auth_token=HF_TOKEN
110
+ )
111
+ except TypeError:
112
+ # older/newer versions may use 'token'
113
+ _diarization_pipeline = Pipeline.from_pretrained(
114
+ local_dir, token=HF_TOKEN
115
+ )
116
+ except Exception as e:
117
+ # Loading failed - likely due to gated model or invalid token
118
+ raise gr.Error(
119
+ "Failed to load the diarization pipeline. This can happen if the model is gated or "
120
+ "your Hugging Face token doesn't have permission.\n\n"
121
+ f"Error details: {e}\n\n"
122
+ "Solutions:\n"
123
+ " - Go to https://hf.co/models/pyannote/speaker-diarization-3.1 and accept the terms if required.\n"
124
+ " - Create a token at https://hf.co/settings/tokens with 'read' scope and add it to your Space Secrets as 'HF_TOKEN'.\n"
125
+ " - Restart/rebuild the Space after adding the secret."
126
+ )
127
+
128
+ if _diarization_pipeline is None:
129
+ raise gr.Error(
130
+ "Diarization pipeline returned None after loading. Check that the model files were downloaded "
131
+ "and that your token has access to the repository."
132
+ )
133
+
134
+ # Move pipeline to CPU
135
  _diarization_pipeline.to(torch.device("cpu"))
136
  return _diarization_pipeline
137