Spaces:
Running
on
Zero
Running
on
Zero
Update app.py
Browse files
app.py
CHANGED
@@ -11,6 +11,7 @@ from PIL import Image
|
|
11 |
import cv2
|
12 |
import torch
|
13 |
import random
|
|
|
14 |
|
15 |
os.system("pip install -e ./controlnet_aux")
|
16 |
|
@@ -25,6 +26,14 @@ login(token=hf_token)
|
|
25 |
|
26 |
MAX_SEED = np.iinfo(np.int32).max
|
27 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
28 |
def randomize_seed_fn(seed: int, randomize_seed: bool) -> int:
|
29 |
if randomize_seed:
|
30 |
seed = random.randint(0, MAX_SEED)
|
@@ -57,8 +66,8 @@ controlnet = FluxMultiControlNetModel([controlnet])
|
|
57 |
pipe = FluxControlNetPipeline.from_pretrained(base_model, controlnet=controlnet, torch_dtype=torch.bfloat16)
|
58 |
pipe.to("cuda")
|
59 |
|
60 |
-
mode_mapping = {"
|
61 |
-
strength_mapping = {"
|
62 |
|
63 |
canny = CannyDetector()
|
64 |
open_pose = OpenposeDetector.from_pretrained("lllyasviel/Annotators")
|
@@ -147,23 +156,24 @@ def resize_img(input_image, max_side=768, min_side=512, size=None,
|
|
147 |
def infer(cond_in, image_in, prompt, inference_steps, guidance_scale, control_mode, control_strength, seed, progress=gr.Progress(track_tqdm=True)):
|
148 |
|
149 |
control_mode_num = mode_mapping[control_mode]
|
|
|
150 |
|
151 |
if cond_in is None:
|
152 |
if image_in is not None:
|
153 |
image_in = resize_img(load_image(image_in))
|
154 |
-
if control_mode == "
|
155 |
control_image = extract_canny(image_in)
|
156 |
-
elif control_mode == "
|
157 |
control_image = extract_depth(image_in)
|
158 |
-
elif control_mode == "
|
159 |
control_image = extract_openpose(image_in)
|
160 |
-
elif control_mode == "
|
161 |
control_image = apply_gaussian_blur(image_in)
|
162 |
-
elif control_mode == "
|
163 |
control_image = add_gaussian_noise(image_in)
|
164 |
-
elif control_mode == "
|
165 |
control_image = convert_to_grayscale(image_in)
|
166 |
-
elif control_mode == "
|
167 |
control_image = tile(image_in)
|
168 |
else:
|
169 |
control_image = resize_img(load_image(cond_in))
|
@@ -202,19 +212,19 @@ with gr.Blocks(theme="Nymbo/Nymbo_Theme", css=css) as demo:
|
|
202 |
with gr.Column():
|
203 |
|
204 |
with gr.Row(equal_height=True):
|
205 |
-
cond_in = gr.Image(label="
|
206 |
-
image_in = gr.Image(label="
|
207 |
|
208 |
-
prompt = gr.Textbox(label="
|
209 |
|
210 |
-
with gr.Accordion("
|
211 |
control_mode = gr.Radio(
|
212 |
-
["
|
213 |
-
info="
|
214 |
)
|
215 |
|
216 |
control_strength = gr.Slider(
|
217 |
-
label="
|
218 |
minimum=0,
|
219 |
maximum=1.0,
|
220 |
step=0.05,
|
@@ -222,25 +232,25 @@ with gr.Blocks(theme="Nymbo/Nymbo_Theme", css=css) as demo:
|
|
222 |
)
|
223 |
|
224 |
seed = gr.Slider(
|
225 |
-
label="
|
226 |
minimum=0,
|
227 |
maximum=MAX_SEED,
|
228 |
step=1,
|
229 |
value=42,
|
230 |
)
|
231 |
-
randomize_seed = gr.Checkbox(label="
|
232 |
|
233 |
-
with gr.Accordion("
|
234 |
with gr.Column():
|
235 |
with gr.Row():
|
236 |
-
inference_steps = gr.Slider(label="
|
237 |
-
guidance_scale = gr.Slider(label="
|
238 |
|
239 |
-
submit_btn = gr.Button("
|
240 |
|
241 |
with gr.Column():
|
242 |
-
result = gr.Image(label="
|
243 |
-
processed_cond = gr.Image(label="
|
244 |
|
245 |
submit_btn.click(
|
246 |
fn=randomize_seed_fn,
|
|
|
11 |
import cv2
|
12 |
import torch
|
13 |
import random
|
14 |
+
from transformers import pipeline
|
15 |
|
16 |
os.system("pip install -e ./controlnet_aux")
|
17 |
|
|
|
26 |
|
27 |
MAX_SEED = np.iinfo(np.int32).max
|
28 |
|
29 |
+
# ๋ฒ์ญ๊ธฐ ์ค์
|
30 |
+
translator = pipeline("translation", model="Helsinki-NLP/opus-mt-ko-en")
|
31 |
+
|
32 |
+
def translate_to_english(text):
|
33 |
+
if any('\uAC00' <= char <= '\uD7A3' for char in text):
|
34 |
+
return translator(text, max_length=512)[0]['translation_text']
|
35 |
+
return text
|
36 |
+
|
37 |
def randomize_seed_fn(seed: int, randomize_seed: bool) -> int:
|
38 |
if randomize_seed:
|
39 |
seed = random.randint(0, MAX_SEED)
|
|
|
66 |
pipe = FluxControlNetPipeline.from_pretrained(base_model, controlnet=controlnet, torch_dtype=torch.bfloat16)
|
67 |
pipe.to("cuda")
|
68 |
|
69 |
+
mode_mapping = {"์บ๋":0, "ํ์ผ":1, "๊น์ด":2, "๋ธ๋ฌ":3, "์คํํฌ์ฆ":4, "๊ทธ๋ ์ด์ค์ผ์ผ":5, "์ ํ์ง": 6}
|
70 |
+
strength_mapping = {"์บ๋":0.65, "ํ์ผ":0.45, "๊น์ด":0.55, "๋ธ๋ฌ":0.45, "์คํํฌ์ฆ":0.55, "๊ทธ๋ ์ด์ค์ผ์ผ":0.45, "์ ํ์ง": 0.4}
|
71 |
|
72 |
canny = CannyDetector()
|
73 |
open_pose = OpenposeDetector.from_pretrained("lllyasviel/Annotators")
|
|
|
156 |
def infer(cond_in, image_in, prompt, inference_steps, guidance_scale, control_mode, control_strength, seed, progress=gr.Progress(track_tqdm=True)):
|
157 |
|
158 |
control_mode_num = mode_mapping[control_mode]
|
159 |
+
prompt = translate_to_english(prompt)
|
160 |
|
161 |
if cond_in is None:
|
162 |
if image_in is not None:
|
163 |
image_in = resize_img(load_image(image_in))
|
164 |
+
if control_mode == "์บ๋":
|
165 |
control_image = extract_canny(image_in)
|
166 |
+
elif control_mode == "๊น์ด":
|
167 |
control_image = extract_depth(image_in)
|
168 |
+
elif control_mode == "์คํํฌ์ฆ":
|
169 |
control_image = extract_openpose(image_in)
|
170 |
+
elif control_mode == "๋ธ๋ฌ":
|
171 |
control_image = apply_gaussian_blur(image_in)
|
172 |
+
elif control_mode == "์ ํ์ง":
|
173 |
control_image = add_gaussian_noise(image_in)
|
174 |
+
elif control_mode == "๊ทธ๋ ์ด์ค์ผ์ผ":
|
175 |
control_image = convert_to_grayscale(image_in)
|
176 |
+
elif control_mode == "ํ์ผ":
|
177 |
control_image = tile(image_in)
|
178 |
else:
|
179 |
control_image = resize_img(load_image(cond_in))
|
|
|
212 |
with gr.Column():
|
213 |
|
214 |
with gr.Row(equal_height=True):
|
215 |
+
cond_in = gr.Image(label="์ฒ๋ฆฌ๋ ์ปจํธ๋กค ์ด๋ฏธ์ง ์
๋ก๋", sources=["upload"], type="filepath")
|
216 |
+
image_in = gr.Image(label="์ฐธ์กฐ ์ด๋ฏธ์ง์์ ์กฐ๊ฑด ์ถ์ถ (์ ํ์ฌํญ)", sources=["upload"], type="filepath")
|
217 |
|
218 |
+
prompt = gr.Textbox(label="ํ๋กฌํํธ", value="์ต๊ณ ํ์ง")
|
219 |
|
220 |
+
with gr.Accordion("์ปจํธ๋กค๋ท"):
|
221 |
control_mode = gr.Radio(
|
222 |
+
["์บ๋", "๊น์ด", "์คํํฌ์ฆ", "๊ทธ๋ ์ด์ค์ผ์ผ", "๋ธ๋ฌ", "ํ์ผ", "์ ํ์ง"], label="๋ชจ๋", value="๊ทธ๋ ์ด์ค์ผ์ผ",
|
223 |
+
info="์ปจํธ๋กค ๋ชจ๋ ์ ํ, ๋ชจ๋ ์ด๋ฏธ์ง์ ์ ์ฉ๋ฉ๋๋ค"
|
224 |
)
|
225 |
|
226 |
control_strength = gr.Slider(
|
227 |
+
label="์ปจํธ๋กค ๊ฐ๋",
|
228 |
minimum=0,
|
229 |
maximum=1.0,
|
230 |
step=0.05,
|
|
|
232 |
)
|
233 |
|
234 |
seed = gr.Slider(
|
235 |
+
label="์๋",
|
236 |
minimum=0,
|
237 |
maximum=MAX_SEED,
|
238 |
step=1,
|
239 |
value=42,
|
240 |
)
|
241 |
+
randomize_seed = gr.Checkbox(label="์๋ ๋ฌด์์ํ", value=True)
|
242 |
|
243 |
+
with gr.Accordion("๊ณ ๊ธ ์ค์ ", open=False):
|
244 |
with gr.Column():
|
245 |
with gr.Row():
|
246 |
+
inference_steps = gr.Slider(label="์ถ๋ก ๋จ๊ณ", minimum=1, maximum=50, step=1, value=24)
|
247 |
+
guidance_scale = gr.Slider(label="๊ฐ์ด๋์ค ์ค์ผ์ผ", minimum=1.0, maximum=10.0, step=0.1, value=3.5)
|
248 |
|
249 |
+
submit_btn = gr.Button("์ ์ถ")
|
250 |
|
251 |
with gr.Column():
|
252 |
+
result = gr.Image(label="๊ฒฐ๊ณผ")
|
253 |
+
processed_cond = gr.Image(label="์ ์ฒ๋ฆฌ๋ ์กฐ๊ฑด")
|
254 |
|
255 |
submit_btn.click(
|
256 |
fn=randomize_seed_fn,
|