Update app.py
Browse files
app.py
CHANGED
@@ -6,6 +6,7 @@ import gradio as gr
|
|
6 |
import torch
|
7 |
from einops import rearrange
|
8 |
from PIL import Image
|
|
|
9 |
|
10 |
from flux.cli import SamplingOptions
|
11 |
from flux.sampling import denoise, get_noise, get_schedule, prepare, unpack
|
@@ -13,6 +14,8 @@ from flux.util import load_ae, load_clip, load_flow_model, load_t5
|
|
13 |
from pulid.pipeline_flux import PuLIDPipeline
|
14 |
from pulid.utils import resize_numpy_image_long
|
15 |
|
|
|
|
|
16 |
|
17 |
def get_models(name: str, device: torch.device, offload: bool):
|
18 |
t5 = load_t5(device, max_length=128)
|
@@ -57,6 +60,11 @@ def generate_image(
|
|
57 |
timestep_to_start_cfg=1,
|
58 |
max_sequence_length=128,
|
59 |
):
|
|
|
|
|
|
|
|
|
|
|
60 |
flux_generator.t5.max_length = max_sequence_length
|
61 |
|
62 |
seed = int(seed)
|
@@ -157,31 +165,33 @@ def create_demo(args, model_name: str, device: str = "cuda" if torch.cuda.is_ava
|
|
157 |
offload: bool = False):
|
158 |
|
159 |
with gr.Blocks(theme="Nymbo/Nymbo_Theme", css=css) as demo:
|
|
|
|
|
160 |
|
161 |
with gr.Row():
|
162 |
with gr.Column():
|
163 |
-
prompt = gr.Textbox(label="
|
164 |
-
id_image = gr.Image(label="ID
|
165 |
-
generate_btn = gr.Button("
|
166 |
|
167 |
with gr.Column():
|
168 |
-
output_image = gr.Image(label="
|
169 |
|
170 |
with gr.Row():
|
171 |
with gr.Column():
|
172 |
-
gr.Markdown("##
|
173 |
|
174 |
all_examples = [
|
175 |
-
['
|
176 |
-
['
|
177 |
-
['
|
178 |
-
['
|
179 |
-
['
|
180 |
-
['
|
181 |
-
['
|
182 |
-
['
|
183 |
-
['
|
184 |
-
['
|
185 |
]
|
186 |
|
187 |
example_images = [example[1] for example in all_examples]
|
@@ -189,7 +199,7 @@ def create_demo(args, model_name: str, device: str = "cuda" if torch.cuda.is_ava
|
|
189 |
|
190 |
gallery = gr.Gallery(
|
191 |
value=list(zip(example_images, example_captions)),
|
192 |
-
label="
|
193 |
show_label=False,
|
194 |
elem_id="gallery",
|
195 |
columns=5,
|
@@ -219,7 +229,7 @@ def create_demo(args, model_name: str, device: str = "cuda" if torch.cuda.is_ava
|
|
219 |
prompt,
|
220 |
id_image,
|
221 |
gr.Slider(0.0, 3.0, 1, step=0.05, visible=False), # id_weight
|
222 |
-
gr.Textbox("
|
223 |
gr.Slider(1.0, 10.0, 1, step=0.1, visible=False), # true_cfg
|
224 |
gr.Slider(0, 20, 1, step=1, visible=False), # timestep_to_start_cfg
|
225 |
gr.Slider(128, 512, 128, step=128, visible=False), # max_sequence_length
|
@@ -234,13 +244,13 @@ if __name__ == "__main__":
|
|
234 |
|
235 |
parser = argparse.ArgumentParser(description="PuLID for FLUX.1-dev")
|
236 |
parser.add_argument("--name", type=str, default="flux-dev", choices=list('flux-dev'),
|
237 |
-
help="
|
238 |
parser.add_argument("--device", type=str, default="cuda" if torch.cuda.is_available() else "cpu",
|
239 |
-
help="
|
240 |
-
parser.add_argument("--offload", action="store_true", help="
|
241 |
-
parser.add_argument("--port", type=int, default=8080, help="
|
242 |
-
parser.add_argument("--dev", action='store_true', help="
|
243 |
-
parser.add_argument("--pretrained_model", type=str, help='
|
244 |
args = parser.parse_args()
|
245 |
|
246 |
import huggingface_hub
|
|
|
6 |
import torch
|
7 |
from einops import rearrange
|
8 |
from PIL import Image
|
9 |
+
from transformers import pipeline
|
10 |
|
11 |
from flux.cli import SamplingOptions
|
12 |
from flux.sampling import denoise, get_noise, get_schedule, prepare, unpack
|
|
|
14 |
from pulid.pipeline_flux import PuLIDPipeline
|
15 |
from pulid.utils import resize_numpy_image_long
|
16 |
|
17 |
+
# ํ์ ๋ฒ์ญ ๋ชจ๋ธ ๋ก๋
|
18 |
+
translator = pipeline("translation", model="Helsinki-NLP/opus-mt-ko-en")
|
19 |
|
20 |
def get_models(name: str, device: torch.device, offload: bool):
|
21 |
t5 = load_t5(device, max_length=128)
|
|
|
60 |
timestep_to_start_cfg=1,
|
61 |
max_sequence_length=128,
|
62 |
):
|
63 |
+
# ํ๊ธ ํ๋กฌํํธ๋ฅผ ์์ด๋ก ๋ฒ์ญ
|
64 |
+
if any('\u3131' <= c <= '\u318E' or '\uAC00' <= c <= '\uD7A3' for c in prompt):
|
65 |
+
translated = translator(prompt)[0]['translation_text']
|
66 |
+
prompt = translated
|
67 |
+
|
68 |
flux_generator.t5.max_length = max_sequence_length
|
69 |
|
70 |
seed = int(seed)
|
|
|
165 |
offload: bool = False):
|
166 |
|
167 |
with gr.Blocks(theme="Nymbo/Nymbo_Theme", css=css) as demo:
|
168 |
+
gr.Markdown("# ์ ๋ชฉ")
|
169 |
+
gr.Markdown("## ์ค๋ช
")
|
170 |
|
171 |
with gr.Row():
|
172 |
with gr.Column():
|
173 |
+
prompt = gr.Textbox(label="ํ๋กฌํํธ", value="์ด์ํ, ์๊ฐ, ์ํ์ ")
|
174 |
+
id_image = gr.Image(label="ID ์ด๋ฏธ์ง", source="webcam", type="numpy")
|
175 |
+
generate_btn = gr.Button("์์ฑ")
|
176 |
|
177 |
with gr.Column():
|
178 |
+
output_image = gr.Image(label="์์ฑ๋ ์ด๋ฏธ์ง")
|
179 |
|
180 |
with gr.Row():
|
181 |
with gr.Column():
|
182 |
+
gr.Markdown("## ์์")
|
183 |
|
184 |
all_examples = [
|
185 |
+
['์ฌ์๊ฐ \"PuLID for FLUX\"๋ผ๊ณ ์ฐ์ธ ๋น๋๋ ๋
น์ ํ์งํ์ ๋ค๊ณ ์๋ค', 'example_inputs/liuyifei.png'],
|
186 |
+
['์๋ชจ์ต ์ด์ํ', 'example_inputs/liuyifei.png'],
|
187 |
+
['VR ๊ธฐ์ ๋ถ์๊ธฐ์ ํฐ ๋จธ๋ฆฌ ์ฌ์ฑ', 'example_inputs/liuyifei.png'],
|
188 |
+
['์ด๋ฆฐ ์์ด๊ฐ ์์ด์คํฌ๋ฆผ์ ๋จน๊ณ ์๋ค', 'example_inputs/liuyifei.png'],
|
189 |
+
['๋จ์๊ฐ \"PuLID for FLUX\"๋ผ๊ณ ์ฐ์ธ ํ์งํ์ ๋ค๊ณ ์๋ค, ๊ฒจ์ธ, ๋ ๋ด๋ฆผ, ์ฐ ์ ์', 'example_inputs/pengwei.jpg'],
|
190 |
+
['์ด์ํ, ์ด๋ถ ์กฐ๋ช
', 'example_inputs/pengwei.jpg'],
|
191 |
+
['25์ธ ๋จ์ฑ์ ์ด๋์ด ํ๋กํ ์ฌ์ง, ์
์์ ์ฐ๊ธฐ๊ฐ ๋์ค๊ณ ์์', 'example_inputs/pengwei.jpg'],
|
192 |
+
['๋ฏธ๊ตญ ๋งํ ์คํ์ผ, ์๋
1๋ช
', 'example_inputs/pengwei.jpg'],
|
193 |
+
['์ด์ํ, ํฝ์ฌ ์คํ์ผ', 'example_inputs/pengwei.jpg'],
|
194 |
+
['์ด์ํ, ์ผ์ ์กฐ๊ฐ์', 'example_inputs/lecun.jpg'],
|
195 |
]
|
196 |
|
197 |
example_images = [example[1] for example in all_examples]
|
|
|
199 |
|
200 |
gallery = gr.Gallery(
|
201 |
value=list(zip(example_images, example_captions)),
|
202 |
+
label="์์ ๊ฐค๋ฌ๋ฆฌ",
|
203 |
show_label=False,
|
204 |
elem_id="gallery",
|
205 |
columns=5,
|
|
|
229 |
prompt,
|
230 |
id_image,
|
231 |
gr.Slider(0.0, 3.0, 1, step=0.05, visible=False), # id_weight
|
232 |
+
gr.Textbox("์ ํ์ง, ์ต์
์ ํ์ง, ํ
์คํธ, ์๋ช
, ์ํฐ๋งํฌ, ์ฌ๋ถ์ ํ๋ค๋ฆฌ", visible=False), # neg_prompt
|
233 |
gr.Slider(1.0, 10.0, 1, step=0.1, visible=False), # true_cfg
|
234 |
gr.Slider(0, 20, 1, step=1, visible=False), # timestep_to_start_cfg
|
235 |
gr.Slider(128, 512, 128, step=128, visible=False), # max_sequence_length
|
|
|
244 |
|
245 |
parser = argparse.ArgumentParser(description="PuLID for FLUX.1-dev")
|
246 |
parser.add_argument("--name", type=str, default="flux-dev", choices=list('flux-dev'),
|
247 |
+
help="ํ์ฌ๋ flux-dev๋ง ์ง์ํฉ๋๋ค")
|
248 |
parser.add_argument("--device", type=str, default="cuda" if torch.cuda.is_available() else "cpu",
|
249 |
+
help="์ฌ์ฉํ ๋๋ฐ์ด์ค")
|
250 |
+
parser.add_argument("--offload", action="store_true", help="์ฌ์ฉํ์ง ์์ ๋ ๋ชจ๋ธ์ CPU๋ก ์ฎ๊น๋๋ค")
|
251 |
+
parser.add_argument("--port", type=int, default=8080, help="์ฌ์ฉํ ํฌํธ")
|
252 |
+
parser.add_argument("--dev", action='store_true', help="๊ฐ๋ฐ ๋ชจ๋")
|
253 |
+
parser.add_argument("--pretrained_model", type=str, help='๊ฐ๋ฐ์ฉ')
|
254 |
args = parser.parse_args()
|
255 |
|
256 |
import huggingface_hub
|