Spaces:
Running
on
Zero
Running
on
Zero
Update app.py
Browse files
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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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"{
|
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="
|
80 |
lines=5
|
81 |
)
|
82 |
|
@@ -156,7 +171,7 @@ with gr.Blocks(css=css) as app:
|
|
156 |
)
|
157 |
|
158 |
generate_button.click(
|
159 |
-
|
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 |
)
|