File size: 2,917 Bytes
6423ff2
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
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()