firstAI / test_free_alternatives.py
ndc8
update
3239c69
raw
history blame
3.13 kB
#!/usr/bin/env python3
"""
Test with hardcoded working models that don't require authentication
"""
import requests
def test_free_inference_alternatives():
"""Test free inference alternatives that work without authentication"""
print("πŸ” Testing inference alternatives that work without auth")
print("=" * 60)
# Test 1: Try some models that might work without auth
free_models = [
"gpt2",
"distilgpt2",
"microsoft/DialoGPT-small"
]
for model in free_models:
print(f"\nπŸ€– Testing {model}")
url = f"https://api-inference.huggingface.co/models/{model}"
payload = {
"inputs": "Hello, how are you today?",
"parameters": {
"max_length": 50,
"temperature": 0.7
}
}
try:
response = requests.post(url, json=payload, timeout=30)
print(f"Status: {response.status_code}")
if response.status_code == 200:
result = response.json()
print(f"βœ… Success: {result}")
return model
elif response.status_code == 503:
print("⏳ Model loading, might work later")
else:
print(f"❌ Error: {response.text}")
except Exception as e:
print(f"❌ Exception: {e}")
return None
def test_alternative_apis():
"""Test completely different free APIs"""
print("\n" + "=" * 60)
print("TESTING ALTERNATIVE FREE APIs")
print("=" * 60)
# Note: These are examples, many might require their own API keys
alternatives = [
"OpenAI GPT (requires key)",
"Anthropic Claude (requires key)",
"Google Gemini (requires key)",
"Local Ollama (if installed)",
"Groq (free tier available)"
]
for alt in alternatives:
print(f"πŸ“ {alt}")
print("\nπŸ’‘ Recommendation: Get a free HuggingFace token from https://huggingface.co/settings/tokens")
if __name__ == "__main__":
working_model = test_free_inference_alternatives()
test_alternative_apis()
print("\n" + "=" * 60)
print("SOLUTION RECOMMENDATIONS")
print("=" * 60)
if working_model:
print(f"βœ… Found working model: {working_model}")
print("πŸ”§ You can update your backend to use this model")
else:
print("❌ No models work without authentication")
print("\n🎯 IMMEDIATE SOLUTIONS:")
print("1. Get free HuggingFace token: https://huggingface.co/settings/tokens")
print("2. Set HF_TOKEN environment variable in your HuggingFace Space")
print("3. Your Space might already have proper auth - the issue is local testing")
print("4. Use the deployed Space API instead of local testing")
print("\nπŸ” DEBUGGING STEPS:")
print("1. Check if your deployed Space has HF_TOKEN in Settings > Variables")
print("2. Test the deployed API directly (it should work)")
print("3. For local development, get your own HF token")