File size: 3,072 Bytes
4e10023 c6f7b75 4e10023 |
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 |
#!/usr/bin/env python3
"""
Simple test for the image-text-to-text pipeline setup
"""
import requests
from transformers import pipeline
import asyncio
def test_pipeline_availability():
"""Test if the image-text-to-text pipeline can be initialized"""
print("π Testing pipeline availability...")
try:
# Try to initialize the pipeline locally
print("π Initializing image-text-to-text pipeline...")
# Try with a smaller, more accessible model first
models_to_try = [
"Salesforce/blip-image-captioning-base", # More common model
"microsoft/git-base-textcaps", # Alternative model
"unsloth/DeepSeek-R1-0528-Qwen3-8B-GGUF" # Updated model
]
for model_name in models_to_try:
try:
print(f"π₯ Trying model: {model_name}")
pipe = pipeline("image-to-text", model=model_name) # Use image-to-text instead
print(f"β
Successfully loaded {model_name}")
# Test with a simple image URL
test_url = "https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/p-blog/candy.JPG"
print(f"πΌοΈ Testing with image: {test_url}")
result = pipe(test_url)
print(f"π Result: {result}")
return True, model_name
except Exception as e:
print(f"β Failed to load {model_name}: {e}")
continue
print("β No suitable models could be loaded")
return False, None
except Exception as e:
print(f"β Pipeline test error: {e}")
return False, None
def test_backend_models_endpoint():
"""Test the backend models endpoint"""
print("\nπ Testing backend models endpoint...")
try:
response = requests.get("http://localhost:8000/v1/models", timeout=10)
if response.status_code == 200:
result = response.json()
print(f"β
Available models: {[model['id'] for model in result['data']]}")
return True
else:
print(f"β Models endpoint failed: {response.status_code}")
return False
except Exception as e:
print(f"β Models endpoint error: {e}")
return False
def main():
"""Run pipeline tests"""
print("π§ͺ Testing Image-Text Pipeline Setup\n")
# Test 1: Check if we can initialize pipelines locally
success, model_name = test_pipeline_availability()
if success:
print(f"\nπ Pipeline test successful with model: {model_name}")
print("π‘ Recommendation: Update backend_service.py to use this model")
else:
print("\nβ οΈ Pipeline test failed")
print("π‘ Recommendation: Use image-to-text pipeline instead of image-text-to-text")
# Test 2: Check backend models
test_backend_models_endpoint()
if __name__ == "__main__":
main()
|