#!/usr/bin/env python3 """ Simple test script for the Dense Captioning Platform API """ def test_gradio_client(): """Test using gradio_client""" print("๐Ÿงช Testing with gradio_client...") try: from gradio_client import Client, handle_file # Initialize client with direct URL (working approach) client = Client("https://hanszhu-dense-captioning-platform.hf.space") # Test with a simple image URL test_url = "https://raw.githubusercontent.com/gradio-app/gradio/main/test/test_files/bus.png" print(f"Testing with URL: {test_url}") # Make prediction using handle_file and fn_index (working approach) result = client.predict( image=handle_file(test_url), fn_index=0 # Use fn_index instead of api_name ) print("โœ… gradio_client test successful!") print(f"Result: {result}") return True except Exception as e: print(f"โŒ gradio_client test failed: {e}") return False def test_direct_api(): """Test direct API call (Blocks don't support RESTful APIs)""" print("\n๐Ÿงช Testing direct API call...") print("โš ๏ธ Direct API calls not supported for Blocks-based Spaces") print(" Use gradio_client instead for API access") return False if __name__ == "__main__": print("๐Ÿš€ Testing Dense Captioning Platform API") print("=" * 50) # Test both methods gradio_success = test_gradio_client() direct_success = test_direct_api() print("\n" + "=" * 50) print("๐Ÿ Test Results:") print(f"gradio_client: {'โœ… PASS' if gradio_success else 'โŒ FAIL'}") print(f"Direct API: {'โœ… PASS' if direct_success else 'โŒ FAIL'}") if gradio_success or direct_success: print("\n๐ŸŽ‰ API is working!") else: print("\nโš ๏ธ API needs more configuration")