-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_api.py
116 lines (95 loc) · 3.61 KB
/
test_api.py
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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
from udio_api_wrapper import UdioApiClient
import os
import sys
def test_music_generation(token):
"""Test the music generation API with Rise & Run lyrics"""
client = UdioApiClient(token)
# Print API details for debugging
print(f"\nAPI Base URL: {client.API_BASE_URL}")
print(f"Using token: {token[:8]}...{token[-4:]}\n")
try:
# Generate the Rise & Run theme
print("Generating Rise & Run theme...")
lyrics = """[Verse]
In a world of care, where dreams align,
There's a force that stands the test of time.
Rise & Run, with hearts so true,
Building bridges, bringing life anew.
Every story, every smile,
They go the extra mile.
Lighting the way, like the morning sun,
That's the power of Rise & Run.
[Verse 2]
From the first hello to the last goodbye,
They lift the weary, help dreams fly high.
Compassion burns in all they do,
A guiding light that pulls us through.
Marketing more than just a brand,
They touch the soul, they understand.
It's not just work; it's a calling begun,
A legacy of care at Rise & Run.
[Chorus]
Rise & Run, together we thrive,
Changing the world, keeping hope alive.
With every heartbeat, every call,
They lift us higher, they catch us all.
Rise & Run, oh, they're second to none,
Healing the world, one step, one run.
[Verse 3]
Oh, they rise for the broken,
Run for the lost,
Building a future, no matter the cost.
They lift the heavy, embrace the small,
In their hands, there's room for all.
[Bridge]
So here's to the dreamers, the doers of love,
Guided by something from far above.
Rise & Run, your journey's begun,
Together, we're stronger—together, we've won.
[Chorus]
Rise & Run, together we thrive,
Changing the world, keeping hope alive.
With every heartbeat, every call,
They lift us higher, they catch us all.
Rise & Run, oh, they're second to none,
Healing the world, one step, one run."""
result = client.generate_music(
prompt=lyrics,
title="Rise & Run Theme",
model="chirp-v3.5", # Using the latest model for better quality
make_instrumental=False # We want vocals for the lyrics
)
work_id = result.get('workId')
if not work_id:
print("Error: No work ID received")
return
print(f"Generation started with work ID: {work_id}")
print("Waiting for completion (this may take a few minutes)...")
# Wait for the generation to complete
final_result = client.wait_for_completion(work_id)
# Print the results
print("\nGeneration completed!")
print("Generated tracks:")
for track in final_result.get('response_data', []):
print(f"\nTitle: {track.get('title')}")
print(f"Audio URL: {track.get('audio_url')}")
print(f"Tags: {track.get('tags')}")
if track.get('error_message'):
print(f"Error: {track.get('error_message')}")
except Exception as e:
print(f"\nError Details:")
print(f"Type: {type(e).__name__}")
print(f"Message: {str(e)}")
if hasattr(e, '__cause__') and e.__cause__:
print(f"Cause: {str(e.__cause__)}")
if __name__ == "__main__":
# Get token from command line argument or environment variable
token = None
if len(sys.argv) > 1:
token = sys.argv[1]
else:
token = os.getenv("UDIO_API_TOKEN")
if not token:
print("Please provide your API token as a command line argument or set the UDIO_API_TOKEN environment variable")
sys.exit(1)
test_music_generation(token)