File size: 2,847 Bytes
52d0298
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
#!/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)