|
|
|
""" |
|
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: |
|
|
|
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 = "https://raw.githubusercontent.com/gradio-app/gradio/main/test/test_files/bus.png" |
|
|
|
|
|
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!") |