Spaces:
Sleeping
Sleeping
#!/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!") |