Spaces:
Running
on
Zero
Running
on
Zero
Update ominicontrol.py
Browse files- ominicontrol.py +38 -10
ominicontrol.py
CHANGED
@@ -3,15 +3,14 @@ from diffusers.pipelines import FluxPipeline
|
|
3 |
from OminiControl.src.flux.condition import Condition
|
4 |
from PIL import Image
|
5 |
import random
|
6 |
-
import os
|
7 |
|
8 |
from OminiControl.src.flux.generate import generate, seed_everything
|
9 |
|
10 |
-
|
11 |
|
12 |
print("Loading model...")
|
13 |
pipe = FluxPipeline.from_pretrained(
|
14 |
-
"black-forest-labs/FLUX.1-dev", torch_dtype=torch.bfloat16
|
15 |
)
|
16 |
pipe = pipe.to("cuda")
|
17 |
|
@@ -21,29 +20,24 @@ pipe.load_lora_weights(
|
|
21 |
"Yuanshi/OminiControlStyle",
|
22 |
weight_name=f"v0/ghibli.safetensors",
|
23 |
adapter_name="ghibli",
|
24 |
-
token=HF_TOKEN
|
25 |
)
|
26 |
pipe.load_lora_weights(
|
27 |
"Yuanshi/OminiControlStyle",
|
28 |
weight_name=f"v0/irasutoya.safetensors",
|
29 |
adapter_name="irasutoya",
|
30 |
-
token=HF_TOKEN
|
31 |
)
|
32 |
pipe.load_lora_weights(
|
33 |
"Yuanshi/OminiControlStyle",
|
34 |
weight_name=f"v0/simpsons.safetensors",
|
35 |
adapter_name="simpsons",
|
36 |
-
token=HF_TOKEN
|
37 |
)
|
38 |
pipe.load_lora_weights(
|
39 |
"Yuanshi/OminiControlStyle",
|
40 |
weight_name=f"v0/snoopy.safetensors",
|
41 |
adapter_name="snoopy",
|
42 |
-
token=HF_TOKEN
|
43 |
)
|
44 |
|
45 |
|
46 |
-
|
47 |
def generate_image(
|
48 |
image,
|
49 |
style,
|
@@ -69,7 +63,7 @@ def generate_image(
|
|
69 |
"The Simpsons": "simpsons",
|
70 |
"Snoopy": "snoopy",
|
71 |
}[style]
|
72 |
-
pipe.set_adapters(activate_adapter_name)
|
73 |
|
74 |
factor = 512 / max(image.size)
|
75 |
image = resize(
|
@@ -125,5 +119,39 @@ def generate_image(
|
|
125 |
default_lora=True,
|
126 |
max_sequence_length=32,
|
127 |
).images[0]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
128 |
|
129 |
-
|
|
|
3 |
from OminiControl.src.flux.condition import Condition
|
4 |
from PIL import Image
|
5 |
import random
|
|
|
6 |
|
7 |
from OminiControl.src.flux.generate import generate, seed_everything
|
8 |
|
9 |
+
from log import insert_log, log_image
|
10 |
|
11 |
print("Loading model...")
|
12 |
pipe = FluxPipeline.from_pretrained(
|
13 |
+
"black-forest-labs/FLUX.1-dev", torch_dtype=torch.bfloat16
|
14 |
)
|
15 |
pipe = pipe.to("cuda")
|
16 |
|
|
|
20 |
"Yuanshi/OminiControlStyle",
|
21 |
weight_name=f"v0/ghibli.safetensors",
|
22 |
adapter_name="ghibli",
|
|
|
23 |
)
|
24 |
pipe.load_lora_weights(
|
25 |
"Yuanshi/OminiControlStyle",
|
26 |
weight_name=f"v0/irasutoya.safetensors",
|
27 |
adapter_name="irasutoya",
|
|
|
28 |
)
|
29 |
pipe.load_lora_weights(
|
30 |
"Yuanshi/OminiControlStyle",
|
31 |
weight_name=f"v0/simpsons.safetensors",
|
32 |
adapter_name="simpsons",
|
|
|
33 |
)
|
34 |
pipe.load_lora_weights(
|
35 |
"Yuanshi/OminiControlStyle",
|
36 |
weight_name=f"v0/snoopy.safetensors",
|
37 |
adapter_name="snoopy",
|
|
|
38 |
)
|
39 |
|
40 |
|
|
|
41 |
def generate_image(
|
42 |
image,
|
43 |
style,
|
|
|
63 |
"The Simpsons": "simpsons",
|
64 |
"Snoopy": "snoopy",
|
65 |
}[style]
|
66 |
+
# pipe.set_adapters(activate_adapter_name)
|
67 |
|
68 |
factor = 512 / max(image.size)
|
69 |
image = resize(
|
|
|
119 |
default_lora=True,
|
120 |
max_sequence_length=32,
|
121 |
).images[0]
|
122 |
+
# result_img = image
|
123 |
+
|
124 |
+
condition_id = log_image(result_img)
|
125 |
+
result_id = log_image(result_img)
|
126 |
+
|
127 |
+
log_data = {
|
128 |
+
"condition": condition_id,
|
129 |
+
"result": result_id,
|
130 |
+
"prompt": "",
|
131 |
+
"inference_mode": inference_mode,
|
132 |
+
"image_guidance_scale": image_guidance,
|
133 |
+
"seed": seed,
|
134 |
+
"steps": steps,
|
135 |
+
"width": width,
|
136 |
+
"height": height,
|
137 |
+
}
|
138 |
+
log_data = {k: str(v) for k, v in log_data.items()}
|
139 |
+
|
140 |
+
_, log_id = insert_log("inference", log_data)
|
141 |
+
|
142 |
+
print(f"Image log ID: {log_id}")
|
143 |
+
|
144 |
+
return result_img, log_id
|
145 |
+
|
146 |
+
|
147 |
+
def vote_feedback(
|
148 |
+
log_id,
|
149 |
+
feedback,
|
150 |
+
):
|
151 |
+
log_data = {
|
152 |
+
"log_id": log_id,
|
153 |
+
"feedback": feedback,
|
154 |
+
}
|
155 |
+
log_data = {k: str(v) for k, v in log_data.items()}
|
156 |
|
157 |
+
insert_log("feedback", log_data)
|