Skip to content
Open
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
1 change: 1 addition & 0 deletions packages/tasks/src/library-to-tasks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ export const LIBRARY_TASK_MAPPING: Partial<Record<ModelLibraryKey, PipelineType[
"image-segmentation",
"image-to-image",
"image-to-text",
"image-text-to-text",
"object-detection",
"question-answering",
"summarization",
Expand Down
21 changes: 19 additions & 2 deletions packages/tasks/src/model-libraries-snippets.ts
Original file line number Diff line number Diff line change
Expand Up @@ -849,11 +849,28 @@ export const transformers = (model: ModelData): string[] => {
const pipelineSnippet = ["# Use a pipeline as a high-level helper", "from transformers import pipeline", ""];

if (model.tags.includes("conversational") && model.config?.tokenizer_config?.chat_template) {
pipelineSnippet.push("messages = [", ' {"role": "user", "content": "Who are you?"},', "]");
if (model.pipeline_tag === "text-generation") {
pipelineSnippet.push("messages = [", ' {"role": "user", "content": "Who are you?"},', "]\n");
} else if (model.pipeline_tag === "image-text-to-text") {
pipelineSnippet.push(
`image_ny = "https://cdn.britannica.com/61/93061-050-99147DCE/Statue-of-Liberty-Island-New-York-Bay.jpg"`,
`image_chicago = "https://cdn.britannica.com/59/94459-050-DBA42467/Skyline-Chicago.jpg"`,
Comment on lines +856 to +857
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The example is super nice, but not all image-text-to-text models support multiple images reliably. I'd go for a simpler single-image example for now.

"\n"
);
}
}
pipelineSnippet.push(`pipe = pipeline("${model.pipeline_tag}", model="${model.id}"` + remote_code_snippet + ")");
if (model.tags.includes("conversational") && model.config?.tokenizer_config?.chat_template) {
pipelineSnippet.push("pipe(messages)");
if (model.pipeline_tag === "text-generation") {
pipelineSnippet.push("pipe(messages)");
} else if (model.pipeline_tag === "image-text-to-text") {
pipelineSnippet.push(
"pipe(",
" images=[image_ny, image_chicago],",
` text="<image> <image> Are these the same cities? If not what cities are these?",`,
")\n"
);
}
}

return [pipelineSnippet.join("\n"), autoSnippet];
Expand Down
Loading