Spaces:
Sleeping
Sleeping
#!/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") |