CoolFace
Apppublic

OnyxMunk/AudioForge

sourceHugging Facemitupdated 8mo agoView on Hugging Face
0likes
verify_workflow.py93 linesDownload Raw Back to scripts
1import requests2import time3import sys4 5BASE_URL = "http://localhost:8001"6 7def verify():8    print("1. Checking Health...")9    try:10        resp = requests.get(f"{BASE_URL}/health")11        resp.raise_for_status()12        print(f"Health OK: {resp.json()}")13    except Exception as e:14        print(f"Health Check Failed: {e}")15        sys.exit(1)16 17    print("\n2. Creating Generation...")18    payload = {19        "prompt": "An epic orchestral soundtrack",20        "duration": 5,21        "style": "Cinematic"22    }23    try:24        resp = requests.post(f"{BASE_URL}/api/v1/generations/", json=payload)25        resp.raise_for_status()26        data = resp.json()27        gen_id = data["id"]28        print(f"Generation Started. ID: {gen_id}")29    except Exception as e:30        print(f"Generation Creation Failed: {e}")31        print(resp.text)32        sys.exit(1)33 34    print("\n3. Polling Status...")35    status = "pending"36    audio_path_url = None37    for _ in range(60): # Wait up to 60 seconds (sim takes 5s)38        time.sleep(1)39        resp = requests.get(f"{BASE_URL}/api/v1/generations/{gen_id}")40        data = resp.json()41        status = data["status"]42        print(f"Status: {status}")43        if status == "completed":44            audio_path_url = data["audio_path"]45            break46        if status == "failed":47            print(f"Generation Failed: {data.get('error_message')}")48            sys.exit(1)49    50    if status != "completed":51        print("Timeout waiting for completion")52        sys.exit(1)53 54    print(f"\n4. Fetching Audio from {audio_path_url}...")55    if not audio_path_url:56        print("Error: No audio_path returned")57        sys.exit(1)58        59    # audio_path_url is relative, e.g. /api/v1/generations/.../audio60    full_audio_url = f"{BASE_URL}{audio_path_url}"61    62    try:63        resp = requests.get(full_audio_url)64        resp.raise_for_status()65        66        content_type = resp.headers.get("content-type")67        content_length = len(resp.content)68        69        print(f"Audio Fetched. Size: {content_length} bytes")70        print(f"Content-Type: {content_type}")71        72        if content_type not in ["audio/wav", "audio/mpeg"]:73             print(f"WARNING: Unexpected Content-Type: {content_type}")74             # This matches one of the user's error conditions to check75        76        # Verify it's a WAV (RIFF header)77        if resp.content[:4] != b'RIFF':78            print("WARNING: File does not start with RIFF header")79        else:80            print("Header check: Valid RIFF/WAV")81            82        # Check CORS headers (basic check if they exist)83        print(f"Access-Control-Allow-Origin: {resp.headers.get('access-control-allow-origin')}")84            85    except Exception as e:86        print(f"Audio Fetch Failed: {e}")87        sys.exit(1)88 89    print("\nVerification Complete: SUCCESS")90 91if __name__ == "__main__":92    verify()93