NickVerri commited on
Commit
ab2ef04
·
verified ·
1 Parent(s): 69bea18

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +13 -19
app.py CHANGED
@@ -7,18 +7,15 @@ import requests
7
  import torch
8
  from datetime import timedelta
9
  from pyannote.audio import Pipeline
 
10
 
11
  # --- Configuration & Tokens ---
12
- # OPTION 1: Set this as a 'Secret' in Hugging Face Space Settings (Recommended)
13
- # OPTION 2: Paste your token between the quotes below to hardcode it permanently
14
  HARDCODED_HF_TOKEN = "PASTE_YOUR_HF_TOKEN_HERE"
15
  HARDCODED_GEMINI_KEY = ""
16
 
17
- # Logic to determine which keys to use
18
  ENV_HF_TOKEN = os.environ.get("HF_TOKEN", "")
19
  ENV_GEMINI_KEY = os.environ.get("GEMINI_API_KEY", "")
20
 
21
- # Determine active keys (Prioritize Secrets > Hardcoded)
22
  ACTIVE_HF_TOKEN = ENV_HF_TOKEN if ENV_HF_TOKEN else HARDCODED_HF_TOKEN
23
  ACTIVE_GEMINI_KEY = ENV_GEMINI_KEY if ENV_GEMINI_KEY else HARDCODED_GEMINI_KEY
24
 
@@ -129,26 +126,23 @@ if uploaded_file:
129
  "audio_optimized.m4a", "-y"
130
  ])
131
 
132
- # 1. Diarization
133
  try:
134
- # Fix for PyTorch 2.6+ 'weights_only' error
135
  try:
136
  torch.serialization.add_safe_globals([torch.torch_version.TorchVersion])
137
  except AttributeError:
138
- pass # Older PyTorch versions don't need this
139
 
140
- # Explicit pipeline loading logic
141
- try:
142
- pipeline = Pipeline.from_pretrained(
143
- "pyannote/speaker-diarization-3.1",
144
- use_auth_token=ACTIVE_HF_TOKEN
145
- )
146
- except Exception:
147
- # Fallback for newer library syntax
148
- pipeline = Pipeline.from_pretrained(
149
- "pyannote/speaker-diarization-3.1",
150
- token=ACTIVE_HF_TOKEN
151
- )
152
 
153
  if torch.cuda.is_available():
154
  pipeline.to(torch.device("cuda"))
 
7
  import torch
8
  from datetime import timedelta
9
  from pyannote.audio import Pipeline
10
+ from huggingface_hub import hf_hub_download
11
 
12
  # --- Configuration & Tokens ---
 
 
13
  HARDCODED_HF_TOKEN = "PASTE_YOUR_HF_TOKEN_HERE"
14
  HARDCODED_GEMINI_KEY = ""
15
 
 
16
  ENV_HF_TOKEN = os.environ.get("HF_TOKEN", "")
17
  ENV_GEMINI_KEY = os.environ.get("GEMINI_API_KEY", "")
18
 
 
19
  ACTIVE_HF_TOKEN = ENV_HF_TOKEN if ENV_HF_TOKEN else HARDCODED_HF_TOKEN
20
  ACTIVE_GEMINI_KEY = ENV_GEMINI_KEY if ENV_GEMINI_KEY else HARDCODED_GEMINI_KEY
21
 
 
126
  "audio_optimized.m4a", "-y"
127
  ])
128
 
129
+ # 1. Diarization with Manual Config Loading
130
  try:
131
+ # Fix for PyTorch 2.6+ security
132
  try:
133
  torch.serialization.add_safe_globals([torch.torch_version.TorchVersion])
134
  except AttributeError:
135
+ pass
136
 
137
+ # Download config.yaml manually to bypass Pipeline.from_pretrained argument issues
138
+ config_path = hf_hub_download(
139
+ repo_id="pyannote/speaker-diarization-3.1",
140
+ filename="config.yaml",
141
+ token=ACTIVE_HF_TOKEN
142
+ )
143
+
144
+ # Load pipeline from the local config file
145
+ pipeline = Pipeline.from_pretrained(config_path)
 
 
 
146
 
147
  if torch.cuda.is_available():
148
  pipeline.to(torch.device("cuda"))