import requests import time import sys BASE_URL = "http://localhost:8001" def verify(): print("1. Checking Health...") try: resp = requests.get(f"{BASE_URL}/health") resp.raise_for_status() print(f"Health OK: {resp.json()}") except Exception as e: print(f"Health Check Failed: {e}") sys.exit(1) print("\n2. Creating Generation...") payload = { "prompt": "An epic orchestral soundtrack", "duration": 5, "style": "Cinematic" } try: resp = requests.post(f"{BASE_URL}/api/v1/generations/", json=payload) resp.raise_for_status() data = resp.json() gen_id = data["id"] print(f"Generation Started. ID: {gen_id}") except Exception as e: print(f"Generation Creation Failed: {e}") print(resp.text) sys.exit(1) print("\n3. Polling Status...") status = "pending" audio_path_url = None for _ in range(60): # Wait up to 60 seconds (sim takes 5s) time.sleep(1) resp = requests.get(f"{BASE_URL}/api/v1/generations/{gen_id}") data = resp.json() status = data["status"] print(f"Status: {status}") if status == "completed": audio_path_url = data["audio_path"] break if status == "failed": print(f"Generation Failed: {data.get('error_message')}") sys.exit(1) if status != "completed": print("Timeout waiting for completion") sys.exit(1) print(f"\n4. Fetching Audio from {audio_path_url}...") if not audio_path_url: print("Error: No audio_path returned") sys.exit(1) # audio_path_url is relative, e.g. /api/v1/generations/.../audio full_audio_url = f"{BASE_URL}{audio_path_url}" try: resp = requests.get(full_audio_url) resp.raise_for_status() content_type = resp.headers.get("content-type") content_length = len(resp.content) print(f"Audio Fetched. Size: {content_length} bytes") print(f"Content-Type: {content_type}") if content_type not in ["audio/wav", "audio/mpeg"]: print(f"WARNING: Unexpected Content-Type: {content_type}") # This matches one of the user's error conditions to check # Verify it's a WAV (RIFF header) if resp.content[:4] != b'RIFF': print("WARNING: File does not start with RIFF header") else: print("Header check: Valid RIFF/WAV") # Check CORS headers (basic check if they exist) print(f"Access-Control-Allow-Origin: {resp.headers.get('access-control-allow-origin')}") except Exception as e: print(f"Audio Fetch Failed: {e}") sys.exit(1) print("\nVerification Complete: SUCCESS") if __name__ == "__main__": verify()