PatienceIzere commited on
Commit
6e4378a
·
verified ·
1 Parent(s): 6c761a9

Update hf_transcriber.py

Browse files
Files changed (1) hide show
  1. hf_transcriber.py +10 -8
hf_transcriber.py CHANGED
@@ -45,16 +45,18 @@ class HFTranscriber:
45
  try:
46
  # Try to get Hugging Face token from environment
47
  hf_token = (os.environ.get('HUGGINGFACE_TOKEN') or os.environ.get('HF_TOKEN') or (st.secrets.get('HUGGINGFACE_TOKEN') if 'secrets' in globals() and hasattr(st.secrets, 'get') else None) or (st.secrets.get('HF_TOKEN') if 'secrets' in globals() and hasattr(st.secrets, 'get') else None))
48
-
49
- # Common parameters for from_pretrained
50
- load_kwargs = {
51
- 'token': hf_token, # Use 'token' instead of 'use_auth_token' for newer versions
52
- 'local_files_only': False
53
- }
54
-
55
- # Remove None values to avoid passing None as token
 
56
  load_kwargs = {k: v for k, v in load_kwargs.items() if v is not None}
57
 
 
58
  if self.is_speecht5:
59
  # Load SpeechT5 model and processor
60
  self.processor = SpeechT5Processor.from_pretrained(
 
45
  try:
46
  # Try to get Hugging Face token from environment
47
  hf_token = (os.environ.get('HUGGINGFACE_TOKEN') or os.environ.get('HF_TOKEN') or (st.secrets.get('HUGGINGFACE_TOKEN') if 'secrets' in globals() and hasattr(st.secrets, 'get') else None) or (st.secrets.get('HF_TOKEN') if 'secrets' in globals() and hasattr(st.secrets, 'get') else None))
48
+ if not hf_token:
49
+ st.sidebar.error("No Hugging Face token found. Using public access (rate limited).Please add it to your environment variables as HUGGINGFACE_TOKEN or HF_TOKEN.")
50
+ #Configure headers for API requests
51
+ headers ={}
52
+ if hf_token:
53
+ headers['Authorization'] = f'Bearer {hf_token}'
54
+ #Configure model loading parameters
55
+ load_kwargs = {'token': hf_token, 'use_auth_token': hf_token, 'local_files_only': False, 'device': 'cuda' if torch.cuda.is_available() else 'cpu'}
56
+ #Remove None values
57
  load_kwargs = {k: v for k, v in load_kwargs.items() if v is not None}
58
 
59
+ #Rest of model loading code.....
60
  if self.is_speecht5:
61
  # Load SpeechT5 model and processor
62
  self.processor = SpeechT5Processor.from_pretrained(