@taskmagic/apps-hugging-face 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +3 -0
- package/package.json +47 -0
- package/src/index.d.ts +1 -0
- package/src/index.js +64 -0
- package/src/index.js.map +1 -0
- package/src/lib/actions/chat-completion.d.ts +18 -0
- package/src/lib/actions/chat-completion.js +537 -0
- package/src/lib/actions/chat-completion.js.map +1 -0
- package/src/lib/actions/create-image.d.ts +14 -0
- package/src/lib/actions/create-image.js +423 -0
- package/src/lib/actions/create-image.js.map +1 -0
- package/src/lib/actions/document-question-answering.d.ts +11 -0
- package/src/lib/actions/document-question-answering.js +140 -0
- package/src/lib/actions/document-question-answering.js.map +1 -0
- package/src/lib/actions/image-classification.d.ts +13 -0
- package/src/lib/actions/image-classification.js +592 -0
- package/src/lib/actions/image-classification.js.map +1 -0
- package/src/lib/actions/language-translation.d.ts +11 -0
- package/src/lib/actions/language-translation.js +222 -0
- package/src/lib/actions/language-translation.js.map +1 -0
- package/src/lib/actions/object-detection.d.ts +9 -0
- package/src/lib/actions/object-detection.js +464 -0
- package/src/lib/actions/object-detection.js.map +1 -0
- package/src/lib/actions/text-classification.d.ts +12 -0
- package/src/lib/actions/text-classification.js +344 -0
- package/src/lib/actions/text-classification.js.map +1 -0
- package/src/lib/actions/text-summarization.d.ts +12 -0
- package/src/lib/actions/text-summarization.js +420 -0
- package/src/lib/actions/text-summarization.js.map +1 -0
- package/src/lib/auth.d.ts +1 -0
- package/src/lib/auth.js +10 -0
- package/src/lib/auth.js.map +1 -0
- package/src/lib/common/index.d.ts +36 -0
- package/src/lib/common/index.js +78 -0
- package/src/lib/common/index.js.map +1 -0
|
@@ -0,0 +1,423 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.createImage = void 0;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
const pieces_framework_1 = require("@taskmagic/pieces-framework");
|
|
6
|
+
const pieces_common_1 = require("@taskmagic/pieces-common");
|
|
7
|
+
const auth_1 = require("../auth");
|
|
8
|
+
const common_1 = require("../common");
|
|
9
|
+
exports.createImage = (0, pieces_framework_1.createAction)({
|
|
10
|
+
name: 'create_image',
|
|
11
|
+
auth: auth_1.huggingFaceAuth,
|
|
12
|
+
displayName: 'Create Image',
|
|
13
|
+
description: 'Generate stunning images from text prompts using state-of-the-art diffusion models - perfect for marketing, product design, and creative content',
|
|
14
|
+
props: {
|
|
15
|
+
useCase: pieces_framework_1.Property.StaticDropdown({
|
|
16
|
+
displayName: 'Use Case',
|
|
17
|
+
description: 'What type of image generation do you need?',
|
|
18
|
+
required: true,
|
|
19
|
+
options: {
|
|
20
|
+
disabled: false,
|
|
21
|
+
options: [
|
|
22
|
+
{
|
|
23
|
+
label: 'Fast Generation (Quick Prototypes)',
|
|
24
|
+
value: 'speed',
|
|
25
|
+
},
|
|
26
|
+
{
|
|
27
|
+
label: 'High Quality (Marketing & Print)',
|
|
28
|
+
value: 'quality',
|
|
29
|
+
},
|
|
30
|
+
{
|
|
31
|
+
label: 'Business Content (Products & Brands)',
|
|
32
|
+
value: 'business',
|
|
33
|
+
},
|
|
34
|
+
{
|
|
35
|
+
label: 'Search All Models',
|
|
36
|
+
value: 'search',
|
|
37
|
+
},
|
|
38
|
+
],
|
|
39
|
+
},
|
|
40
|
+
defaultValue: 'quality',
|
|
41
|
+
}),
|
|
42
|
+
model: pieces_framework_1.Property.Dropdown({
|
|
43
|
+
displayName: 'Image Generation Model',
|
|
44
|
+
description: 'Select the best model for your use case',
|
|
45
|
+
required: true,
|
|
46
|
+
refreshers: ['useCase'],
|
|
47
|
+
options: (_a) => tslib_1.__awaiter(void 0, [_a], void 0, function* ({ useCase }) {
|
|
48
|
+
const getModelsByUseCase = (type) => {
|
|
49
|
+
switch (type) {
|
|
50
|
+
case 'speed':
|
|
51
|
+
return [
|
|
52
|
+
{
|
|
53
|
+
label: 'FLUX.1 Schnell (⚡ Ultra Fast - 1-4 steps)',
|
|
54
|
+
value: 'black-forest-labs/FLUX.1-schnell',
|
|
55
|
+
description: '634K downloads | Best for rapid prototyping',
|
|
56
|
+
},
|
|
57
|
+
{
|
|
58
|
+
label: 'SD Turbo (⚡ Real-time - 1 step)',
|
|
59
|
+
value: 'stabilityai/sd-turbo',
|
|
60
|
+
description: '1.2M downloads | Fastest generation',
|
|
61
|
+
},
|
|
62
|
+
{
|
|
63
|
+
label: 'SDXL Turbo (⚡ Fast - 1-4 steps)',
|
|
64
|
+
value: 'stabilityai/sdxl-turbo',
|
|
65
|
+
description: '223K downloads | Fast with good quality',
|
|
66
|
+
},
|
|
67
|
+
];
|
|
68
|
+
case 'quality':
|
|
69
|
+
return [
|
|
70
|
+
{
|
|
71
|
+
label: 'FLUX.1 Dev (Premium Quality)',
|
|
72
|
+
value: 'black-forest-labs/FLUX.1-dev',
|
|
73
|
+
description: '1.4M downloads | State-of-the-art results',
|
|
74
|
+
},
|
|
75
|
+
{
|
|
76
|
+
label: 'Stable Diffusion XL (🎯 Reliable Quality)',
|
|
77
|
+
value: 'stabilityai/stable-diffusion-xl-base-1.0',
|
|
78
|
+
description: '2.2M downloads | Industry standard',
|
|
79
|
+
},
|
|
80
|
+
{
|
|
81
|
+
label: 'SD 3 Medium (🔬 Advanced Features)',
|
|
82
|
+
value: 'stabilityai/stable-diffusion-3-medium',
|
|
83
|
+
description: '13K downloads | Latest technology',
|
|
84
|
+
},
|
|
85
|
+
];
|
|
86
|
+
case 'business':
|
|
87
|
+
return [
|
|
88
|
+
{
|
|
89
|
+
label: 'Stable Diffusion XL (💼 Professional)',
|
|
90
|
+
value: 'stabilityai/stable-diffusion-xl-base-1.0',
|
|
91
|
+
description: '2.2M downloads | Business-ready quality',
|
|
92
|
+
},
|
|
93
|
+
{
|
|
94
|
+
label: 'DreamShaper v7 (🎨 Versatile Style)',
|
|
95
|
+
value: 'Lykon/dreamshaper-7',
|
|
96
|
+
description: '833K downloads | Great for varied content',
|
|
97
|
+
},
|
|
98
|
+
{
|
|
99
|
+
label: 'OpenJourney (🌟 Midjourney Style)',
|
|
100
|
+
value: 'prompthero/openjourney',
|
|
101
|
+
description: '8K downloads | Artistic business content',
|
|
102
|
+
},
|
|
103
|
+
];
|
|
104
|
+
default:
|
|
105
|
+
return [];
|
|
106
|
+
}
|
|
107
|
+
};
|
|
108
|
+
if (useCase === 'search') {
|
|
109
|
+
try {
|
|
110
|
+
const response = yield pieces_common_1.httpClient.sendRequest({
|
|
111
|
+
method: pieces_common_1.HttpMethod.GET,
|
|
112
|
+
url: 'https://huggingface.co/api/models?pipeline_tag=text-to-image&sort=downloads&limit=50',
|
|
113
|
+
});
|
|
114
|
+
const models = response.body;
|
|
115
|
+
return {
|
|
116
|
+
disabled: false,
|
|
117
|
+
placeholder: 'Select from 50+ popular models...',
|
|
118
|
+
options: models
|
|
119
|
+
.filter((model) => model.downloads > 50000)
|
|
120
|
+
.slice(0, 20)
|
|
121
|
+
.map((model) => ({
|
|
122
|
+
label: `${model.id} (${(model.downloads / 1000).toFixed(0)}K downloads)`,
|
|
123
|
+
value: model.id,
|
|
124
|
+
})),
|
|
125
|
+
};
|
|
126
|
+
}
|
|
127
|
+
catch (error) {
|
|
128
|
+
return {
|
|
129
|
+
disabled: false,
|
|
130
|
+
options: getModelsByUseCase('quality'),
|
|
131
|
+
};
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
return {
|
|
135
|
+
disabled: false,
|
|
136
|
+
options: getModelsByUseCase(useCase),
|
|
137
|
+
};
|
|
138
|
+
}),
|
|
139
|
+
}),
|
|
140
|
+
prompt: pieces_framework_1.Property.LongText({
|
|
141
|
+
displayName: 'Text Prompt',
|
|
142
|
+
description: 'Describe the image you want to generate. Be specific about style, colors, composition, and details.',
|
|
143
|
+
required: true,
|
|
144
|
+
defaultValue: '',
|
|
145
|
+
}),
|
|
146
|
+
aspectRatio: pieces_framework_1.Property.StaticDropdown({
|
|
147
|
+
displayName: 'Aspect Ratio',
|
|
148
|
+
description: 'Choose the dimensions for your image',
|
|
149
|
+
required: false,
|
|
150
|
+
options: {
|
|
151
|
+
disabled: false,
|
|
152
|
+
options: [
|
|
153
|
+
{ label: '📱 Portrait (512×768) - Social Media', value: 'portrait' },
|
|
154
|
+
{ label: '🖥️ Landscape (768×512) - Banners', value: 'landscape' },
|
|
155
|
+
{ label: '⬜ Square (512×512) - Profile Pictures', value: 'square' },
|
|
156
|
+
{ label: '📺 Wide (1024×576) - Headers', value: 'wide' },
|
|
157
|
+
{ label: '⚙️ Custom Dimensions', value: 'custom' },
|
|
158
|
+
],
|
|
159
|
+
},
|
|
160
|
+
defaultValue: 'square',
|
|
161
|
+
}),
|
|
162
|
+
customWidth: pieces_framework_1.Property.Number({
|
|
163
|
+
displayName: 'Custom Width',
|
|
164
|
+
description: 'Width in pixels (64-1024)',
|
|
165
|
+
required: false,
|
|
166
|
+
}),
|
|
167
|
+
customHeight: pieces_framework_1.Property.Number({
|
|
168
|
+
displayName: 'Custom Height',
|
|
169
|
+
description: 'Height in pixels (64-1024)',
|
|
170
|
+
required: false,
|
|
171
|
+
}),
|
|
172
|
+
negativePrompt: pieces_framework_1.Property.LongText({
|
|
173
|
+
displayName: 'Negative Prompt',
|
|
174
|
+
description: "Describe what you DON'T want in the image (blur, low quality, distorted, etc.)",
|
|
175
|
+
required: false,
|
|
176
|
+
}),
|
|
177
|
+
qualitySettings: pieces_framework_1.Property.StaticDropdown({
|
|
178
|
+
displayName: 'Quality vs Speed',
|
|
179
|
+
description: 'Balance between image quality and generation time',
|
|
180
|
+
required: false,
|
|
181
|
+
options: {
|
|
182
|
+
disabled: false,
|
|
183
|
+
options: [
|
|
184
|
+
{ label: '⚡ Fast (10-20 steps)', value: 'fast' },
|
|
185
|
+
{ label: '⚖️ Balanced (20-30 steps)', value: 'balanced' },
|
|
186
|
+
{ label: '🎯 High Quality (30-50 steps)', value: 'quality' },
|
|
187
|
+
{ label: '🏆 Maximum Quality (50+ steps)', value: 'maximum' },
|
|
188
|
+
{ label: '⚙️ Custom Steps', value: 'custom' },
|
|
189
|
+
],
|
|
190
|
+
},
|
|
191
|
+
defaultValue: 'balanced',
|
|
192
|
+
}),
|
|
193
|
+
customSteps: pieces_framework_1.Property.Number({
|
|
194
|
+
displayName: 'Custom Inference Steps',
|
|
195
|
+
description: 'Number of denoising steps (1-100)',
|
|
196
|
+
required: false,
|
|
197
|
+
}),
|
|
198
|
+
guidanceScale: pieces_framework_1.Property.Number({
|
|
199
|
+
displayName: 'Guidance Scale',
|
|
200
|
+
description: 'How closely to follow the prompt (1-20). Higher values = more prompt adherence but may reduce creativity.',
|
|
201
|
+
required: false,
|
|
202
|
+
defaultValue: 7.5,
|
|
203
|
+
}),
|
|
204
|
+
seed: pieces_framework_1.Property.Number({
|
|
205
|
+
displayName: 'Seed (Optional)',
|
|
206
|
+
description: 'Set a seed for reproducible results. Leave empty for random generation.',
|
|
207
|
+
required: false,
|
|
208
|
+
}),
|
|
209
|
+
scheduler: pieces_framework_1.Property.StaticDropdown({
|
|
210
|
+
displayName: 'Scheduler',
|
|
211
|
+
description: 'Advanced: Choose the noise scheduler algorithm',
|
|
212
|
+
required: false,
|
|
213
|
+
options: {
|
|
214
|
+
disabled: false,
|
|
215
|
+
options: [
|
|
216
|
+
{ label: 'DPM++ 2M Karras (Recommended)', value: 'DPM++2MKarras' },
|
|
217
|
+
{ label: 'Euler A (Fast)', value: 'EulerA' },
|
|
218
|
+
{ label: 'DDIM (Stable)', value: 'DDIM' },
|
|
219
|
+
{ label: 'LMS (Classic)', value: 'LMS' },
|
|
220
|
+
],
|
|
221
|
+
},
|
|
222
|
+
}),
|
|
223
|
+
},
|
|
224
|
+
run(context) {
|
|
225
|
+
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
226
|
+
const { useCase, model, prompt, aspectRatio, customWidth, customHeight, negativePrompt, qualitySettings, customSteps, guidanceScale, seed, scheduler, } = context.propsValue;
|
|
227
|
+
if (!(prompt === null || prompt === void 0 ? void 0 : prompt.trim())) {
|
|
228
|
+
throw new Error('Please provide a text prompt for image generation');
|
|
229
|
+
}
|
|
230
|
+
let width, height;
|
|
231
|
+
switch (aspectRatio) {
|
|
232
|
+
case 'portrait':
|
|
233
|
+
width = 512;
|
|
234
|
+
height = 768;
|
|
235
|
+
break;
|
|
236
|
+
case 'landscape':
|
|
237
|
+
width = 768;
|
|
238
|
+
height = 512;
|
|
239
|
+
break;
|
|
240
|
+
case 'square':
|
|
241
|
+
width = 512;
|
|
242
|
+
height = 512;
|
|
243
|
+
break;
|
|
244
|
+
case 'wide':
|
|
245
|
+
width = 1024;
|
|
246
|
+
height = 576;
|
|
247
|
+
break;
|
|
248
|
+
case 'custom':
|
|
249
|
+
width = customWidth || 512;
|
|
250
|
+
height = customHeight || 512;
|
|
251
|
+
break;
|
|
252
|
+
default:
|
|
253
|
+
width = 512;
|
|
254
|
+
height = 512;
|
|
255
|
+
}
|
|
256
|
+
let numInferenceSteps;
|
|
257
|
+
switch (qualitySettings) {
|
|
258
|
+
case 'fast':
|
|
259
|
+
numInferenceSteps = 15;
|
|
260
|
+
break;
|
|
261
|
+
case 'balanced':
|
|
262
|
+
numInferenceSteps = 25;
|
|
263
|
+
break;
|
|
264
|
+
case 'quality':
|
|
265
|
+
numInferenceSteps = 40;
|
|
266
|
+
break;
|
|
267
|
+
case 'maximum':
|
|
268
|
+
numInferenceSteps = 60;
|
|
269
|
+
break;
|
|
270
|
+
case 'custom':
|
|
271
|
+
numInferenceSteps = customSteps || 25;
|
|
272
|
+
break;
|
|
273
|
+
default:
|
|
274
|
+
numInferenceSteps = 25;
|
|
275
|
+
}
|
|
276
|
+
// Build parameters object
|
|
277
|
+
const parameters = {
|
|
278
|
+
guidance_scale: guidanceScale || 7.5,
|
|
279
|
+
num_inference_steps: numInferenceSteps,
|
|
280
|
+
width: width,
|
|
281
|
+
height: height,
|
|
282
|
+
};
|
|
283
|
+
if (negativePrompt === null || negativePrompt === void 0 ? void 0 : negativePrompt.trim()) {
|
|
284
|
+
parameters['negative_prompt'] = negativePrompt.trim();
|
|
285
|
+
}
|
|
286
|
+
if (seed !== undefined && seed !== null) {
|
|
287
|
+
parameters['seed'] = Math.floor(seed);
|
|
288
|
+
}
|
|
289
|
+
if (scheduler) {
|
|
290
|
+
parameters['scheduler'] = scheduler;
|
|
291
|
+
}
|
|
292
|
+
const startTime = Date.now();
|
|
293
|
+
try {
|
|
294
|
+
const response = yield pieces_common_1.httpClient.sendRequest({
|
|
295
|
+
method: pieces_common_1.HttpMethod.POST,
|
|
296
|
+
url: `${common_1.HF_ROUTER_BASE}/${model}`,
|
|
297
|
+
headers: {
|
|
298
|
+
Authorization: `Bearer ${context.auth}`,
|
|
299
|
+
'Content-Type': 'application/json',
|
|
300
|
+
},
|
|
301
|
+
responseType: 'arraybuffer',
|
|
302
|
+
body: {
|
|
303
|
+
inputs: prompt.trim(),
|
|
304
|
+
parameters: parameters,
|
|
305
|
+
},
|
|
306
|
+
});
|
|
307
|
+
const imageBuffer = Buffer.from(response.body);
|
|
308
|
+
const base64Image = imageBuffer.toString('base64');
|
|
309
|
+
const generationTime = (Date.now() - startTime) / 1000;
|
|
310
|
+
const imageSizeKB = Math.round(imageBuffer.length / 1024);
|
|
311
|
+
return {
|
|
312
|
+
image: base64Image,
|
|
313
|
+
imageData: {
|
|
314
|
+
format: 'PNG',
|
|
315
|
+
width: width,
|
|
316
|
+
height: height,
|
|
317
|
+
sizeKB: imageSizeKB,
|
|
318
|
+
base64: `data:image/png;base64,${base64Image}`,
|
|
319
|
+
},
|
|
320
|
+
generation: {
|
|
321
|
+
prompt: prompt.trim(),
|
|
322
|
+
negativePrompt: (negativePrompt === null || negativePrompt === void 0 ? void 0 : negativePrompt.trim()) || '',
|
|
323
|
+
model: model,
|
|
324
|
+
useCase: useCase,
|
|
325
|
+
},
|
|
326
|
+
parameters: {
|
|
327
|
+
width: width,
|
|
328
|
+
height: height,
|
|
329
|
+
aspectRatio: aspectRatio,
|
|
330
|
+
guidanceScale: guidanceScale || 7.5,
|
|
331
|
+
inferenceSteps: numInferenceSteps,
|
|
332
|
+
scheduler: scheduler || 'auto',
|
|
333
|
+
seed: seed || 'random',
|
|
334
|
+
},
|
|
335
|
+
metrics: {
|
|
336
|
+
generationTimeSeconds: generationTime,
|
|
337
|
+
imageSizeKB: imageSizeKB,
|
|
338
|
+
resolution: `${width}×${height}`,
|
|
339
|
+
qualitySetting: qualitySettings || 'balanced',
|
|
340
|
+
estimatedCost: calculateEstimatedCost(model, width, height, numInferenceSteps),
|
|
341
|
+
},
|
|
342
|
+
businessInsights: {
|
|
343
|
+
useCase: getUseCaseDescription(useCase),
|
|
344
|
+
qualityTips: getQualityTips(prompt, negativePrompt, numInferenceSteps),
|
|
345
|
+
nextSteps: getNextSteps(useCase, imageSizeKB),
|
|
346
|
+
},
|
|
347
|
+
};
|
|
348
|
+
}
|
|
349
|
+
catch (error) {
|
|
350
|
+
const errorMessage = error instanceof Error ? error.message : String(error);
|
|
351
|
+
throw new Error(`Image generation failed: ${errorMessage}`);
|
|
352
|
+
}
|
|
353
|
+
});
|
|
354
|
+
},
|
|
355
|
+
});
|
|
356
|
+
function getUseCaseDescription(useCase) {
|
|
357
|
+
const descriptions = {
|
|
358
|
+
speed: 'Optimized for rapid prototyping and quick content creation',
|
|
359
|
+
quality: 'High-resolution generation perfect for marketing and professional use',
|
|
360
|
+
business: 'Business-focused models ideal for product imagery and brand content',
|
|
361
|
+
search: 'Custom model selection for specialized requirements',
|
|
362
|
+
};
|
|
363
|
+
return (descriptions[useCase] ||
|
|
364
|
+
'AI-powered image generation');
|
|
365
|
+
}
|
|
366
|
+
function getQualityTips(prompt, negativePrompt, steps) {
|
|
367
|
+
const tips = [];
|
|
368
|
+
if (prompt.length < 20) {
|
|
369
|
+
tips.push('💡 Add more descriptive details to your prompt for better results');
|
|
370
|
+
}
|
|
371
|
+
if (!negativePrompt) {
|
|
372
|
+
tips.push('🚫 Consider adding negative prompts to avoid unwanted elements (blur, low quality, etc.)');
|
|
373
|
+
}
|
|
374
|
+
if (steps < 20) {
|
|
375
|
+
tips.push('⚡ Using fast generation - increase steps for higher quality if needed');
|
|
376
|
+
}
|
|
377
|
+
if (steps > 50) {
|
|
378
|
+
tips.push('⏱️ High step count may take longer - consider balanced setting for faster results');
|
|
379
|
+
}
|
|
380
|
+
if (!prompt.toLowerCase().includes('high quality') &&
|
|
381
|
+
!prompt.toLowerCase().includes('detailed')) {
|
|
382
|
+
tips.push('🎯 Add quality keywords like "high resolution", "detailed", or "professional" to your prompt');
|
|
383
|
+
}
|
|
384
|
+
if (tips.length === 0) {
|
|
385
|
+
tips.push('✅ Good generation parameters - expect quality results');
|
|
386
|
+
}
|
|
387
|
+
return tips;
|
|
388
|
+
}
|
|
389
|
+
function getNextSteps(useCase, imageSizeKB) {
|
|
390
|
+
const steps = [];
|
|
391
|
+
if (useCase === 'business') {
|
|
392
|
+
steps.push('🎨 Try variations with different styles or angles');
|
|
393
|
+
steps.push('📐 Consider generating multiple aspect ratios for different platforms');
|
|
394
|
+
}
|
|
395
|
+
if (useCase === 'speed') {
|
|
396
|
+
steps.push('🔄 Generate variations quickly with different seeds');
|
|
397
|
+
steps.push('⬆️ Upscale to higher quality when you find the perfect concept');
|
|
398
|
+
}
|
|
399
|
+
if (imageSizeKB > 1000) {
|
|
400
|
+
steps.push('📉 Consider optimizing image size for web use');
|
|
401
|
+
}
|
|
402
|
+
steps.push('💾 Save successful prompts for consistent brand imagery');
|
|
403
|
+
steps.push('🔄 Use the same seed to create variations of this concept');
|
|
404
|
+
return steps;
|
|
405
|
+
}
|
|
406
|
+
function calculateEstimatedCost(model, width, height, steps) {
|
|
407
|
+
const basePixelCost = 0.000001;
|
|
408
|
+
const stepMultiplier = steps / 25;
|
|
409
|
+
const modelMultiplier = model.includes('FLUX.1-dev')
|
|
410
|
+
? 2.5
|
|
411
|
+
: model.includes('stable-diffusion-3')
|
|
412
|
+
? 2.0
|
|
413
|
+
: model.includes('turbo')
|
|
414
|
+
? 0.5
|
|
415
|
+
: 1.0;
|
|
416
|
+
const pixels = width * height;
|
|
417
|
+
const estimatedCost = pixels * basePixelCost * stepMultiplier * modelMultiplier;
|
|
418
|
+
if (estimatedCost < 0.001) {
|
|
419
|
+
return '< $0.001';
|
|
420
|
+
}
|
|
421
|
+
return `~$${estimatedCost.toFixed(4)}`;
|
|
422
|
+
}
|
|
423
|
+
//# sourceMappingURL=create-image.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"create-image.js","sourceRoot":"","sources":["../../../../../../../../packages/pieces/community/hugging-face/src/lib/actions/create-image.ts"],"names":[],"mappings":";;;;AAAA,kEAAqE;AACrE,4DAAkE;AAClE,kCAA0C;AAC1C,sCAA2C;AAE9B,QAAA,WAAW,GAAG,IAAA,+BAAY,EAAC;IACtC,IAAI,EAAE,cAAc;IACpB,IAAI,EAAE,sBAAe;IACrB,WAAW,EAAE,cAAc;IAC3B,WAAW,EACT,kJAAkJ;IACpJ,KAAK,EAAE;QACL,OAAO,EAAE,2BAAQ,CAAC,cAAc,CAAC;YAC/B,WAAW,EAAE,UAAU;YACvB,WAAW,EAAE,4CAA4C;YACzD,QAAQ,EAAE,IAAI;YACd,OAAO,EAAE;gBACP,QAAQ,EAAE,KAAK;gBACf,OAAO,EAAE;oBACP;wBACE,KAAK,EAAE,oCAAoC;wBAC3C,KAAK,EAAE,OAAO;qBACf;oBACD;wBACE,KAAK,EAAE,kCAAkC;wBACzC,KAAK,EAAE,SAAS;qBACjB;oBACD;wBACE,KAAK,EAAE,sCAAsC;wBAC7C,KAAK,EAAE,UAAU;qBAClB;oBACD;wBACE,KAAK,EAAE,mBAAmB;wBAC1B,KAAK,EAAE,QAAQ;qBAChB;iBACF;aACF;YACD,YAAY,EAAE,SAAS;SACxB,CAAC;QACF,KAAK,EAAE,2BAAQ,CAAC,QAAQ,CAAC;YACvB,WAAW,EAAE,wBAAwB;YACrC,WAAW,EAAE,yCAAyC;YACtD,QAAQ,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,KAAK,CAAC,QAAQ,CAAC,OAAO,CAAC;gBACzB,CAAC,CAAC,GAAG;gBACL,CAAC,CAAC,GAAG,CAAC;IAER,MAAM,MAAM,GAAG,KAAK,GAAG,MAAM,CAAC;IAC9B,MAAM,aAAa,GACjB,MAAM,GAAG,aAAa,GAAG,cAAc,GAAG,eAAe,CAAC;IAE5D,IAAI,aAAa,GAAG,KAAK,EAAE,CAAC;QAC1B,OAAO,UAAU,CAAC;IACpB,CAAC;IAED,OAAO,KAAK,aAAa,CAAC,OAAO,CAAC,CAAC,CAAC,EAAE,CAAC;AACzC,CAAC"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export declare const documentQuestionAnswering: import("@taskmagic/pieces-framework").IAction<import("@taskmagic/pieces-framework").SecretTextProperty<true>, {
|
|
2
|
+
model: import("@taskmagic/pieces-framework").StaticDropdownProperty<string, true>;
|
|
3
|
+
image: import("@taskmagic/pieces-framework").FileProperty<true>;
|
|
4
|
+
question: import("@taskmagic/pieces-framework").ShortTextProperty<true>;
|
|
5
|
+
top_k: import("@taskmagic/pieces-framework").NumberProperty<false>;
|
|
6
|
+
max_answer_len: import("@taskmagic/pieces-framework").NumberProperty<false>;
|
|
7
|
+
handle_impossible_answer: import("@taskmagic/pieces-framework").CheckboxProperty<false>;
|
|
8
|
+
lang: import("@taskmagic/pieces-framework").StaticDropdownProperty<string, false>;
|
|
9
|
+
use_cache: import("@taskmagic/pieces-framework").CheckboxProperty<false>;
|
|
10
|
+
wait_for_model: import("@taskmagic/pieces-framework").CheckboxProperty<false>;
|
|
11
|
+
}>;
|
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.documentQuestionAnswering = void 0;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
const pieces_framework_1 = require("@taskmagic/pieces-framework");
|
|
6
|
+
const auth_1 = require("../auth");
|
|
7
|
+
const common_1 = require("../common");
|
|
8
|
+
exports.documentQuestionAnswering = (0, pieces_framework_1.createAction)({
|
|
9
|
+
name: 'document_question_answering',
|
|
10
|
+
auth: auth_1.huggingFaceAuth,
|
|
11
|
+
displayName: 'Document Question Answering',
|
|
12
|
+
description: 'Answer questions from document images using Hugging Face models',
|
|
13
|
+
props: {
|
|
14
|
+
model: pieces_framework_1.Property.StaticDropdown({
|
|
15
|
+
displayName: 'Model',
|
|
16
|
+
description: 'Hugging Face document question answering model',
|
|
17
|
+
required: true,
|
|
18
|
+
options: {
|
|
19
|
+
disabled: false,
|
|
20
|
+
options: [
|
|
21
|
+
{
|
|
22
|
+
label: 'impira/layoutlm-document-qa (Recommended)',
|
|
23
|
+
value: 'impira/layoutlm-document-qa',
|
|
24
|
+
},
|
|
25
|
+
{
|
|
26
|
+
label: 'microsoft/layoutlmv3-base',
|
|
27
|
+
value: 'microsoft/layoutlmv3-base',
|
|
28
|
+
},
|
|
29
|
+
{
|
|
30
|
+
label: 'nielsr/layoutlmv2-finetuned-docvqa',
|
|
31
|
+
value: 'nielsr/layoutlmv2-finetuned-docvqa',
|
|
32
|
+
},
|
|
33
|
+
],
|
|
34
|
+
},
|
|
35
|
+
defaultValue: 'impira/layoutlm-document-qa',
|
|
36
|
+
}),
|
|
37
|
+
image: pieces_framework_1.Property.File({
|
|
38
|
+
displayName: 'Document Image',
|
|
39
|
+
description: 'Image of the document to analyze (invoice, contract, etc.)',
|
|
40
|
+
required: true,
|
|
41
|
+
}),
|
|
42
|
+
question: pieces_framework_1.Property.ShortText({
|
|
43
|
+
displayName: 'Question',
|
|
44
|
+
description: "Question to ask about the document (e.g., 'What is the invoice total?')",
|
|
45
|
+
required: true,
|
|
46
|
+
}),
|
|
47
|
+
top_k: pieces_framework_1.Property.Number({
|
|
48
|
+
displayName: 'Number of Answers',
|
|
49
|
+
description: 'Number of top answers to return',
|
|
50
|
+
required: false,
|
|
51
|
+
defaultValue: 1,
|
|
52
|
+
}),
|
|
53
|
+
max_answer_len: pieces_framework_1.Property.Number({
|
|
54
|
+
displayName: 'Max Answer Length',
|
|
55
|
+
description: 'Maximum length of predicted answers',
|
|
56
|
+
required: false,
|
|
57
|
+
}),
|
|
58
|
+
handle_impossible_answer: pieces_framework_1.Property.Checkbox({
|
|
59
|
+
displayName: 'Handle Impossible Answers',
|
|
60
|
+
description: "Whether to accept 'impossible' as an answer when no answer is found",
|
|
61
|
+
required: false,
|
|
62
|
+
defaultValue: true,
|
|
63
|
+
}),
|
|
64
|
+
lang: pieces_framework_1.Property.StaticDropdown({
|
|
65
|
+
displayName: 'OCR Language',
|
|
66
|
+
description: 'Language to use for OCR text extraction',
|
|
67
|
+
required: false,
|
|
68
|
+
options: {
|
|
69
|
+
disabled: false,
|
|
70
|
+
options: [
|
|
71
|
+
{ label: 'English', value: 'en' },
|
|
72
|
+
{ label: 'Spanish', value: 'es' },
|
|
73
|
+
{ label: 'French', value: 'fr' },
|
|
74
|
+
{ label: 'German', value: 'de' },
|
|
75
|
+
{ label: 'Italian', value: 'it' },
|
|
76
|
+
{ label: 'Portuguese', value: 'pt' },
|
|
77
|
+
],
|
|
78
|
+
},
|
|
79
|
+
defaultValue: 'en',
|
|
80
|
+
}),
|
|
81
|
+
use_cache: pieces_framework_1.Property.Checkbox({
|
|
82
|
+
displayName: 'Use Cache',
|
|
83
|
+
description: 'Use cached results if available',
|
|
84
|
+
required: false,
|
|
85
|
+
defaultValue: true,
|
|
86
|
+
}),
|
|
87
|
+
wait_for_model: pieces_framework_1.Property.Checkbox({
|
|
88
|
+
displayName: 'Wait for Model',
|
|
89
|
+
description: 'Wait for model to load if not ready',
|
|
90
|
+
required: false,
|
|
91
|
+
defaultValue: false,
|
|
92
|
+
}),
|
|
93
|
+
},
|
|
94
|
+
run(context) {
|
|
95
|
+
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
96
|
+
const { model, image, question, top_k, max_answer_len, handle_impossible_answer, lang, use_cache, wait_for_model, } = context.propsValue;
|
|
97
|
+
const base64Image = Buffer.from(image.data).toString('base64');
|
|
98
|
+
const parameters = {};
|
|
99
|
+
if (top_k !== undefined) {
|
|
100
|
+
parameters.top_k = top_k;
|
|
101
|
+
}
|
|
102
|
+
if (max_answer_len !== undefined) {
|
|
103
|
+
parameters.max_answer_len = max_answer_len;
|
|
104
|
+
}
|
|
105
|
+
if (handle_impossible_answer !== undefined) {
|
|
106
|
+
parameters.handle_impossible_answer = handle_impossible_answer;
|
|
107
|
+
}
|
|
108
|
+
if (lang) {
|
|
109
|
+
parameters.lang = lang;
|
|
110
|
+
}
|
|
111
|
+
const body = {
|
|
112
|
+
inputs: {
|
|
113
|
+
image: base64Image,
|
|
114
|
+
question: question,
|
|
115
|
+
},
|
|
116
|
+
options: {
|
|
117
|
+
use_cache: use_cache !== null && use_cache !== void 0 ? use_cache : true,
|
|
118
|
+
wait_for_model: wait_for_model !== null && wait_for_model !== void 0 ? wait_for_model : false,
|
|
119
|
+
},
|
|
120
|
+
};
|
|
121
|
+
if (Object.keys(parameters).length > 0) {
|
|
122
|
+
body['parameters'] = parameters;
|
|
123
|
+
}
|
|
124
|
+
const rawResult = yield (0, common_1.callPipelineTask)({
|
|
125
|
+
auth: context.auth,
|
|
126
|
+
model: model,
|
|
127
|
+
body,
|
|
128
|
+
});
|
|
129
|
+
const result = Array.isArray(rawResult) ? rawResult[0] : rawResult;
|
|
130
|
+
return {
|
|
131
|
+
answer: result.answer,
|
|
132
|
+
score: result.score,
|
|
133
|
+
start: result.start,
|
|
134
|
+
end: result.end,
|
|
135
|
+
raw_result: rawResult,
|
|
136
|
+
};
|
|
137
|
+
});
|
|
138
|
+
},
|
|
139
|
+
});
|
|
140
|
+
//# sourceMappingURL=document-question-answering.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"document-question-answering.js","sourceRoot":"","sources":["../../../../../../../../packages/pieces/community/hugging-face/src/lib/actions/document-question-answering.ts"],"names":[],"mappings":";;;;AAAA,kEAAqE;AACrE,kCAA0C;AAC1C,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,KAAK,EAAE,MAAM,CAAC,KAAK;gBACnB,KAAK,EAAE,MAAM,CAAC,KAAK;gBACnB,GAAG,EAAE,MAAM,CAAC,GAAG;gBACf,UAAU,EAAE,SAAS;aACtB,CAAC;QACJ,CAAC;KAAA;CACF,CAAC,CAAC"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
export declare const imageClassification: import("@taskmagic/pieces-framework").IAction<import("@taskmagic/pieces-framework").SecretTextProperty<true>, {
|
|
2
|
+
classificationMode: import("@taskmagic/pieces-framework").StaticDropdownProperty<string, true>;
|
|
3
|
+
useCase: import("@taskmagic/pieces-framework").StaticDropdownProperty<string, true>;
|
|
4
|
+
model: import("@taskmagic/pieces-framework").DropdownProperty<string, true>;
|
|
5
|
+
imageSource: import("@taskmagic/pieces-framework").StaticDropdownProperty<string, true>;
|
|
6
|
+
imageFile: import("@taskmagic/pieces-framework").FileProperty<true>;
|
|
7
|
+
imageUrl: import("@taskmagic/pieces-framework").ShortTextProperty<true>;
|
|
8
|
+
customCategories: import("@taskmagic/pieces-framework").ArrayProperty<true>;
|
|
9
|
+
hypothesisTemplate: import("@taskmagic/pieces-framework").ShortTextProperty<false>;
|
|
10
|
+
topK: import("@taskmagic/pieces-framework").NumberProperty<false>;
|
|
11
|
+
confidenceThreshold: import("@taskmagic/pieces-framework").NumberProperty<false>;
|
|
12
|
+
outputFormat: import("@taskmagic/pieces-framework").StaticDropdownProperty<string, false>;
|
|
13
|
+
}>;
|