YosefAyele's picture
fix issues with model loading
8f83228
#!/usr/bin/env python3
"""
Test script to verify if the Hugging Face model exists and can be loaded.
Run this to debug model loading issues.
"""
from transformers import pipeline
import requests
def test_model_exists(model_name):
"""Test if model exists on Hugging Face"""
url = f"https://huggingface.co/api/models/{model_name}"
try:
response = requests.get(url)
if response.status_code == 200:
print(f"βœ… Model {model_name} exists on Hugging Face")
model_info = response.json()
print(f" Pipeline tag: {model_info.get('pipeline_tag', 'Unknown')}")
print(f" Downloads: {model_info.get('downloads', 'Unknown')}")
return True
elif response.status_code == 404:
print(f"❌ Model {model_name} not found on Hugging Face")
return False
else:
print(f"⚠️ Unexpected response: {response.status_code}")
return False
except Exception as e:
print(f"❌ Error checking model: {e}")
return False
def test_model_loading(model_name):
"""Test loading the model with transformers"""
try:
print(f"\nπŸ”„ Attempting to load model: {model_name}")
classifier = pipeline(
"text-classification",
model=model_name,
return_all_scores=True,
trust_remote_code=True
)
print("βœ… Model loaded successfully!")
# Test classification
test_text = "This product looks amazing!"
result = classifier(test_text)
print(f"βœ… Test classification successful:")
print(f" Input: '{test_text}'")
print(f" Output: {result}")
return True
except Exception as e:
print(f"❌ Error loading model: {e}")
return False
def main():
model_name = "YosefA/adfluence-intent-model"
print(f"πŸ§ͺ Testing model: {model_name}")
print("=" * 50)
# Test 1: Check if model exists
exists = test_model_exists(model_name)
if exists:
# Test 2: Try loading the model
test_model_loading(model_name)
else:
print("\nπŸ’‘ Suggestions:")
print("1. Check if the model name is spelled correctly")
print("2. Verify the model is public (not private)")
print("3. Check if you need to be logged in to access it")
print("4. Try searching for similar models:")
print(" https://huggingface.co/models?search=intent+classification")
if __name__ == "__main__":
main()