hanszhu's picture
build(space): initial Docker Space with Gradio app, MMDet, SAM integration
eb4d305
#!/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!")