-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathnodes_lora.py
More file actions
73 lines (64 loc) · 2.01 KB
/
Copy pathnodes_lora.py
File metadata and controls
73 lines (64 loc) · 2.01 KB
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
from .utils import (
ASPECT_RATIOS,
add_hf_token,
call_api_with_fallback,
generation_url_to_tensor,
resolve_api_key,
)
LORA_MODELS = [
"p-image-lora",
]
class PrunaTextToImageLoRA:
"""Generate an image from a text prompt with a custom LoRA using the Pruna API.
LoRA weights must be a HuggingFace URL in the format:
huggingface.co/<username>/<repo>[/<filename>]
Note: LoRAs used with p-image-lora must be trained with p-image-trainer.
"""
CATEGORY = "pruna ai"
RETURN_TYPES = ("IMAGE",)
RETURN_NAMES = ("image",)
FUNCTION = "generate"
@classmethod
def INPUT_TYPES(cls):
return {
"required": {
"prompt": ("STRING", {"multiline": True, "default": ""}),
"model": (LORA_MODELS, {"default": "p-image-lora"}),
"lora_weights": (
"STRING",
{"default": "huggingface.co/username/repo"},
),
"lora_scale": (
"FLOAT",
{"default": 0.5, "min": -1.0, "max": 3.0, "step": 0.05},
),
"aspect_ratio": (ASPECT_RATIOS, {"default": "1:1"}),
"api_key": ("STRING", {"default": ""}),
},
"optional": {
"hf_api_token": ("STRING", {"default": ""}),
},
}
def generate(
self,
prompt: str,
model: str,
lora_weights: str,
lora_scale: float,
aspect_ratio: str,
api_key: str,
hf_api_token: str = "",
):
key = resolve_api_key(api_key)
payload: dict = {
"input": {
"prompt": prompt,
"lora_weights": lora_weights,
"lora_scale": lora_scale,
"aspect_ratio": aspect_ratio,
}
}
add_hf_token(payload, hf_api_token)
data = call_api_with_fallback(model, payload, key)
tensor = generation_url_to_tensor(data)
return (tensor,)