Spaces:
Sleeping
Sleeping
#!/usr/bin/env python3 | |
""" | |
Test script for the integrated Inference Server setup | |
This script verifies that both the FastAPI API and Gradio UI work correctly. | |
""" | |
import asyncio | |
import sys | |
import time | |
from pathlib import Path | |
import httpx | |
# Add src to path | |
src_path = Path(__file__).parent / "src" | |
sys.path.insert(0, str(src_path)) | |
async def test_api_endpoints(): | |
"""Test that the FastAPI endpoints work correctly.""" | |
base_url = "http://localhost:7860" | |
async with httpx.AsyncClient(timeout=10.0) as client: | |
try: | |
# Test main health endpoint | |
print("π Testing main health endpoint...") | |
response = await client.get(f"{base_url}/api/health") | |
assert response.status_code == 200 | |
data = response.json() | |
print(f"β Health check passed: {data}") | |
# Test API docs availability | |
print("π Testing API docs availability...") | |
response = await client.get(f"{base_url}/api/docs") | |
assert response.status_code == 200 | |
print("β API docs available") | |
# Test OpenAPI schema | |
print("π Testing OpenAPI schema...") | |
response = await client.get(f"{base_url}/api/openapi.json") | |
assert response.status_code == 200 | |
schema = response.json() | |
print(f"β OpenAPI schema available: {schema['info']['title']}") | |
# Test sessions endpoint | |
print("π Testing sessions endpoint...") | |
response = await client.get(f"{base_url}/api/sessions") | |
assert response.status_code == 200 | |
sessions = response.json() | |
print(f"β Sessions endpoint works: {len(sessions)} sessions") | |
# Test Gradio UI availability | |
print("π¨ Testing Gradio UI availability...") | |
response = await client.get(f"{base_url}/") | |
assert response.status_code == 200 | |
print("β Gradio UI available") | |
print("\nπ All tests passed! The integrated setup is working correctly.") | |
return True | |
except Exception as e: | |
print(f"β Test failed: {e}") | |
return False | |
async def test_session_creation(): | |
"""Test creating a session through the API.""" | |
base_url = "http://localhost:7860" | |
async with httpx.AsyncClient(timeout=30.0) as client: | |
try: | |
# Create a test session | |
print("π§ Testing session creation...") | |
session_data = { | |
"session_id": "test-session", | |
"policy_path": "./checkpoints/act_so101_beyond", | |
"camera_names": ["front"], | |
"arena_server_url": "http://localhost:8000", | |
} | |
response = await client.post(f"{base_url}/api/sessions", json=session_data) | |
if response.status_code == 200: | |
print("β Session creation successful") | |
return True | |
print( | |
f"β οΈ Session creation failed (expected if no model exists): {response.status_code}" | |
) | |
return True # This is expected if no model exists | |
except Exception as e: | |
print(f"β οΈ Session creation test failed (expected if no model exists): {e}") | |
return True # This is expected if no model exists | |
def print_integration_info(): | |
"""Print information about the integrated setup.""" | |
print("=" * 60) | |
print("π€ Integrated Inference Server Test Results") | |
print("=" * 60) | |
print() | |
print("π Access Points:") | |
print(" π¨ Gradio UI: http://localhost:7860/") | |
print(" π API Docs: http://localhost:7860/api/docs") | |
print(" π Health Check: http://localhost:7860/api/health") | |
print(" π OpenAPI Schema: http://localhost:7860/api/openapi.json") | |
print(" π Sessions API: http://localhost:7860/api/sessions") | |
print() | |
print("π§ Features Available:") | |
print(" β Direct session management through UI") | |
print(" β Full REST API for programmatic access") | |
print(" β Interactive API documentation") | |
print(" β Single port deployment") | |
print(" β CORS enabled for frontend integration") | |
print() | |
if __name__ == "__main__": | |
print("π§ͺ Testing Integrated Inference Server Setup") | |
print("Make sure the server is running with: python launch_simple.py") | |
print() | |
# Wait a moment for server to be ready | |
time.sleep(2) | |
# Run tests | |
try: | |
success = asyncio.run(test_api_endpoints()) | |
if success: | |
asyncio.run(test_session_creation()) | |
print_integration_info() | |
except KeyboardInterrupt: | |
print("\nπ Tests interrupted by user") | |
except Exception as e: | |
print(f"β Test runner error: {e}") | |
sys.exit(1) | |