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