Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions packages/tasks-gen/scripts/generate-snippets-fixtures.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,17 @@ const TEST_CASES: {
providers: ["hf-inference", "fal-ai"],
languages: ["sh", "js", "py"],
},
{
testName: "text-to-video",
model: {
id: "tencent/HunyuanVideo",
pipeline_tag: "text-to-video",
tags: [],
inference: "",
},
providers: ["replicate", "fal-ai"],
languages: ["js", "py"],
},
{
testName: "text-classification",
model: {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { HfInference } from "@huggingface/inference";

const client = new HfInference("api_token");

const video = await client.textToVideo({
model: "tencent/HunyuanVideo",
provider: "fal-ai",
inputs: "A young man walking on the street",
parameters: { num_inference_steps: 5 },
});
// Use the generated video (it's a Blob)
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { HfInference } from "@huggingface/inference";

const client = new HfInference("api_token");

const video = await client.textToVideo({
model: "tencent/HunyuanVideo",
provider: "replicate",
inputs: "A young man walking on the street",
parameters: { num_inference_steps: 5 },
});
// Use the generated video (it's a Blob)
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
from huggingface_hub import InferenceClient

client = InferenceClient(
provider="fal-ai",
api_key="api_token"
)

video = client.text_to_video(
"A young man walking on the street",
model="tencent/HunyuanVideo"
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
from huggingface_hub import InferenceClient

client = InferenceClient(
provider="replicate",
api_key="api_token"
)

video = client.text_to_video(
"A young man walking on the street",
model="tencent/HunyuanVideo"
)
3 changes: 3 additions & 0 deletions packages/tasks/src/snippets/inputs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,8 @@ const inputsAudioClassification = () => `"sample1.flac"`;

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

const inputsTextToVideo = () => `"A young man walking on the street"`;

const inputsTextToSpeech = () => `"The answer to the universe is 42"`;

const inputsTextToAudio = () => `"liquid drum and bass, atmospheric synths, airy sounds"`;
Expand Down Expand Up @@ -130,6 +132,7 @@ const modelInputSnippets: {
"text-generation": inputsTextGeneration,
"image-text-to-text": inputsTextGeneration,
"text-to-image": inputsTextToImage,
"text-to-video": inputsTextToVideo,
"text-to-speech": inputsTextToSpeech,
"text-to-audio": inputsTextToAudio,
"text2text-generation": inputsText2TextGeneration,
Expand Down
28 changes: 28 additions & 0 deletions packages/tasks/src/snippets/js.ts
Original file line number Diff line number Diff line change
Expand Up @@ -275,6 +275,33 @@ query({"inputs": ${getModelInputSnippet(model)}}).then((response) => {
];
};

export const snippetTextToVideo = (
model: ModelDataMinimal,
accessToken: string,
provider: SnippetInferenceProvider
): InferenceSnippet[] => {
return ["fal-ai", "replicate"].includes(provider)
? [
{
client: "huggingface.js",
content: `\
import { HfInference } from "@huggingface/inference";

const client = new HfInference("${accessToken || `{API_TOKEN}`}");

const video = await client.textToVideo({
model: "${model.id}",
provider: "${provider}",
inputs: ${getModelInputSnippet(model)},
parameters: { num_inference_steps: 5 },
});
// Use the generated video (it's a Blob)
`,
},
]
: [];
};

export const snippetTextToAudio = (
model: ModelDataMinimal,
accessToken: string,
Expand Down Expand Up @@ -420,6 +447,7 @@ export const jsSnippets: Partial<
"sentence-similarity": snippetBasic,
"automatic-speech-recognition": snippetAutomaticSpeechRecognition,
"text-to-image": snippetTextToImage,
"text-to-video": snippetTextToVideo,
"text-to-speech": snippetTextToAudio,
"text-to-audio": snippetTextToAudio,
"audio-to-audio": snippetFile,
Expand Down
22 changes: 22 additions & 0 deletions packages/tasks/src/snippets/python.ts
Original file line number Diff line number Diff line change
Expand Up @@ -308,6 +308,27 @@ image = Image.open(io.BytesIO(image_bytes))`,
];
};

export const snippetTextToVideo = (
model: ModelDataMinimal,
accessToken: string,
provider: SnippetInferenceProvider
): InferenceSnippet[] => {
return ["fal-ai", "replicate"].includes(provider)
? [
{
client: "huggingface_hub",
content: `\
${snippetImportInferenceClient(accessToken, provider)}

video = client.text_to_video(
${getModelInputSnippet(model)},
model="${model.id}"
)`,
},
]
: [];
};

export const snippetTabular = (model: ModelDataMinimal): InferenceSnippet[] => {
return [
{
Expand Down Expand Up @@ -412,6 +433,7 @@ export const pythonSnippets: Partial<
"sentence-similarity": snippetBasic,
"automatic-speech-recognition": snippetFile,
"text-to-image": snippetTextToImage,
"text-to-video": snippetTextToVideo,
"text-to-speech": snippetTextToAudio,
"text-to-audio": snippetTextToAudio,
"audio-to-audio": snippetFile,
Expand Down
2 changes: 1 addition & 1 deletion packages/tasks/src/tasks/text-to-video/data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ const taskData: TaskDataCustom = {
],
summary:
"Text-to-video models can be used in any application that requires generating consistent sequence of images from text. ",
widgetModels: [],
widgetModels: ["tencent/HunyuanVideo"],
youtubeId: undefined,
};

Expand Down
Loading