mypiper commited on
Commit
de5e2bc
·
verified ·
1 Parent(s): 02b2159

Create hugging_face.yaml

Browse files
Files changed (1) hide show
  1. hugging_face.yaml +179 -0
hugging_face.yaml ADDED
@@ -0,0 +1,179 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ _id: hugging_face
2
+ title: Hugging Face
3
+ description: ""
4
+ version: 1
5
+ readme: ""
6
+ url: https://huggingface.co/PiperMy/Node-Packages/resolve/main/hugging_face.yaml
7
+ author: Anton Breslavskii | https://github.com/breslavsky
8
+ nodes:
9
+ pulid_flux:
10
+ _id: pulid_flux
11
+ arrange:
12
+ x: 140
13
+ y: 60
14
+ category:
15
+ id: deep_swap
16
+ title: en=Deep swap;ru=Глубокая замена
17
+ environment:
18
+ HF_TOKEN:
19
+ title: Hugging Face Token
20
+ type: string
21
+ scope: global
22
+ inputs:
23
+ prompt:
24
+ order: 1
25
+ title: en=Prompt;ru=Подсказка
26
+ type: string
27
+ required: true
28
+ default: portrait, color, cinematic
29
+ person:
30
+ title: en=Person;ru=Фото человека
31
+ type: image
32
+ required: true
33
+ imageSize:
34
+ title: Image size
35
+ type: string
36
+ default: 1024x1024
37
+ enum:
38
+ - 512x512
39
+ - 1024x1024
40
+ outputs:
41
+ image:
42
+ title: ""
43
+ type: image
44
+ package: hugging_face
45
+ script: |-
46
+ export async function run({ inputs }) {
47
+
48
+ const { FatalError, NextNode } = DEFINITIONS;
49
+
50
+ const HF_TOKEN = env?.variables?.get('HF_TOKEN');
51
+ if(!HF_TOKEN) {
52
+ throw new FatalError('Please, set your API key Hugging Face');
53
+ }
54
+
55
+ const { Client } = await import("@gradio/client/dist/index.js");
56
+ const { person, prompt, imageSize } = inputs;
57
+ const [width, height] = (() => {
58
+ const [width, height] = imageSize.split('x');
59
+ return [parseInt(width), parseInt(height)];
60
+ })();
61
+
62
+ const { data: id_image } = await download(person);
63
+ const client = await Client.connect("PiperMy/PuLID-FLUX", {
64
+ hf_token: HF_TOKEN
65
+ });
66
+
67
+ console.log('Send request');
68
+ try {
69
+ const { data } = await client.predict("/generate_image", {
70
+ prompt,
71
+ id_image,
72
+ start_step: 0,
73
+ guidance: 2,
74
+ seed: -1,
75
+ true_cfg: 1,
76
+ width,
77
+ height,
78
+ num_steps: 25,
79
+ id_weight: 1,
80
+ neg_prompt: "artefacts, bad face",
81
+ timestep_to_start_cfg: 0,
82
+ max_sequence_length: 128,
83
+ });
84
+ const [{ url }] = data;
85
+ const { data: image } = await download(url);
86
+ return NextNode.from({ outputs: { image } });
87
+ } catch (e) {
88
+ throw new FatalError(e.message);
89
+ }
90
+
91
+ }
92
+ source: catalog
93
+ title: PuLID Flux
94
+ version: 1
95
+ deepseek_r1_8b_six:
96
+ _id: deepseek_r1_8b_six
97
+ arrange:
98
+ x: 210
99
+ y: 310
100
+ category:
101
+ id: llm_agents
102
+ title: en=Language Agents;ru=Языковые агенты
103
+ environment:
104
+ HF_TOKEN:
105
+ title: Hugging Face Token
106
+ type: string
107
+ scope: pipeline
108
+ inputs:
109
+ question:
110
+ order: 1
111
+ title: en=Question;ru=Вопрос
112
+ type: string
113
+ required: true
114
+ multiline: true
115
+ default: What time is it now? Only JSON ready to parse.
116
+ answerFormat:
117
+ order: 2
118
+ title: en=Answer format;ru=Формат ответа
119
+ description: Don't forget add instructions for LLM
120
+ type: string
121
+ required: true
122
+ default: text
123
+ enum:
124
+ - text|Text
125
+ - json|JSON
126
+ outputs:
127
+ answer:
128
+ title: en=Answer;ru=Ответ
129
+ type: string
130
+ json:
131
+ title: JSON
132
+ type: json
133
+ package: hugging_face
134
+ script: |
135
+ export async function run({ inputs }) {
136
+
137
+ const { FatalError, NextNode } = DEFINITIONS;
138
+ const OpenAI = require('openai');
139
+
140
+ const HF_TOKEN = env?.variables?.get('HF_TOKEN');
141
+ if (!HF_TOKEN) {
142
+ throw new FatalError('Please, set your API key for HF');
143
+ }
144
+
145
+ const { question, model, answerFormat } = inputs;
146
+
147
+ const openai = new OpenAI({
148
+ baseURL: 'https://jq20v0lfcxycc1z3.us-east-1.aws.endpoints.huggingface.cloud/v1/',
149
+ apiKey: HF_TOKEN,
150
+ });
151
+
152
+ const result = await openai.chat.completions.create({
153
+ model: 'lmstudio-community/DeepSeek-R1-Distill-Llama-8B-GGUF',
154
+ messages: [
155
+ { "role": "user", "content": question },
156
+ ],
157
+ });
158
+
159
+ const { content: answer } = result.choices[0].message;
160
+
161
+ switch (answerFormat) {
162
+ case 'text':
163
+ return NextNode.from({ outputs: { answer } });
164
+ case 'json':
165
+ try {
166
+ const json = answer.replace(/^\`\`\`json\s*/ig, '').replace(/\`\`\`\s*$/ig, '');
167
+ return NextNode.from({ outputs: { json: JSON.parse(json) } });
168
+ } catch (e) {
169
+ console.log(e);
170
+ message(`Wrong JSON for question \`\`\`text\n${question}\n\`\`\`\nnanswer from LLM\n\`\`\`text${answer}\n\`\`\``, 'defect');
171
+ throw new FatalError("Can't parse JSON asnwer from LLM");
172
+ }
173
+ default:
174
+ throw new FatalError(`Wrong answer format ${answerFormat}`);
175
+ }
176
+ }
177
+ source: catalog
178
+ title: DeepSeek R1 Distill Llama 8B Q8
179
+ version: 1