breslavsky commited on
Commit
813914a
·
1 Parent(s): 9da7a60

add yaml for detect gender

Browse files
pipelines/detect_gender/detect_gender.yaml ADDED
@@ -0,0 +1,369 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ name: en=Detect Gender;ru=Определение пола
2
+ version: 1
3
+ description: en=Check gender from photo with AI;ru=Определение пола по фото с помощью ИИ
4
+ tags:
5
+ - Gender Detection
6
+ - en=Images;ru=Изображения
7
+ - en=Computer Vision;ru=Компьютерное зрение
8
+ readme: |
9
+ Instantly detect the gender (male/female) from uploaded photos using AI-powered classification.
10
+
11
+ ## Examples
12
+
13
+ <div class="row">
14
+ <div class="col-3">
15
+ <label>Female Example</label>
16
+ <button class="transparent" onclick="play({image: 'https://huggingface.co/PiperMy/Pipelines/resolve/main/pipelines/detect_gender/female.png'}, this)">
17
+ <img src="https://huggingface.co/PiperMy/Pipelines/resolve/main/pipelines/detect_gender/female.png">
18
+ </button>
19
+ </div>
20
+ <div class="col-3">
21
+ <label>Male Example</label>
22
+ <button class="transparent" onclick="play({image: 'https://huggingface.co/PiperMy/Pipelines/resolve/main/pipelines/detect_gender/male.png'}, this)">
23
+ <img src="https://huggingface.co/PiperMy/Pipelines/resolve/main/pipelines/detect_gender/male.png">
24
+ </button>
25
+ </div>
26
+ </div>
27
+
28
+ ## Features
29
+ - **AI-Based Classification**: Identify gender using deep learning models.
30
+ - **Fast Processing**: Get results in just seconds.
31
+ - **Simple Upload Interface**: Just upload a photo and get the result.
32
+ - **Optimized for Accuracy**: Tailored labels for better detection.
33
+
34
+ ## Description
35
+ The "Detect Gender" pipeline uses advanced image classification models to detect whether a person in a photo is male or female. It leverages AI to analyze visual features and predict gender with high reliability.
36
+
37
+ The system is lightweight, fast, and easy to integrate into larger AI pipelines or web applications.
38
+
39
+ ## How It Works
40
+ 1. **Upload Image**: Upload a photo containing a face.
41
+ 2. **AI Processing**: The system analyzes the image and classifies the gender.
42
+ 3. **View Results**: See the detected gender and prediction confidence.
43
+
44
+ ## Applications
45
+ - **Social Media**: Profile gender analysis.
46
+ - **Photo Tagging**: Automatic tagging for photo libraries.
47
+ - **Content Moderation**: Gender detection for demographic analysis.
48
+ - **Entertainment Apps**: Fun gender prediction games.
49
+
50
+ ## Integration Possibilities
51
+ - **Mobile Apps**: Gender tagging features.
52
+ - **Web Services**: Gender detection for uploaded avatars.
53
+ - **Security Systems**: Supplementary demographic analysis.
54
+ - **Creative Filters**: Use gender detection to apply style-specific effects.
55
+
56
+ --- ru ---
57
+ Мгновенно определяйте пол (мужской/женский) по загруженным фото с помощью классификации на основе ИИ.
58
+
59
+ ## Примеры
60
+
61
+ <div class="row">
62
+ <div class="col-3">
63
+ <label>Пример женского</label>
64
+ <button class="transparent" onclick="play({image: 'https://huggingface.co/PiperMy/Pipelines/resolve/main/pipelines/detect_gender/female.png'}, this)">
65
+ <img src="https://huggingface.co/PiperMy/Pipelines/resolve/main/pipelines/detect_gender/female.png">
66
+ </button>
67
+ </div>
68
+ <div class="col-3">
69
+ <label>Пример мужского</label>
70
+ <button class="transparent" onclick="play({image: 'https://huggingface.co/PiperMy/Pipelines/resolve/main/pipelines/detect_gender/male.png'}, this)">
71
+ <img src="https://huggingface.co/PiperMy/Pipelines/resolve/main/pipelines/detect_gender/male.png">
72
+ </button>
73
+ </div>
74
+ </div>
75
+
76
+ ## Возможности
77
+ - **Классификация на основе ИИ**: Определение пола с использованием моделей глубокого обучения.
78
+ - **Быстрая обработка**: Результаты в считанные секунды.
79
+ - **Простой интерфейс загрузки**: Загрузите фото и получите результат.
80
+ - **Оптимизация для точности**: Специально настроенные метки для улучшенной точности.
81
+
82
+ ## Описание
83
+ Пайплайн "Определение пола" использует передовые модели классификации изображений для определения пола человека на фото. Он использует ИИ для анализа визуальных характеристик и точного предсказания пола с высокой надежностью.
84
+
85
+ Система легкая, быстрая и легко интегрируемая в более сложные AI пайплайны или веб-приложения.
86
+
87
+ ## Как это работает
88
+ 1. **Загрузка изображения**: Загрузите фото с лицом.
89
+ 2. **Обработка ИИ**: Система анализирует изображение и классифици��ует пол.
90
+ 3. **Посмотреть результат**: Получите пол и уверенность в предсказаниях.
91
+
92
+ ## Применение
93
+ - **Социальные сети**: Анализ пола профилей.
94
+ - **Тегирование фото**: Автоматическое добавление тегов для фото-библиотек.
95
+ - **Модерация контента**: Определение пола для демографического анализа.
96
+ - **Развлекательные приложения**: Игры по предсказанию пола.
97
+
98
+ ## Возможности интеграции
99
+ - **Мобильные приложения**: Функция тегирования пола.
100
+ - **Веб-сервисы**: Определение пола для загруженных аватаров.
101
+ - **Системы безопасности**: Дополнительный демографический анализ.
102
+ - **Креативные фильтры**: Использование определения пола для применения фильтров по стилю.
103
+ thumbnail: https://huggingface.co/PiperMy/Pipelines/resolve/main/thumbnails/detect_gender.jpg
104
+ script: |-
105
+ export async function costs() {
106
+ return 0.001;
107
+ }
108
+ category:
109
+ _id: computer_vision
110
+ title: en=Computer vision;ru=Компьютерное зрение
111
+ icon: object_detection
112
+ start:
113
+ nodes:
114
+ - classify_image
115
+ deploy:
116
+ slug: detect-gender-v1
117
+ scope:
118
+ id: detect_gender_v1
119
+ activated: false
120
+ maxConcurrent: 0
121
+ inputs:
122
+ image:
123
+ title: en=Image;ru=Изображение
124
+ type: image
125
+ required: true
126
+ flows:
127
+ to_classify_image:
128
+ to: classify_image
129
+ input: image
130
+ arrange:
131
+ x: 180
132
+ y: 130
133
+ outputs:
134
+ gender:
135
+ title: en=Gender;ru=Пол
136
+ type: string
137
+ flows:
138
+ evaluate_tags:
139
+ from: evaluate_tags
140
+ output: gender
141
+ arrange:
142
+ x: 940
143
+ y: 110
144
+ tags:
145
+ title: en=Tags;ru=Теги
146
+ type: json
147
+ flows:
148
+ evaluate_tags:
149
+ from: evaluate_tags
150
+ output: tags
151
+ arrange:
152
+ x: 940
153
+ y: 190
154
+ flows:
155
+ classify_image_to_evaluate_tags_d39aa:
156
+ from: classify_image
157
+ output: labels
158
+ to: evaluate_tags
159
+ input: tags
160
+ nodes:
161
+ classify_image:
162
+ _id: classify_image_artworks
163
+ version: 1
164
+ category:
165
+ _id: image_analysis
166
+ title: en=Image analysis;ru=Анализ изображений
167
+ package: artworks
168
+ title: en=Classify image;ru=Тегировать изображение
169
+ source: catalog
170
+ execution: regular
171
+ script: |-
172
+ const CHECK_TASK_INTERVAL = 1000;
173
+ const MAX_ATTEMPTS = 20;
174
+
175
+ export async function run({ inputs, state }) {
176
+
177
+ const { FatalError, TimeoutError, RepeatNode, NextNode } = DEFINITIONS;
178
+ const { ArtWorks, FatalError: ArtWorksError } = require('artworks');
179
+
180
+ const PAAS_BASE_URL = env.variables.get('PAAS_BASE_URL');
181
+ if (!PAAS_BASE_URL) {
182
+ throw new FatalError('Please, set PAAS_BASE_URL in environment');
183
+ }
184
+ const OPEN_PAAS_USER = env.variables.get('OPEN_PAAS_USER');
185
+ if (!OPEN_PAAS_USER) {
186
+ throw new FatalError('Please, set OPEN_PAAS_USER in environment');
187
+ }
188
+ const OPEN_PAAS_PASSWORD = env.variables.get('OPEN_PAAS_PASSWORD');
189
+ if (!OPEN_PAAS_PASSWORD) {
190
+ throw new FatalError('Please, set OPEN_PAAS_PASSWORD in environment');
191
+ }
192
+
193
+ const artworks = new ArtWorks({
194
+ baseUrl: PAAS_BASE_URL,
195
+ username: OPEN_PAAS_USER,
196
+ password: OPEN_PAAS_PASSWORD
197
+ });
198
+
199
+ if (!state) {
200
+ const { image, labels } = inputs;
201
+
202
+ const payload = {
203
+ type: "classify-image",
204
+ isFast: true,
205
+ payload: {
206
+ base64: false,
207
+ image,
208
+ labels: Object.values(labels),
209
+ },
210
+ };
211
+ try {
212
+ const task = await artworks.createTask(payload);
213
+ console.log(`Task created ${task}`);
214
+ return RepeatNode.from({
215
+ state: {
216
+ payload,
217
+ task,
218
+ attempt: 0,
219
+ startedAt: new Date()
220
+ },
221
+ progress: {
222
+ total: MAX_ATTEMPTS,
223
+ processed: 0
224
+ },
225
+ delay: 2000
226
+ });
227
+ } catch (e) {
228
+ if (e instanceof ArtWorksError) {
229
+ throw new FatalError(e.message);
230
+ }
231
+ throw e;
232
+ }
233
+ } else {
234
+ const {
235
+ payload,
236
+ task,
237
+ attempt,
238
+ startedAt
239
+ } = state;
240
+
241
+ if (attempt > MAX_ATTEMPTS) {
242
+ try {
243
+ await artworks.cancelTask(task);
244
+ } catch (e) { }
245
+
246
+ const now = new Date();
247
+ const time = (now - new Date(startedAt)) / 1000;
248
+ throw new TimeoutError(`PaaS task for text to image ${task} timeout in ${time} sec`);
249
+ }
250
+
251
+ console.log(`Check task ${attempt} ${task}`);
252
+
253
+ try {
254
+ const results = await artworks.checkState(task);
255
+ if (!results) {
256
+ return RepeatNode.from({
257
+ delay: CHECK_TASK_INTERVAL,
258
+ state: {
259
+ payload,
260
+ task,
261
+ attempt: attempt + 1,
262
+ startedAt,
263
+ },
264
+ progress: {
265
+ total: MAX_ATTEMPTS,
266
+ processed: attempt
267
+ },
268
+ });
269
+ }
270
+ let { probs } = results;
271
+ const { labels } = inputs;
272
+ const tags = {};
273
+ for (const key of Object.keys(labels)) {
274
+ tags[key] = probs[labels[key]];
275
+ }
276
+ return NextNode.from({
277
+ outputs: {
278
+ labels: tags
279
+ }
280
+ });
281
+ } catch (e) {
282
+ if (e instanceof ArtWorksError) {
283
+ throw new FatalError(e.message);
284
+ }
285
+ throw e;
286
+ }
287
+ }
288
+ }
289
+ arrange:
290
+ x: 260
291
+ y: 90
292
+ inputs:
293
+ image:
294
+ order: 1
295
+ title: en=Image;ru=Изображение
296
+ type: image
297
+ required: true
298
+ labels:
299
+ order: 2
300
+ title: en=Labels;ru=Теги
301
+ type: json
302
+ required: true
303
+ default: '{ "girl": "girl on photo", "male": "male on photo" }'
304
+ schema:
305
+ id: image-labels
306
+ outputs:
307
+ labels:
308
+ title: en=Labels;ru=Теги
309
+ type: json
310
+ environment:
311
+ OPEN_PAAS_USER:
312
+ title: PaaS user
313
+ type: string
314
+ scope: global
315
+ OPEN_PAAS_PASSWORD:
316
+ title: PaaS password
317
+ type: string
318
+ scope: global
319
+ PAAS_BASE_URL:
320
+ title: PaaS base url
321
+ type: string
322
+ scope: global
323
+ evaluate_tags:
324
+ _id: multiply_numbers
325
+ version: 0
326
+ title: en=Evaluate tags;ru=Оценить теги
327
+ source: node
328
+ execution: rapid
329
+ script: |-
330
+ export async function run({ inputs }) {
331
+ const { NextNode } = DEFINITIONS;
332
+ const { tags } = inputs;
333
+ return NextNode.from({
334
+ outputs: {
335
+ tags,
336
+ gender: tags['male'] > tags['female'] ?
337
+ 'male' : 'female'
338
+ }
339
+ });
340
+ }
341
+ arrange:
342
+ x: 580
343
+ y: 90
344
+ inputs:
345
+ tags:
346
+ title: en=Tags;ru=Тэги
347
+ type: json
348
+ required: true
349
+ outputs:
350
+ gender:
351
+ title: en=Gender;ru=Пол
352
+ type: string
353
+ tags:
354
+ title: en=Tags;ru=Тэги
355
+ type: json
356
+ environment: {}
357
+ ------
358
+ {
359
+ "inputs": {
360
+ "image": "https://huggingface.co/PiperMy/Pipelines/resolve/main/assets/persons/nicolas_cage/01.jpg"
361
+ },
362
+ "nodes": {
363
+ "classify_image": {
364
+ "inputs": {
365
+ "labels": "{ \"female\": \"girl on photo\", \"male\": \"male on photo\" }"
366
+ }
367
+ }
368
+ }
369
+ }