Skip to content

Generating Videos From Generated Images with Moderation

Project Setup

Terminal window
# Create a project directory.
mkdir prodia-video-generation-from-generated-images
cd prodia-video-generation-from-generated-images

Install Node (if not already installed):

Terminal window
brew install node
# Close the current terminal and open a new one so that node is available.

Create project skeleton:

Terminal window
# Requires node --version >= 18
# Initialize the project with npm.
npm init -y
# Install the prodia-js library.
npm install prodia --save
Terminal window
# Export your token so it can be used by the main code.
export PRODIA_TOKEN=your-token-here

Create a main file for your project:

main.js
const { createProdia } = require("prodia/v2");
const prodia = createProdia({
token: process.env.PRODIA_TOKEN // get it from environment
});

You’re now ready to make some API calls!

Generate an image (inside a workflow)

main.js
const { createProdia } = require("prodia/v2");
const fs = require("node:fs/promises"); // add this to imports at the top
const prodia = createProdia({
token: process.env.PRODIA_TOKEN, // get it from environment
});
(async () => {
const job = await prodia.job({
type: "workflow.serial.v1",
config: {
jobs: [
{
type: "inference.flux.schnell.txt2img.v1",
config: {
prompt: "puppies in a cloud, 4k",
},
},
],
},
});
const image = await job.arrayBuffer();
await fs.writeFile("puppies.jpg", new Uint8Array(image));
// open puppies.jpg
})();
Terminal window
node main.js
Terminal window
open puppies.jpg

Adding content moderation

main.js
const { createProdia } = require("prodia/v2");
const fs = require("node:fs/promises"); // add this to imports at the top
const prodia = createProdia({
token: process.env.PRODIA_TOKEN, // get it from environment
});
(async () => {
const job = await prodia.job({
type: "workflow.serial.v1",
config: {
jobs: [
{
type: "inference.flux.schnell.txt2img.v1",
config: {
prompt: "puppies in a cloud, 4k",
},
},
{
type: "workflow.moderate.v1",
config: {
threshold: 0.95,
},
},
],
},
});
const image = await job.arrayBuffer();
await fs.writeFile("puppies.jpg", new Uint8Array(image));
// open puppies.jpg
})();
Terminal window
node main.js
Terminal window
open puppies.jpg

Generate video

main.js
const { createProdia } = require("prodia/v2");
const fs = require("node:fs/promises"); // add this to imports at the top
const prodia = createProdia({
token: process.env.PRODIA_TOKEN, // get it from environment
});
(async () => {
const job = await prodia.job({
type: "workflow.serial.v1",
config: {
jobs: [
{
type: "inference.flux.schnell.txt2img.v1",
config: {
prompt: "puppies in a cloud, 4k",
},
},
{
type: "workflow.moderate.v1",
config: {
threshold: 0.95,
},
},
{
type: "inference.kling.img2vid.v1",
config: {
prompt: "puppies playing in the clouds",
},
},
],
},
});
const video = await job.arrayBuffer();
await fs.writeFile("puppies.mp4", new Uint8Array(video));
// open puppies.mp4
})();
Terminal window
node main.js
Terminal window
open puppies.mp4