@@ -1142,13 +1142,31 @@ export const transformers = (model: ModelData): string[] => {
1142
1142
}
1143
1143
1144
1144
if ( model . pipeline_tag && LIBRARY_TASK_MAPPING . transformers ?. includes ( model . pipeline_tag ) ) {
1145
- const pipelineSnippet = [ "# Use a pipeline as a high-level helper" , "from transformers import pipeline" , "" ] ;
1145
+ const pipelineSnippet = [
1146
+ "# Use a pipeline as a high-level helper" ,
1147
+ "from transformers import pipeline" ,
1148
+ "" ,
1149
+ `pipe = pipeline("${ model . pipeline_tag } ", model="${ model . id } "` + remote_code_snippet + ")" ,
1150
+ ] ;
1146
1151
1147
- if ( model . tags . includes ( "conversational" ) && model . config ?. tokenizer_config ?. chat_template ) {
1148
- pipelineSnippet . push ( "messages = [" , ' {"role": "user", "content": "Who are you?"},' , "]" ) ;
1149
- }
1150
- pipelineSnippet . push ( `pipe = pipeline("${ model . pipeline_tag } ", model="${ model . id } "` + remote_code_snippet + ")" ) ;
1151
- if ( model . tags . includes ( "conversational" ) && model . config ?. tokenizer_config ?. chat_template ) {
1152
+ if ( model . tags . includes ( "conversational" ) ) {
1153
+ if ( model . tags . includes ( "image-text-to-text" ) ) {
1154
+ pipelineSnippet . push (
1155
+ "messages = [" ,
1156
+ [
1157
+ " {" ,
1158
+ ' "role": "user",' ,
1159
+ ' "content": [' ,
1160
+ ' {"type": "image", "url": "https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/p-blog/candy.JPG"},' ,
1161
+ ' {"type": "text", "text": "What animal is on the candy?"}' ,
1162
+ " ]" ,
1163
+ " }," ,
1164
+ ] . join ( "\n" ) ,
1165
+ "]"
1166
+ ) ;
1167
+ } else {
1168
+ pipelineSnippet . push ( "messages = [" , ' {"role": "user", "content": "Who are you?"},' , "]" ) ;
1169
+ }
1152
1170
pipelineSnippet . push ( "pipe(messages)" ) ;
1153
1171
}
1154
1172
0 commit comments