11import type { ModelData } from "./model-data" ;
2+ import type { WidgetExampleTextInput } from "./widget-example" ;
23import { LIBRARY_TASK_MAPPING } from "./library-to-tasks" ;
34
45const TAG_CUSTOM_CODE = "custom_code" ;
@@ -70,12 +71,8 @@ function get_base_diffusers_model(model: ModelData): string {
7071 return model . cardData ?. base_model ?. toString ( ) ?? "fill-in-base-model" ;
7172}
7273
73- function get_prompt_from_diffusers_model ( model : ModelData ) : string {
74- return (
75- model . cardData ?. widget ?. [ 0 ] ?. text ?. toString ( ) ??
76- model . cardData ?. instance_prompt ?. toString ( ) ??
77- "Astronaut in a jungle, cold color palette, muted colors, detailed, 8k"
78- ) ;
74+ function get_prompt_from_diffusers_model ( model : ModelData ) : string | undefined {
75+ return ( model . widgetData ?. [ 0 ] as WidgetExampleTextInput ) . text ?? model . cardData ?. instance_prompt ?? undefined ;
7976}
8077
8178export const bertopic = ( model : ModelData ) : string [ ] => [
@@ -137,12 +134,14 @@ depth = model.infer_image(raw_img) # HxW raw depth map in numpy
137134 ] ;
138135} ;
139136
137+ const diffusers_default_prompt = "Astronaut in a jungle, cold color palette, muted colors, detailed, 8k" ;
138+
140139const diffusers_default = ( model : ModelData ) => [
141140 `from diffusers import DiffusionPipeline
142141
143142pipe = DiffusionPipeline.from_pretrained("${ model . id } ")
144143
145- prompt = "${ get_prompt_from_diffusers_model ( model ) } "
144+ prompt = "${ get_prompt_from_diffusers_model ( model ) ?? diffusers_default_prompt } "
146145image = pipe(prompt).images[0]` ,
147146] ;
148147
@@ -161,7 +160,7 @@ const diffusers_lora = (model: ModelData) => [
161160pipe = DiffusionPipeline.from_pretrained("${ get_base_diffusers_model ( model ) } ")
162161pipe.load_lora_weights("${ model . id } ")
163162
164- prompt = "${ get_prompt_from_diffusers_model ( model ) } "
163+ prompt = "${ get_prompt_from_diffusers_model ( model ) ?? diffusers_default_prompt } "
165164image = pipe(prompt).images[0]` ,
166165] ;
167166
0 commit comments