import sys
import requests
import time
base_url = "https://api.verbalia.net"
headers = {"X-API-Key": "<api_key>"}
files = {
'file': ('ref_video.mp4', open('ref_video.mp4', 'rb'), 'video/mp4')
}
data = {
'resource_name': 'workshop-facecam',
'resource_type': 'video'
}
video_upload_response = requests.post(
base_url + "/resources/upload",
files=files,
params=data,
headers=headers
)
if video_upload_response.status_code != 200:
print(f'Failed to upload file. Status code: {video_upload_response.status_code}')
print('Response:', video_upload_response.text)
sys.exit(1)
print('Upload successful', video_upload_response.json())
body = {
"avatar": {
"name": "adam",
},
"script": {
"resource_id": video_upload_response.json()['resource_id'],
"type": "video"
},
}
generation_response = requests.post(
base_url + "/generate-video",
json=body,
headers=headers
)
if generation_response.status_code != 200:
print(f'Failed to generate video. Status code: {generation_response.status_code}')
print('Response:', generation_response.text)
sys.exit(1)
print('Generation successful.', generation_response.json())
while True:
time.sleep(60)
response = requests.get(
base_url + "/status/" + generation_response.json()["request_id"],
headers=headers
)
print(response.json())
if response.json()["status"] in ["completed", "failed"]:
break
if response.json()["status"] == "completed":
video_response = requests.get(response.json()["video_url"])
with open(f"verbalia_video.mp4", "wb") as f:
f.write(video_response.content)