3ssem0
fix: configuration error - aligned entry point to app.py and enforced LF/BOM-less encoding
ec47953
Raw
History Blame Contribute Delete
1.04 kB
import os
from dotenv import load_dotenv
from huggingface_hub import InferenceClient, whoami
# Load .env explicitly
load_dotenv()
token = os.getenv("HUGGINGFACE_TOKEN")
print(f"Token from environment: {token}")
if not token:
print("❌ No token found!")
exit(1)
# 1. Check whoami (verifies validity)
try:
user_info = whoami(token=token)
print(f"βœ… Token is valid for user: {user_info['name']}")
print(f" Org: {user_info.get('orgs', 'None')}")
except Exception as e:
print(f"❌ Token validation failed (whoami): {e}")
# 2. Try simple inference with a generic model
client = InferenceClient(token=token)
model = "HuggingFaceH4/zephyr-7b-beta"
print(f"\nTesting Inference on {model}...")
try:
messages = [{"role": "user", "content": "Hello!"}]
response = client.chat_completion(messages=messages, model=model, max_tokens=10)
print(f"βœ… Inference success: {response.choices[0].message.content}")
except Exception as e:
print(f"❌ Inference failed: {e}")