File size: 4,031 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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
#!/usr/bin/env python3
"""
Test script to check web interface and understand API issue
"""

import requests
import time

def check_web_interface():
    """Check if the web interface is working"""
    print("πŸ” Checking web interface...")
    
    try:
        response = requests.get("https://hanszhu-dense-captioning-platform.hf.space/")
        
        if response.status_code == 200:
            print("βœ… Web interface is accessible")
            
            # Check if it contains our app content
            if "Dense Captioning Platform" in response.text:
                print("βœ… App is loaded correctly")
            else:
                print("❌ App content not found")
                
            # Check if it contains Gradio elements
            if "gradio" in response.text.lower():
                print("βœ… Gradio is loaded")
            else:
                print("❌ Gradio not found")
                
        else:
            print(f"❌ Web interface not accessible: {response.status_code}")
            
    except Exception as e:
        print(f"❌ Error checking web interface: {e}")

def check_api_info():
    """Check API info endpoint"""
    print("\nπŸ” Checking API info...")
    
    try:
        # Try different API info endpoints
        endpoints = [
            "https://hanszhu-dense-captioning-platform.hf.space/api",
            "https://hanszhu-dense-captioning-platform.hf.space/api/",
            "https://hanszhu-dense-captioning-platform.hf.space/api/predict",
            "https://hanszhu-dense-captioning-platform.hf.space/api/predict/"
        ]
        
        for endpoint in endpoints:
            print(f"\nTrying: {endpoint}")
            
            try:
                response = requests.get(endpoint)
                print(f"  Status: {response.status_code}")
                print(f"  Content-Type: {response.headers.get('content-type', 'unknown')}")
                
                if response.status_code == 200:
                    content = response.text[:200]
                    print(f"  Content: {content}...")
                    
                    # Check if it's JSON
                    if response.headers.get('content-type', '').startswith('application/json'):
                        print("  βœ… JSON response")
                    else:
                        print("  ❌ Not JSON response")
                        
            except Exception as e:
                print(f"  Error: {e}")
                
    except Exception as e:
        print(f"❌ Error checking API info: {e}")

def wait_and_retry():
    """Wait and retry to see if the API becomes available"""
    print("\n⏳ Waiting for API to become available...")
    
    for i in range(5):
        print(f"\nAttempt {i+1}/5:")
        
        try:
            response = requests.get("https://hanszhu-dense-captioning-platform.hf.space/api")
            
            if response.status_code == 200 and response.headers.get('content-type', '').startswith('application/json'):
                print("βœ… API is now available!")
                return True
            else:
                print(f"❌ API not ready yet: {response.status_code}")
                
        except Exception as e:
            print(f"❌ Error: {e}")
            
        if i < 4:  # Don't sleep after the last attempt
            print("Waiting 30 seconds...")
            time.sleep(30)
    
    return False

if __name__ == "__main__":
    print("πŸš€ Testing Dense Captioning Platform Web Interface")
    print("=" * 60)
    
    check_web_interface()
    check_api_info()
    
    # Wait and retry
    if not wait_and_retry():
        print("\n⚠️ API is still not available after waiting")
        print("This might indicate:")
        print("1. The space is still loading models")
        print("2. There's a configuration issue")
        print("3. The API endpoints need different configuration")
    
    print("\n" + "=" * 60)
    print("🏁 Web interface test completed!")