Spaces:
Running
on
Zero
Running
on
Zero
Update app.py
Browse files
app.py
CHANGED
@@ -15,8 +15,8 @@ translator = pipeline("translation", model="Helsinki-NLP/opus-mt-ko-en")
|
|
15 |
|
16 |
# ๊ธฐ๋ณธ ๋ชจ๋ธ ๋ฐ LoRA ์ค์
|
17 |
base_model = "black-forest-labs/FLUX.1-dev"
|
18 |
-
model_lora_repo = "Motas/Flux_Fashion_Photography_Style"
|
19 |
-
clothes_lora_repo = "prithivMLmods/Canopus-Clothing-Flux-LoRA"
|
20 |
|
21 |
pipe = DiffusionPipeline.from_pretrained(base_model, torch_dtype=torch.bfloat16)
|
22 |
pipe.to("cuda")
|
@@ -38,7 +38,9 @@ clothes_examples = [
|
|
38 |
|
39 |
@spaces.GPU()
|
40 |
def generate_fashion(prompt, mode, cfg_scale, steps, randomize_seed, seed, width, height, lora_scale, progress=gr.Progress(track_tqdm=True)):
|
41 |
-
|
|
|
|
|
42 |
def contains_korean(text):
|
43 |
return any(ord('๊ฐ') <= ord(char) <= ord('ํฃ') for char in text)
|
44 |
|
@@ -48,7 +50,6 @@ def generate_fashion(prompt, mode, cfg_scale, steps, randomize_seed, seed, width
|
|
48 |
else:
|
49 |
actual_prompt = prompt
|
50 |
|
51 |
-
# ๋ชจ๋์ ๋ฐ๋ฅธ LoRA ๋ฐ ํธ๋ฆฌ๊ฑฐ์๋ ์ค์
|
52 |
if mode == "ํจ์
๋ชจ๋ธ ์์ฑ":
|
53 |
pipe.load_lora_weights(model_lora_repo)
|
54 |
trigger_word = "fashion photography, professional model"
|
@@ -60,12 +61,6 @@ def generate_fashion(prompt, mode, cfg_scale, steps, randomize_seed, seed, width
|
|
60 |
seed = random.randint(0, MAX_SEED)
|
61 |
generator = torch.Generator(device="cuda").manual_seed(seed)
|
62 |
|
63 |
-
progress(0, "Starting fashion generation...")
|
64 |
-
|
65 |
-
for i in range(1, steps + 1):
|
66 |
-
if i % (steps // 10) == 0:
|
67 |
-
progress(i / steps * 100, f"Processing step {i} of {steps}...")
|
68 |
-
|
69 |
image = pipe(
|
70 |
prompt=f"{actual_prompt} {trigger_word}",
|
71 |
num_inference_steps=steps,
|
@@ -76,48 +71,43 @@ def generate_fashion(prompt, mode, cfg_scale, steps, randomize_seed, seed, width
|
|
76 |
joint_attention_kwargs={"scale": lora_scale},
|
77 |
).images[0]
|
78 |
|
79 |
-
progress(100, "Completed!")
|
80 |
return image, seed
|
81 |
|
82 |
-
def update_examples(mode):
|
83 |
-
if mode == "ํจ์
๋ชจ๋ธ ์์ฑ":
|
84 |
-
return gr.Examples(examples=model_examples)
|
85 |
-
else:
|
86 |
-
return gr.Examples(examples=clothes_examples)
|
87 |
-
|
88 |
with gr.Blocks(theme="Yntec/HaleyCH_Theme_Orange") as app:
|
89 |
gr.Markdown("# ๐ญ Fashion AI Studio")
|
90 |
gr.Markdown("AI๋ฅผ ์ฌ์ฉํ์ฌ ํจ์
๋ชจ๋ธ๊ณผ ์๋ฅ๋ฅผ ์์ฑํด๋ณด์ธ์")
|
91 |
|
92 |
with gr.Column():
|
93 |
-
# ๋ชจ๋ ์ ํ
|
94 |
mode = gr.Radio(
|
95 |
choices=["ํจ์
๋ชจ๋ธ ์์ฑ", "ํจ์
์๋ฅ ์์ฑ"],
|
96 |
label="์์ฑ ๋ชจ๋",
|
97 |
value="ํจ์
๋ชจ๋ธ ์์ฑ"
|
98 |
)
|
99 |
|
100 |
-
# ํ๋กฌํํธ ์
๋ ฅ
|
101 |
prompt = gr.TextArea(
|
102 |
label="โ๏ธ ํจ์
์ค๋ช
(ํ๊ธ ๋๋ ์์ด)",
|
103 |
placeholder="ํจ์
๋ชจ๋ธ์ด๋ ์๋ฅ๋ฅผ ์ค๋ช
ํ์ธ์...",
|
104 |
lines=3
|
105 |
)
|
106 |
|
107 |
-
# ์์
|
108 |
-
with gr.Column() as
|
109 |
-
|
110 |
examples=model_examples,
|
111 |
inputs=prompt,
|
112 |
-
label="์์
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
113 |
)
|
114 |
|
115 |
-
# ๊ฒฐ๊ณผ ์ด๋ฏธ์ง
|
116 |
result = gr.Image(label="์์ฑ๋ ์ด๋ฏธ์ง")
|
117 |
-
|
118 |
generate_button = gr.Button("๐ ์ด๋ฏธ์ง ์์ฑ")
|
119 |
|
120 |
-
# ๊ณ ๊ธ ์ค์
|
121 |
with gr.Accordion("๐จ ๊ณ ๊ธ ์ค์ ", open=False):
|
122 |
with gr.Row():
|
123 |
cfg_scale = gr.Slider(label="CFG Scale", minimum=1, maximum=20, value=7.0)
|
@@ -132,11 +122,16 @@ with gr.Blocks(theme="Yntec/HaleyCH_Theme_Orange") as app:
|
|
132 |
randomize_seed = gr.Checkbox(True, label="์๋ ๋๋คํ")
|
133 |
seed = gr.Slider(label="Seed", minimum=0, maximum=MAX_SEED, value=42)
|
134 |
|
135 |
-
|
|
|
|
|
|
|
|
|
|
|
136 |
mode.change(
|
137 |
-
fn=
|
138 |
inputs=[mode],
|
139 |
-
outputs=[
|
140 |
)
|
141 |
|
142 |
generate_button.click(
|
|
|
15 |
|
16 |
# ๊ธฐ๋ณธ ๋ชจ๋ธ ๋ฐ LoRA ์ค์
|
17 |
base_model = "black-forest-labs/FLUX.1-dev"
|
18 |
+
model_lora_repo = "Motas/Flux_Fashion_Photography_Style"
|
19 |
+
clothes_lora_repo = "prithivMLmods/Canopus-Clothing-Flux-LoRA"
|
20 |
|
21 |
pipe = DiffusionPipeline.from_pretrained(base_model, torch_dtype=torch.bfloat16)
|
22 |
pipe.to("cuda")
|
|
|
38 |
|
39 |
@spaces.GPU()
|
40 |
def generate_fashion(prompt, mode, cfg_scale, steps, randomize_seed, seed, width, height, lora_scale, progress=gr.Progress(track_tqdm=True)):
|
41 |
+
if not prompt:
|
42 |
+
return None, seed
|
43 |
+
|
44 |
def contains_korean(text):
|
45 |
return any(ord('๊ฐ') <= ord(char) <= ord('ํฃ') for char in text)
|
46 |
|
|
|
50 |
else:
|
51 |
actual_prompt = prompt
|
52 |
|
|
|
53 |
if mode == "ํจ์
๋ชจ๋ธ ์์ฑ":
|
54 |
pipe.load_lora_weights(model_lora_repo)
|
55 |
trigger_word = "fashion photography, professional model"
|
|
|
61 |
seed = random.randint(0, MAX_SEED)
|
62 |
generator = torch.Generator(device="cuda").manual_seed(seed)
|
63 |
|
|
|
|
|
|
|
|
|
|
|
|
|
64 |
image = pipe(
|
65 |
prompt=f"{actual_prompt} {trigger_word}",
|
66 |
num_inference_steps=steps,
|
|
|
71 |
joint_attention_kwargs={"scale": lora_scale},
|
72 |
).images[0]
|
73 |
|
|
|
74 |
return image, seed
|
75 |
|
|
|
|
|
|
|
|
|
|
|
|
|
76 |
with gr.Blocks(theme="Yntec/HaleyCH_Theme_Orange") as app:
|
77 |
gr.Markdown("# ๐ญ Fashion AI Studio")
|
78 |
gr.Markdown("AI๋ฅผ ์ฌ์ฉํ์ฌ ํจ์
๋ชจ๋ธ๊ณผ ์๋ฅ๋ฅผ ์์ฑํด๋ณด์ธ์")
|
79 |
|
80 |
with gr.Column():
|
|
|
81 |
mode = gr.Radio(
|
82 |
choices=["ํจ์
๋ชจ๋ธ ์์ฑ", "ํจ์
์๋ฅ ์์ฑ"],
|
83 |
label="์์ฑ ๋ชจ๋",
|
84 |
value="ํจ์
๋ชจ๋ธ ์์ฑ"
|
85 |
)
|
86 |
|
|
|
87 |
prompt = gr.TextArea(
|
88 |
label="โ๏ธ ํจ์
์ค๋ช
(ํ๊ธ ๋๋ ์์ด)",
|
89 |
placeholder="ํจ์
๋ชจ๋ธ์ด๋ ์๋ฅ๋ฅผ ์ค๋ช
ํ์ธ์...",
|
90 |
lines=3
|
91 |
)
|
92 |
|
93 |
+
# ์์ ์น์
์ ๋ชจ๋๋ณ๋ก ๋ถ๋ฆฌ
|
94 |
+
with gr.Column(visible=True) as model_examples_container:
|
95 |
+
gr.Examples(
|
96 |
examples=model_examples,
|
97 |
inputs=prompt,
|
98 |
+
label="ํจ์
๋ชจ๋ธ ์์"
|
99 |
+
)
|
100 |
+
|
101 |
+
with gr.Column(visible=False) as clothes_examples_container:
|
102 |
+
gr.Examples(
|
103 |
+
examples=clothes_examples,
|
104 |
+
inputs=prompt,
|
105 |
+
label="ํจ์
์๋ฅ ์์"
|
106 |
)
|
107 |
|
|
|
108 |
result = gr.Image(label="์์ฑ๋ ์ด๋ฏธ์ง")
|
|
|
109 |
generate_button = gr.Button("๐ ์ด๋ฏธ์ง ์์ฑ")
|
110 |
|
|
|
111 |
with gr.Accordion("๐จ ๊ณ ๊ธ ์ค์ ", open=False):
|
112 |
with gr.Row():
|
113 |
cfg_scale = gr.Slider(label="CFG Scale", minimum=1, maximum=20, value=7.0)
|
|
|
122 |
randomize_seed = gr.Checkbox(True, label="์๋ ๋๋คํ")
|
123 |
seed = gr.Slider(label="Seed", minimum=0, maximum=MAX_SEED, value=42)
|
124 |
|
125 |
+
def update_visibility(mode):
|
126 |
+
return (
|
127 |
+
gr.update(visible=(mode == "ํจ์
๋ชจ๋ธ ์์ฑ")),
|
128 |
+
gr.update(visible=(mode == "ํจ์
์๋ฅ ์์ฑ"))
|
129 |
+
)
|
130 |
+
|
131 |
mode.change(
|
132 |
+
fn=update_visibility,
|
133 |
inputs=[mode],
|
134 |
+
outputs=[model_examples_container, clothes_examples_container]
|
135 |
)
|
136 |
|
137 |
generate_button.click(
|