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")