How to parse base64 output
Decode and save model output
Text-to-image and text-to-audio models like Stable Diffusion XL and MusicGen return the image or audio they create as base64-encoded strings, which then need to be parsed and saved as files. This guide provides examples for working with base64 output from these models.
Example: Parsing Stable Diffusion output into a file
To follow this example, deploy Stable Diffusion XL from the model library.
Python invocation
In this example, we’ll use a Python script to call the model and parse the response.
Truss CLI invocation
You can also use the Truss CLI and pipe the results into a similar Python script.
Command line:
Script:
Example: Parsing MusicGen output into multiple files
To follow this example, deploy MusicGen from the model library.
Python invocation
In this example, we’ll use a Python script to call the model and parse the response.
Truss CLI invocation
You can also use the Truss CLI and pipe the results into a similar Python script.
Command line:
Script: