Spaces:
Sleeping
Sleeping
File size: 3,811 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 116 117 118 119 120 121 122 123 |
#!/usr/bin/env python3
"""
Debug script to check API status and endpoints
"""
import requests
import json
def check_space_status():
"""Check if the space is running"""
print("π Checking space status...")
try:
# Check main page
response = requests.get("https://hanszhu-dense-captioning-platform.hf.space/")
print(f"Main page status: {response.status_code}")
if response.status_code == 200:
print("β
Space is accessible")
else:
print("β Space is not accessible")
except Exception as e:
print(f"β Error checking space: {e}")
def check_api_endpoints():
"""Check various API endpoints"""
print("\nπ Checking API endpoints...")
base_url = "https://hanszhu-dense-captioning-platform.hf.space"
endpoints = [
"/",
"/api",
"/api/predict",
"/predict",
"/api/predict/",
"/predict/"
]
for endpoint in endpoints:
try:
response = requests.get(f"{base_url}{endpoint}")
print(f"{endpoint}: {response.status_code} - {response.headers.get('content-type', 'unknown')}")
if response.status_code == 200:
print(f" Content preview: {response.text[:100]}...")
except Exception as e:
print(f"{endpoint}: Error - {e}")
def test_post_request():
"""Test POST request to predict endpoint"""
print("\nπ Testing POST request...")
try:
# Test URL
test_url = "https://raw.githubusercontent.com/gradio-app/gradio/main/test/test_files/bus.png"
# Try different POST formats
test_data = [
{"data": [test_url]},
{"fn_index": 0, "data": [test_url]},
{"data": test_url},
test_url
]
for i, data in enumerate(test_data):
print(f"\nTest {i+1}: {type(data)}")
try:
response = requests.post(
"https://hanszhu-dense-captioning-platform.hf.space/predict",
json=data,
headers={"Content-Type": "application/json"}
)
print(f" Status: {response.status_code}")
print(f" Content-Type: {response.headers.get('content-type', 'unknown')}")
print(f" Response: {response.text[:200]}...")
except Exception as e:
print(f" Error: {e}")
except Exception as e:
print(f"β Error in POST test: {e}")
def test_gradio_client_detailed():
"""Test gradio_client with detailed error handling"""
print("\nπ Testing gradio_client with detailed error handling...")
try:
from gradio_client import Client
print("Creating client...")
client = Client("hanszhu/Dense-Captioning-Platform")
print("Getting space info...")
info = client.view_api()
print(f"API info: {info}")
print("Making prediction...")
test_url = "https://raw.githubusercontent.com/gradio-app/gradio/main/test/test_files/bus.png"
result = client.predict(test_url, api_name="/predict")
print(f"β
Success! Result: {result}")
except Exception as e:
print(f"β gradio_client error: {e}")
import traceback
traceback.print_exc()
if __name__ == "__main__":
print("π Debugging Dense Captioning Platform API")
print("=" * 60)
check_space_status()
check_api_endpoints()
test_post_request()
test_gradio_client_detailed()
print("\n" + "=" * 60)
print("οΏ½οΏ½ Debug completed!") |