fantos commited on
Commit
1666a97
โ€ข
1 Parent(s): 5221f40

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +34 -24
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 = {"canny":0, "tile":1, "depth":2, "blur":3, "openpose":4, "gray":5, "low quality": 6}
61
- strength_mapping = {"canny":0.65, "tile":0.45, "depth":0.55, "blur":0.45, "openpose":0.55, "gray":0.45, "low quality": 0.4}
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 == "canny":
155
  control_image = extract_canny(image_in)
156
- elif control_mode == "depth":
157
  control_image = extract_depth(image_in)
158
- elif control_mode == "openpose":
159
  control_image = extract_openpose(image_in)
160
- elif control_mode == "blur":
161
  control_image = apply_gaussian_blur(image_in)
162
- elif control_mode == "low quality":
163
  control_image = add_gaussian_noise(image_in)
164
- elif control_mode == "gray":
165
  control_image = convert_to_grayscale(image_in)
166
- elif control_mode == "tile":
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="Upload a processed control image", sources=["upload"], type="filepath")
206
- image_in = gr.Image(label="Extract condition from a reference image (Optional)", sources=["upload"], type="filepath")
207
 
208
- prompt = gr.Textbox(label="Prompt", value="best quality")
209
 
210
- with gr.Accordion("Controlnet"):
211
  control_mode = gr.Radio(
212
- ["canny", "depth", "openpose", "gray", "blur", "tile", "low quality"], label="Mode", value="gray",
213
- info="select the control mode, one for all"
214
  )
215
 
216
  control_strength = gr.Slider(
217
- label="control strength",
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="Seed",
226
  minimum=0,
227
  maximum=MAX_SEED,
228
  step=1,
229
  value=42,
230
  )
231
- randomize_seed = gr.Checkbox(label="Randomize seed", value=True)
232
 
233
- with gr.Accordion("Advanced settings", open=False):
234
  with gr.Column():
235
  with gr.Row():
236
- inference_steps = gr.Slider(label="Inference steps", minimum=1, maximum=50, step=1, value=24)
237
- guidance_scale = gr.Slider(label="Guidance scale", minimum=1.0, maximum=10.0, step=0.1, value=3.5)
238
 
239
- submit_btn = gr.Button("Submit")
240
 
241
  with gr.Column():
242
- result = gr.Image(label="Result")
243
- processed_cond = gr.Image(label="Preprocessed Cond")
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,