File size: 4,031 Bytes
a12ee00 7621093 a12ee00 7621093 a12ee00 7621093 a12ee00 7621093 a12ee00 7621093 a12ee00 7621093 3637e81 7621093 52d2c68 7621093 |
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 |
import requests
import base64
# Important: the NVIDIA L40S will only support small resolutions, short length and no post-processing.
# If you want those features, you might need to use the NVIDIA A100.
# Use your own Inference Endpoint URL
API_URL = "https://<use your own Inference Endpoint here>.endpoints.huggingface.cloud"
# Use you own API token
API_TOKEN = "hf_<replace by your own Hugging Face token>"
def query(payload):
response = requests.post(API_URL, headers={
"Accept": "application/json",
"Authorization": f"Bearer {API_TOKEN}",
"Content-Type": "application/json"
}, json=payload)
return response.json()
def save_video(json_response):
video_data_uri = ""
try:
# Extract the video data URI from the response
video_data_uri = json_response["video"]
except Exception as e:
message = str(json_response)
print(message)
raise ValueError(message)
# Remove the data URI prefix to get just the base64 data
# Assumes format like "data:video/mp4;base64,<actual_base64_data>"
base64_data = video_data_uri.split(",")[1]
# Decode the base64 data
video_data = base64.b64decode(base64_data)
# Write the binary data to an MP4 file
with open("video.mp4", "wb") as f:
f.write(video_data)
# Make the API call
output = query({
"inputs": {
"prompt": "Portrait photo, selfie of a beautiful young caucasian woman called Charlotte, wearing a pastel-blue hoodie. She is livestreaming from NYC streets. She looks straight into the camera, looking serious, and she talks. The camera is fixed, static, a medium-shot centered on her face. 4K webcam footage. Intricate details, super resolution, sharp image, award winning."
},
"parameters": {
# ------------------- settings for LTX-Video -----------------------
# for a vertical video look
"width": 480,
"height": 768,
# LTX-Video requires a frame number divisible by 8, plus one frame
# note: glitches might appear if you use more than 168 frames
"num_frames": (8 * 14) + 1,
# using 30 steps seems to be enough for most cases, otherwise use 50 for best quality
# I think using a large number of steps (> 30) might create some overexposure and saturation
"num_inference_steps": 40,
# values between 3.0 and 4.0 are nice
"guidance_scale": 3.5,
# seed: -1,
# ------------------- settings for Varnish -----------------------
# This will double the number of frames.
# You can activate this if you want:
# - a slow motion effect (in that case use double_num_frames=True and fps=24, 25 or 30)
# - a HD soap / video game effect (in that case use double_num_frames=True and fps=60)
"double_num_frames": True,
# controls the number of frames per second
# use this in combination with the num_frames and double_num_frames settings to control the duration and "feel" of your video
"fps": 60, # typical values are: 24, 25, 30, 60
# upscale the video using Real-ESRGAN.
# This upscaling algorithm is relatively fast,
# but might create an uncanny "3D render" or "drawing" effect.
"super_resolution": True,
# for cosmetic purposes and get a "cinematic" feel, you can optionally add some film grain.
# it is not recommended to add film grain if your theme doesn't match (film grain is great for black & white, retro looks)
# and if you do, adding more than 12% will start to negatively impact file size (video codecs aren't great are compressing film grain)
# 0% = no grain
# 10% = a bit of grain
"grain_amount": 10, # value between 0-100
# the following parameters are a work in progress
"enable_audio": False,
#"audio_prompt": "voices, voice, talking, speaking, speech",
#"audio_negative_prompt": "",
}
})
# Save the video
save_video(output) |