fantos commited on
Commit
6960db5
β€’
1 Parent(s): 4f076f3

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +20 -5
app.py CHANGED
@@ -4,11 +4,15 @@ import torch
4
  from PIL import Image
5
  from diffusers import DiffusionPipeline
6
  import random
 
7
 
8
  torch.backends.cudnn.deterministic = True
9
  torch.backends.cudnn.benchmark = False
10
  torch.backends.cuda.matmul.allow_tf32 = True
11
 
 
 
 
12
  base_model = "black-forest-labs/FLUX.1-dev"
13
  pipe = DiffusionPipeline.from_pretrained(base_model, torch_dtype=torch.bfloat16)
14
 
@@ -21,7 +25,18 @@ pipe.to("cuda")
21
  MAX_SEED = 2**32-1
22
 
23
  @spaces.GPU()
24
- def run_lora(prompt, cfg_scale, steps, randomize_seed, seed, width, height, lora_scale, progress=gr.Progress(track_tqdm=True)):
 
 
 
 
 
 
 
 
 
 
 
25
  if randomize_seed:
26
  seed = random.randint(0, MAX_SEED)
27
  generator = torch.Generator(device="cuda").manual_seed(seed)
@@ -33,7 +48,7 @@ def run_lora(prompt, cfg_scale, steps, randomize_seed, seed, width, height, lora
33
  progress(i / steps * 100, f"Processing step {i} of {steps}...")
34
 
35
  image = pipe(
36
- prompt=f"{prompt} {trigger_word}",
37
  num_inference_steps=steps,
38
  guidance_scale=cfg_scale,
39
  width=width,
@@ -75,8 +90,8 @@ with gr.Blocks(css=css) as app:
75
  with gr.Column(scale=3):
76
  with gr.Group(elem_classes="parameter-box"):
77
  prompt = gr.TextArea(
78
- label="✍️ Your Prompt",
79
- placeholder="Describe the image you want to generate...",
80
  lines=5
81
  )
82
 
@@ -156,7 +171,7 @@ with gr.Blocks(css=css) as app:
156
  )
157
 
158
  generate_button.click(
159
- run_lora,
160
  inputs=[prompt, cfg_scale, steps, randomize_seed, seed, width, height, lora_scale],
161
  outputs=[result, seed]
162
  )
 
4
  from PIL import Image
5
  from diffusers import DiffusionPipeline
6
  import random
7
+ from transformers import pipeline
8
 
9
  torch.backends.cudnn.deterministic = True
10
  torch.backends.cudnn.benchmark = False
11
  torch.backends.cuda.matmul.allow_tf32 = True
12
 
13
+ # λ²ˆμ—­ λͺ¨λΈ μ΄ˆκΈ°ν™”
14
+ translator = pipeline("translation", model="Helsinki-NLP/opus-mt-ko-en")
15
+
16
  base_model = "black-forest-labs/FLUX.1-dev"
17
  pipe = DiffusionPipeline.from_pretrained(base_model, torch_dtype=torch.bfloat16)
18
 
 
25
  MAX_SEED = 2**32-1
26
 
27
  @spaces.GPU()
28
+ def translate_and_generate(prompt, cfg_scale, steps, randomize_seed, seed, width, height, lora_scale, progress=gr.Progress(track_tqdm=True)):
29
+ # ν•œκΈ€ 감지 및 λ²ˆμ—­
30
+ def contains_korean(text):
31
+ return any(ord('κ°€') <= ord(char) <= ord('힣') for char in text)
32
+
33
+ if contains_korean(prompt):
34
+ # ν•œκΈ€μ„ μ˜μ–΄λ‘œ λ²ˆμ—­
35
+ translated = translator(prompt)[0]['translation_text']
36
+ actual_prompt = translated
37
+ else:
38
+ actual_prompt = prompt
39
+
40
  if randomize_seed:
41
  seed = random.randint(0, MAX_SEED)
42
  generator = torch.Generator(device="cuda").manual_seed(seed)
 
48
  progress(i / steps * 100, f"Processing step {i} of {steps}...")
49
 
50
  image = pipe(
51
+ prompt=f"{actual_prompt} {trigger_word}",
52
  num_inference_steps=steps,
53
  guidance_scale=cfg_scale,
54
  width=width,
 
90
  with gr.Column(scale=3):
91
  with gr.Group(elem_classes="parameter-box"):
92
  prompt = gr.TextArea(
93
+ label="✍️ Your Prompt (ν•œκΈ€ λ˜λŠ” μ˜μ–΄)",
94
+ placeholder="이미지λ₯Ό μ„€λͺ…ν•˜μ„Έμš”... (ν•œκΈ€ μž…λ ₯μ‹œ μžλ™μœΌλ‘œ μ˜μ–΄λ‘œ λ²ˆμ—­λ©λ‹ˆλ‹€)",
95
  lines=5
96
  )
97
 
 
171
  )
172
 
173
  generate_button.click(
174
+ translate_and_generate,
175
  inputs=[prompt, cfg_scale, steps, randomize_seed, seed, width, height, lora_scale],
176
  outputs=[result, seed]
177
  )