TranscriptWriting / debug_token.py
jmisak's picture
Upload 57 files
52d0298 verified
raw
history blame
2.85 kB
#!/usr/bin/env python3
"""
Debug: Show exactly what token is being loaded
"""
import os
print("=" * 80)
print("TOKEN DEBUG")
print("=" * 80)
print()
# Load .env file
def load_env_file(filepath='.env'):
print(f"Attempting to load: {filepath}")
print(f"File exists: {os.path.exists(filepath)}")
print()
if os.path.exists(filepath):
with open(filepath, 'r') as f:
lines = f.readlines()
print(f"Found {len(lines)} lines in .env file")
print()
for i, line in enumerate(lines, 1):
line = line.strip()
if line and not line.startswith('#'):
if '=' in line:
key, value = line.split('=', 1)
key = key.strip()
value = value.strip()
if key == 'HUGGINGFACE_TOKEN':
print(f"Line {i}: Found HUGGINGFACE_TOKEN")
print(f" Full value: {value}")
print(f" Length: {len(value)} chars")
print(f" Starts with 'hf_': {value.startswith('hf_')}")
print(f" First 20 chars: {value[:20]}")
print(f" Last 5 chars: ...{value[-5:]}")
print()
os.environ[key] = value
return True
else:
print("ERROR: .env file not found!")
return False
env_loaded = load_env_file('.env')
print()
print("After loading:")
print(f" os.getenv('HUGGINGFACE_TOKEN'): {os.getenv('HUGGINGFACE_TOKEN')}")
print(f" Length: {len(os.getenv('HUGGINGFACE_TOKEN', ''))} chars")
print()
# Try to use it
print("Testing with HuggingFace:")
print()
try:
from huggingface_hub import InferenceClient
token = os.getenv('HUGGINGFACE_TOKEN')
print(f"Token passed to InferenceClient: {token[:20]}...{token[-5:]}")
print()
client = InferenceClient(token=token)
print("βœ… InferenceClient created (token accepted)")
# Try a simple API call
print()
print("Testing actual API call...")
response = client.text_generation(
prompt="Say hello",
model="microsoft/Phi-3-mini-4k-instruct",
max_new_tokens=10
)
print(f"βœ… API call successful!")
print(f"Response: {response}")
except Exception as e:
print(f"❌ Error: {e}")
print()
print("This suggests the token is invalid or revoked.")
print()
print("Please:")
print("1. Go to https://huggingface.co/settings/tokens")
print("2. Check if your token shows as 'Active'")
print("3. If not, create a NEW token")
print("4. Copy it EXACTLY (no spaces, no quotes)")
print()
print("=" * 80)