File size: 2,558 Bytes
de5e2bc
6a1c851
de5e2bc
 
6a1c851
de5e2bc
6a1c851
de5e2bc
 
 
 
6a1c851
 
de5e2bc
6a1c851
 
de5e2bc
 
 
 
 
 
6a1c851
de5e2bc
6a1c851
 
 
 
de5e2bc
 
 
6a1c851
 
de5e2bc
6a1c851
 
de5e2bc
 
 
 
 
 
 
 
6a1c851
de5e2bc
 
 
 
6a1c851
 
de5e2bc
6a1c851
de5e2bc
 
 
 
 
 
6a1c851
de5e2bc
6a1c851
 
 
 
 
 
 
de5e2bc
 
6a1c851
 
 
 
 
 
de5e2bc
 
6a1c851
 
de5e2bc
 
 
 
 
 
6a1c851
de5e2bc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
_id: hugging_face
author: Anton Breslavskii | https://github.com/breslavsky
description: ""
readme: ""
title: Hugging Face
url: https://huggingface.co/PiperMy/Node-Packages/resolve/main/hugging_face.yaml
version: 2
nodes:
  pulid_flux:
    _id: pulid_flux
    arrange:
      x: 180
      y: 260
    category:
      _id: deep_swap
      title: en=Magic portrait;ru=Магический портрет
    environment:
      HF_TOKEN:
        title: Hugging Face Token
        type: string
        scope: global
    inputs:
      person:
        order: 1
        title: en=Person;ru=Персона
        type: image
      prompt:
        order: 2
        title: en=Prompt;ru=Подсказка
        type: string
        required: true
        multiline: true
        default: a portrait of a zombie
    outputs:
      portrait:
        title: Portrait
        type: image
    package: hugging_face
    script: |-
      export async function run({ inputs }) {

          const { FatalError, NextNode } = DEFINITIONS;

          const HF_TOKEN = env?.variables?.get('HF_TOKEN');
          if (!HF_TOKEN) {
              throw new FatalError('Please, set your API key Hugging Face');
          }

          const { Client } = await import("@gradio/client/dist/index.js");

          const { person, prompt } = inputs;
          const { data: id_image } = await download(person);
          const client = await Client.connect("PiperMy/tight-inversion-pulid-demo", {
              hf_token: HF_TOKEN
          });

          console.log('Send request');
          try {
              const { data } = await client.predict("/generate_image", {
                  prompt: prompt || 'a portrait of a zombie',
                  id_image,
                  id_weight: 0.5,
                  num_steps: 16,
                  guidance: 3.5,
                  width: 1024,
                  height: 1024,
                  neg_prompt: "bad image",
                  true_cfg: 5,
                  timestep_to_start_cfg: 0,
                  max_sequence_length: 128,
                  start_step: 0,
                  seed: -1,
                  gamma: .5,
                  eta: 0.7,
                  s: 0,
                  tau: 2,
              });
              const [{ url }] = data;
              const { data: portrait } = await download(url);
              return NextNode.from({ outputs: { portrait } });
          } catch (e) {
              throw new FatalError(e.message);
          }

      }
    source: catalog
    title: Magic portrait
    version: 1