Skip to content

Commit 0193e6b

Browse files
authored
Add text to video snippets (#1240)
There is probably some missing snippets, I added these based on our docs. Feel free to update if something's missing Needed for huggingface-internal/moon-landing#12722
1 parent 6638151 commit 0193e6b

File tree

9 files changed

+109
-1
lines changed

9 files changed

+109
-1
lines changed

packages/tasks-gen/scripts/generate-snippets-fixtures.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,17 @@ const TEST_CASES: {
9090
providers: ["hf-inference", "fal-ai"],
9191
languages: ["sh", "js", "py"],
9292
},
93+
{
94+
testName: "text-to-video",
95+
model: {
96+
id: "tencent/HunyuanVideo",
97+
pipeline_tag: "text-to-video",
98+
tags: [],
99+
inference: "",
100+
},
101+
providers: ["replicate", "fal-ai"],
102+
languages: ["js", "py"],
103+
},
93104
{
94105
testName: "text-classification",
95106
model: {
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import { HfInference } from "@huggingface/inference";
2+
3+
const client = new HfInference("api_token");
4+
5+
const video = await client.textToVideo({
6+
model: "tencent/HunyuanVideo",
7+
provider: "fal-ai",
8+
inputs: "A young man walking on the street",
9+
parameters: { num_inference_steps: 5 },
10+
});
11+
// Use the generated video (it's a Blob)
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import { HfInference } from "@huggingface/inference";
2+
3+
const client = new HfInference("api_token");
4+
5+
const video = await client.textToVideo({
6+
model: "tencent/HunyuanVideo",
7+
provider: "replicate",
8+
inputs: "A young man walking on the street",
9+
parameters: { num_inference_steps: 5 },
10+
});
11+
// Use the generated video (it's a Blob)
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
from huggingface_hub import InferenceClient
2+
3+
client = InferenceClient(
4+
provider="fal-ai",
5+
api_key="api_token"
6+
)
7+
8+
video = client.text_to_video(
9+
"A young man walking on the street",
10+
model="tencent/HunyuanVideo"
11+
)
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
from huggingface_hub import InferenceClient
2+
3+
client = InferenceClient(
4+
provider="replicate",
5+
api_key="api_token"
6+
)
7+
8+
video = client.text_to_video(
9+
"A young man walking on the street",
10+
model="tencent/HunyuanVideo"
11+
)

packages/tasks/src/snippets/inputs.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,8 @@ const inputsAudioClassification = () => `"sample1.flac"`;
9696

9797
const inputsTextToImage = () => `"Astronaut riding a horse"`;
9898

99+
const inputsTextToVideo = () => `"A young man walking on the street"`;
100+
99101
const inputsTextToSpeech = () => `"The answer to the universe is 42"`;
100102

101103
const inputsTextToAudio = () => `"liquid drum and bass, atmospheric synths, airy sounds"`;
@@ -130,6 +132,7 @@ const modelInputSnippets: {
130132
"text-generation": inputsTextGeneration,
131133
"image-text-to-text": inputsTextGeneration,
132134
"text-to-image": inputsTextToImage,
135+
"text-to-video": inputsTextToVideo,
133136
"text-to-speech": inputsTextToSpeech,
134137
"text-to-audio": inputsTextToAudio,
135138
"text2text-generation": inputsText2TextGeneration,

packages/tasks/src/snippets/js.ts

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -275,6 +275,33 @@ query({"inputs": ${getModelInputSnippet(model)}}).then((response) => {
275275
];
276276
};
277277

278+
export const snippetTextToVideo = (
279+
model: ModelDataMinimal,
280+
accessToken: string,
281+
provider: SnippetInferenceProvider
282+
): InferenceSnippet[] => {
283+
return ["fal-ai", "replicate"].includes(provider)
284+
? [
285+
{
286+
client: "huggingface.js",
287+
content: `\
288+
import { HfInference } from "@huggingface/inference";
289+
290+
const client = new HfInference("${accessToken || `{API_TOKEN}`}");
291+
292+
const video = await client.textToVideo({
293+
model: "${model.id}",
294+
provider: "${provider}",
295+
inputs: ${getModelInputSnippet(model)},
296+
parameters: { num_inference_steps: 5 },
297+
});
298+
// Use the generated video (it's a Blob)
299+
`,
300+
},
301+
]
302+
: [];
303+
};
304+
278305
export const snippetTextToAudio = (
279306
model: ModelDataMinimal,
280307
accessToken: string,
@@ -420,6 +447,7 @@ export const jsSnippets: Partial<
420447
"sentence-similarity": snippetBasic,
421448
"automatic-speech-recognition": snippetAutomaticSpeechRecognition,
422449
"text-to-image": snippetTextToImage,
450+
"text-to-video": snippetTextToVideo,
423451
"text-to-speech": snippetTextToAudio,
424452
"text-to-audio": snippetTextToAudio,
425453
"audio-to-audio": snippetFile,

packages/tasks/src/snippets/python.ts

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -308,6 +308,27 @@ image = Image.open(io.BytesIO(image_bytes))`,
308308
];
309309
};
310310

311+
export const snippetTextToVideo = (
312+
model: ModelDataMinimal,
313+
accessToken: string,
314+
provider: SnippetInferenceProvider
315+
): InferenceSnippet[] => {
316+
return ["fal-ai", "replicate"].includes(provider)
317+
? [
318+
{
319+
client: "huggingface_hub",
320+
content: `\
321+
${snippetImportInferenceClient(accessToken, provider)}
322+
323+
video = client.text_to_video(
324+
${getModelInputSnippet(model)},
325+
model="${model.id}"
326+
)`,
327+
},
328+
]
329+
: [];
330+
};
331+
311332
export const snippetTabular = (model: ModelDataMinimal): InferenceSnippet[] => {
312333
return [
313334
{
@@ -412,6 +433,7 @@ export const pythonSnippets: Partial<
412433
"sentence-similarity": snippetBasic,
413434
"automatic-speech-recognition": snippetFile,
414435
"text-to-image": snippetTextToImage,
436+
"text-to-video": snippetTextToVideo,
415437
"text-to-speech": snippetTextToAudio,
416438
"text-to-audio": snippetTextToAudio,
417439
"audio-to-audio": snippetFile,

packages/tasks/src/tasks/text-to-video/data.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ const taskData: TaskDataCustom = {
9999
],
100100
summary:
101101
"Text-to-video models can be used in any application that requires generating consistent sequence of images from text. ",
102-
widgetModels: [],
102+
widgetModels: ["tencent/HunyuanVideo"],
103103
youtubeId: undefined,
104104
};
105105

0 commit comments

Comments
 (0)