Skip to content

Commit 2e5caaf

Browse files
author
multimodalart
committed
Apply review comments
1 parent 324e720 commit 2e5caaf

File tree

2 files changed

+7
-14
lines changed

2 files changed

+7
-14
lines changed

packages/tasks/src/model-data.ts

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -107,12 +107,6 @@ export interface ModelData {
107107
parameters?: Record<string, unknown>;
108108
};
109109
base_model?: string | string[];
110-
widget?: Array<{
111-
text: string;
112-
output?: {
113-
url: string;
114-
};
115-
}>;
116110
instance_prompt?: string;
117111
};
118112
/**

packages/tasks/src/model-libraries-snippets.ts

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import type { ModelData } from "./model-data";
2+
import type { WidgetExampleTextInput } from "./widget-example";
23
import { LIBRARY_TASK_MAPPING } from "./library-to-tasks";
34

45
const 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

8178
export 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+
140139
const diffusers_default = (model: ModelData) => [
141140
`from diffusers import DiffusionPipeline
142141
143142
pipe = 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}"
146145
image = pipe(prompt).images[0]`,
147146
];
148147

@@ -161,7 +160,7 @@ const diffusers_lora = (model: ModelData) => [
161160
pipe = DiffusionPipeline.from_pretrained("${get_base_diffusers_model(model)}")
162161
pipe.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}"
165164
image = pipe(prompt).images[0]`,
166165
];
167166

0 commit comments

Comments
 (0)