anfastech commited on
Commit
5170332
ยท
1 Parent(s): 13a1b12

Fix: token issue

Browse files
.gitignore ADDED
@@ -0,0 +1,4 @@
 
 
 
 
 
1
+ .env
2
+ hello.wav
3
+ venv/
4
+ __pycache__/
diagnosis/ai_engine/detect_stuttering.py CHANGED
@@ -1,4 +1,5 @@
1
  # diagnosis/ai_engine/detect_stuttering.py
 
2
  import librosa
3
  import torch
4
  import torchaudio
@@ -25,6 +26,7 @@ logger = logging.getLogger(__name__)
25
  MODEL_ID = "ai4bharat/indicwav2vec-hindi"
26
  LID_MODEL_ID = "facebook/mms-lid-126"
27
  DEVICE = "cuda" if torch.cuda.is_available() else "cpu"
 
28
 
29
  INDIAN_LANGUAGES = {
30
  'hindi': 'hin', 'english': 'eng', 'tamil': 'tam', 'telugu': 'tel',
@@ -137,11 +139,19 @@ class AdvancedStutterDetector:
137
 
138
  def __init__(self):
139
  logger.info(f"๐Ÿš€ Initializing Advanced AI Engine on {DEVICE}...")
 
 
 
 
140
  try:
141
  # Wav2Vec2 Model Loading - IndicWav2Vec Hindi Model
142
- self.processor = AutoProcessor.from_pretrained(MODEL_ID)
 
 
 
143
  self.model = Wav2Vec2ForCTC.from_pretrained(
144
  MODEL_ID,
 
145
  torch_dtype=torch.float16 if DEVICE == "cuda" else torch.float32
146
  ).to(DEVICE)
147
  self.model.eval()
@@ -167,8 +177,14 @@ class AdvancedStutterDetector:
167
  """Detect language using MMS LID model"""
168
  try:
169
  from transformers import Wav2Vec2ForSequenceClassification
170
- lid_model = Wav2Vec2ForSequenceClassification.from_pretrained(LID_MODEL_ID).to(DEVICE)
171
- lid_processor = AutoFeatureExtractor.from_pretrained(LID_MODEL_ID)
 
 
 
 
 
 
172
 
173
  audio, sr = librosa.load(audio_path, sr=16000)
174
  inputs = lid_processor(audio, sampling_rate=16000, return_tensors="pt").to(DEVICE)
 
1
  # diagnosis/ai_engine/detect_stuttering.py
2
+ import os
3
  import librosa
4
  import torch
5
  import torchaudio
 
26
  MODEL_ID = "ai4bharat/indicwav2vec-hindi"
27
  LID_MODEL_ID = "facebook/mms-lid-126"
28
  DEVICE = "cuda" if torch.cuda.is_available() else "cpu"
29
+ HF_TOKEN = os.getenv("HF_TOKEN") # Hugging Face token for authenticated model access
30
 
31
  INDIAN_LANGUAGES = {
32
  'hindi': 'hin', 'english': 'eng', 'tamil': 'tam', 'telugu': 'tel',
 
139
 
140
  def __init__(self):
141
  logger.info(f"๐Ÿš€ Initializing Advanced AI Engine on {DEVICE}...")
142
+ if HF_TOKEN:
143
+ logger.info("โœ… HF_TOKEN found - using authenticated model access")
144
+ else:
145
+ logger.warning("โš ๏ธ HF_TOKEN not found - model access may fail if authentication is required")
146
  try:
147
  # Wav2Vec2 Model Loading - IndicWav2Vec Hindi Model
148
+ self.processor = AutoProcessor.from_pretrained(
149
+ MODEL_ID,
150
+ token=HF_TOKEN
151
+ )
152
  self.model = Wav2Vec2ForCTC.from_pretrained(
153
  MODEL_ID,
154
+ token=HF_TOKEN,
155
  torch_dtype=torch.float16 if DEVICE == "cuda" else torch.float32
156
  ).to(DEVICE)
157
  self.model.eval()
 
177
  """Detect language using MMS LID model"""
178
  try:
179
  from transformers import Wav2Vec2ForSequenceClassification
180
+ lid_model = Wav2Vec2ForSequenceClassification.from_pretrained(
181
+ LID_MODEL_ID,
182
+ token=HF_TOKEN
183
+ ).to(DEVICE)
184
+ lid_processor = AutoFeatureExtractor.from_pretrained(
185
+ LID_MODEL_ID,
186
+ token=HF_TOKEN
187
+ )
188
 
189
  audio, sr = librosa.load(audio_path, sr=16000)
190
  inputs = lid_processor(audio, sampling_rate=16000, return_tensors="pt").to(DEVICE)