1
1
import type { ModelData } from "./model-data" ;
2
+ import type { WidgetExampleTextInput } from "./widget-example" ;
2
3
import { LIBRARY_TASK_MAPPING } from "./library-to-tasks" ;
3
4
4
5
const TAG_CUSTOM_CODE = "custom_code" ;
@@ -8,6 +9,8 @@ function nameWithoutNamespace(modelId: string): string {
8
9
return splitted . length === 1 ? splitted [ 0 ] : splitted [ 1 ] ;
9
10
}
10
11
12
+ const escapeStringForJson = ( str : string ) : string => JSON . stringify ( str ) ;
13
+
11
14
//#region snippets
12
15
13
16
export const adapters = ( model : ModelData ) : string [ ] => [
@@ -70,6 +73,13 @@ function get_base_diffusers_model(model: ModelData): string {
70
73
return model . cardData ?. base_model ?. toString ( ) ?? "fill-in-base-model" ;
71
74
}
72
75
76
+ function get_prompt_from_diffusers_model ( model : ModelData ) : string | undefined {
77
+ const prompt = ( model . widgetData ?. [ 0 ] as WidgetExampleTextInput ) . text ?? model . cardData ?. instance_prompt ;
78
+ if ( prompt ) {
79
+ return escapeStringForJson ( prompt ) ;
80
+ }
81
+ }
82
+
73
83
export const bertopic = ( model : ModelData ) : string [ ] => [
74
84
`from bertopic import BERTopic
75
85
@@ -129,12 +139,14 @@ depth = model.infer_image(raw_img) # HxW raw depth map in numpy
129
139
] ;
130
140
} ;
131
141
142
+ const diffusersDefaultPrompt = "Astronaut in a jungle, cold color palette, muted colors, detailed, 8k" ;
143
+
132
144
const diffusers_default = ( model : ModelData ) => [
133
145
`from diffusers import DiffusionPipeline
134
146
135
147
pipe = DiffusionPipeline.from_pretrained("${ model . id } ")
136
148
137
- prompt = "Astronaut in a jungle, cold color palette, muted colors, detailed, 8k "
149
+ prompt = "${ get_prompt_from_diffusers_model ( model ) ?? diffusersDefaultPrompt } "
138
150
image = pipe(prompt).images[0]` ,
139
151
] ;
140
152
@@ -153,7 +165,7 @@ const diffusers_lora = (model: ModelData) => [
153
165
pipe = DiffusionPipeline.from_pretrained("${ get_base_diffusers_model ( model ) } ")
154
166
pipe.load_lora_weights("${ model . id } ")
155
167
156
- prompt = "Astronaut in a jungle, cold color palette, muted colors, detailed, 8k "
168
+ prompt = "${ get_prompt_from_diffusers_model ( model ) ?? diffusersDefaultPrompt } "
157
169
image = pipe(prompt).images[0]` ,
158
170
] ;
159
171
0 commit comments