-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_endpoint.py
More file actions
102 lines (83 loc) · 2.84 KB
/
test_endpoint.py
File metadata and controls
102 lines (83 loc) · 2.84 KB
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
94
95
96
97
98
99
100
101
102
#!/usr/bin/env python3
"""
Test script for RunPod VAE endpoint
Usage:
python test_endpoint.py <audio_file>
Environment variables:
RUNPOD_ENDPOINT_ID - Your endpoint ID
RUNPOD_API_KEY - Your API key
"""
import os
import sys
import base64
import requests
import numpy as np
ENDPOINT_ID = os.environ.get("RUNPOD_ENDPOINT_ID")
API_KEY = os.environ.get("RUNPOD_API_KEY")
def test_endpoint(audio_path: str):
if not ENDPOINT_ID or not API_KEY:
print("Error: Set RUNPOD_ENDPOINT_ID and RUNPOD_API_KEY environment variables")
print("\nExample:")
print(" export RUNPOD_ENDPOINT_ID=abc123xyz")
print(" export RUNPOD_API_KEY=your_key_here")
sys.exit(1)
if not os.path.exists(audio_path):
print(f"Error: File not found: {audio_path}")
sys.exit(1)
print(f"Loading: {audio_path}")
with open(audio_path, "rb") as f:
audio_bytes = f.read()
audio_b64 = base64.b64encode(audio_bytes).decode()
print(f"Audio size: {len(audio_bytes) / 1024 / 1024:.1f} MB")
print(f"\nCalling RunPod endpoint: {ENDPOINT_ID}")
print("This may take 30-60 seconds on first call (cold start)...")
response = requests.post(
f"https://api.runpod.ai/v2/{ENDPOINT_ID}/runsync",
headers={
"Authorization": f"Bearer {API_KEY}",
"Content-Type": "application/json"
},
json={
"input": {
"audio_base64": audio_b64,
"compute_umap": True
}
},
timeout=300
)
if response.status_code != 200:
print(f"Error: HTTP {response.status_code}")
print(response.text)
sys.exit(1)
result = response.json()
if "error" in result:
print(f"Error: {result['error']}")
if "traceback" in result:
print(result["traceback"])
sys.exit(1)
output = result.get("output", result)
# Decode results
latents = np.frombuffer(
base64.b64decode(output["latents"]),
dtype=np.float32
).reshape(output["latents_shape"])
projection = None
if "projection" in output:
projection = np.frombuffer(
base64.b64decode(output["projection"]),
dtype=np.float32
).reshape(output["projection_shape"])
print("\n--- Results ---")
print(f"Duration: {output['duration']:.1f} seconds")
print(f"Latents: {latents.shape} (num_points x 64)")
if projection is not None:
print(f"Projection: {projection.shape} (num_points x 3)")
print(f"Amplitudes: {len(output['amplitudes'])} values")
print("\nSuccess! Endpoint is working.")
if __name__ == "__main__":
if len(sys.argv) < 2:
print("Usage: python test_endpoint.py <audio_file>")
print("\nExample:")
print(" python test_endpoint.py song.mp3")
sys.exit(1)
test_endpoint(sys.argv[1])