Spaces:
Sleeping
Sleeping
File size: 1,955 Bytes
eb4d305 |
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 |
#!/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") |