| |
| """ |
| 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: |
| |
| print("π Initializing image-text-to-text pipeline...") |
| |
| |
| models_to_try = [ |
| "Salesforce/blip-image-captioning-base", |
| "microsoft/git-base-textcaps", |
| "unsloth/gemma-3n-E4B-it-GGUF" |
| ] |
| |
| for model_name in models_to_try: |
| try: |
| print(f"π₯ Trying model: {model_name}") |
| pipe = pipeline("image-to-text", model=model_name) |
| print(f"β
Successfully loaded {model_name}") |
| |
| |
| 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") |
| |
| |
| 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_backend_models_endpoint() |
|
|
| if __name__ == "__main__": |
| main() |
|
|