Spaces:
Running
on
Zero
Running
on
Zero
Update app.py
Browse files
app.py
CHANGED
@@ -1,14 +1,62 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
import gradio as gr
|
2 |
import spaces
|
3 |
import torch
|
|
|
4 |
from diffusers import FluxKontextPipeline
|
5 |
from diffusers.utils import load_image
|
6 |
from PIL import Image
|
7 |
-
import os
|
8 |
|
9 |
-
#
|
10 |
-
#
|
11 |
-
#
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
12 |
STYLE_LORA_MAP = {
|
13 |
"3D_Chibi": "3D_Chibi_lora_weights.safetensors",
|
14 |
"American_Cartoon": "American_Cartoon_lora_weights.safetensors",
|
@@ -31,116 +79,106 @@ STYLE_LORA_MAP = {
|
|
31 |
"Vector": "Vector_lora_weights.safetensors",
|
32 |
"Picasso": "Picasso_lora_weights.safetensors",
|
33 |
"Macaron": "Macaron_lora_weights.safetensors",
|
34 |
-
"Rick_Morty": "Rick_Morty_lora_weights.safetensors"
|
35 |
}
|
36 |
|
37 |
-
# ----------------------------------------------
|
38 |
-
# Style descriptions (ํดํ์ฉ)
|
39 |
-
# ----------------------------------------------
|
40 |
STYLE_DESCRIPTIONS = {
|
41 |
-
"3D_Chibi": "
|
42 |
-
"American_Cartoon": "
|
43 |
-
"Chinese_Ink": "
|
44 |
-
"Clay_Toy": "
|
45 |
-
"Fabric": "
|
46 |
-
"Ghibli": "
|
47 |
-
"Irasutoya": "
|
48 |
-
"Jojo": "
|
49 |
-
"Oil_Painting": "
|
50 |
-
"Pixel": "
|
51 |
-
"Snoopy": "
|
52 |
-
"Poly": "
|
53 |
-
"LEGO": "
|
54 |
-
"Origami": "
|
55 |
-
"Pop_Art": "
|
56 |
-
"Van_Gogh": "
|
57 |
-
"Paper_Cutting": "
|
58 |
-
"Line": "
|
59 |
-
"Vector": "
|
60 |
-
"Picasso": "
|
61 |
-
"Macaron": "
|
62 |
-
"Rick_Morty": "
|
63 |
}
|
64 |
|
65 |
-
#
|
66 |
-
|
67 |
-
|
68 |
-
|
69 |
-
def get_dtype():
|
70 |
-
"""์ต์ dtype(bf16 ์ง์ ์ bf16, ์๋๋ฉด fp16) ์ ํ"""
|
71 |
-
if torch.cuda.is_available():
|
72 |
-
major, _ = torch.cuda.get_device_capability()
|
73 |
-
if major >= 8: # Ada/Hopper GPU๋ bf16 ๋ณธ๊ฒฉ ์ง์
|
74 |
-
return torch.bfloat16
|
75 |
-
return torch.float16
|
76 |
|
77 |
|
78 |
def load_pipeline():
|
79 |
-
"""
|
80 |
-
global
|
81 |
-
if
|
82 |
-
|
83 |
-
|
84 |
-
|
85 |
-
|
86 |
-
|
87 |
-
|
88 |
-
|
89 |
-
|
90 |
-
|
91 |
-
|
92 |
-
|
93 |
-
|
94 |
-
|
95 |
-
|
96 |
-
|
97 |
|
98 |
-
|
99 |
|
|
|
|
|
|
|
|
|
100 |
|
101 |
-
|
102 |
-
|
103 |
-
input_image,
|
104 |
-
style_name,
|
105 |
-
prompt_suffix,
|
106 |
-
num_inference_steps,
|
107 |
-
guidance_scale,
|
108 |
-
seed,
|
109 |
-
):
|
110 |
-
"""์ ํํ ์คํ์ผ๋ก ์ด๋ฏธ์ง ๋ณํ"""
|
111 |
|
|
|
|
|
|
|
|
|
|
|
|
|
112 |
if input_image is None:
|
113 |
-
gr.Warning("
|
114 |
return None
|
115 |
|
116 |
try:
|
117 |
pipe = load_pipeline()
|
118 |
|
119 |
-
#
|
120 |
-
|
121 |
-
|
122 |
-
|
|
|
123 |
|
124 |
-
# ์ด๋ฏธ์ง
|
125 |
-
img =
|
126 |
img = img.convert("RGB").resize((1024, 1024), Image.Resampling.LANCZOS)
|
127 |
|
128 |
-
# LoRA
|
129 |
lora_file = STYLE_LORA_MAP[style_name]
|
130 |
adapter_name = "style"
|
131 |
-
pipe.load_lora_weights(
|
132 |
-
|
133 |
-
weight_name=lora_file,
|
134 |
-
adapter_name=adapter_name,
|
135 |
-
)
|
136 |
-
pipe.set_adapters([adapter_name], adapter_weights=[1.0])
|
137 |
|
138 |
-
# ํ๋กฌํํธ
|
139 |
-
|
|
|
140 |
if prompt_suffix and prompt_suffix.strip():
|
141 |
prompt += f" {prompt_suffix.strip()}"
|
142 |
|
143 |
-
gr.Info("
|
144 |
|
145 |
result = pipe(
|
146 |
image=img,
|
@@ -152,111 +190,85 @@ def style_transfer(
|
|
152 |
width=1024,
|
153 |
)
|
154 |
|
155 |
-
# LoRA ์ธ๋ก๋
|
156 |
-
pipe.unload_lora_weights()
|
157 |
torch.cuda.empty_cache()
|
158 |
|
159 |
return result.images[0]
|
160 |
|
161 |
except Exception as e:
|
162 |
-
gr.Error(f"๐จ ์ค๋ฅ: {e}")
|
163 |
torch.cuda.empty_cache()
|
|
|
164 |
return None
|
165 |
|
166 |
-
|
167 |
-
|
168 |
-
|
169 |
-
|
170 |
-
|
171 |
with gr.Blocks(title="FLUX.1 Kontext Style Transfer", theme=gr.themes.Soft()) as demo:
|
172 |
-
gr.Markdown(
|
173 |
-
|
174 |
-
|
175 |
-
|
176 |
-
|
177 |
-
)
|
178 |
|
179 |
with gr.Row():
|
180 |
with gr.Column(scale=1):
|
181 |
input_image = gr.Image(label="Upload Image", type="pil", height=400)
|
182 |
-
|
183 |
style_dropdown = gr.Dropdown(
|
184 |
choices=list(STYLE_LORA_MAP.keys()),
|
185 |
value="Ghibli",
|
186 |
label="Select Style",
|
187 |
-
info="Choose from 22 different artistic styles",
|
188 |
-
)
|
189 |
-
|
190 |
-
style_info = gr.Textbox(
|
191 |
-
label="Style Description",
|
192 |
-
value=STYLE_DESCRIPTIONS["Ghibli"],
|
193 |
-
interactive=False,
|
194 |
-
lines=2,
|
195 |
-
)
|
196 |
-
|
197 |
-
prompt_suffix = gr.Textbox(
|
198 |
-
label="Additional Instructions (Optional)",
|
199 |
-
placeholder="์: 'make it more colorful', 'add dramatic lighting' โฆ",
|
200 |
-
lines=2,
|
201 |
)
|
|
|
|
|
202 |
|
203 |
with gr.Accordion("Advanced Settings", open=False):
|
204 |
-
num_steps = gr.Slider(
|
205 |
-
|
206 |
-
|
207 |
-
|
208 |
-
|
209 |
-
label="Inference Steps",
|
210 |
-
info="๋ ๋์์๋ก ํ์งโ ์๋โ",
|
211 |
-
)
|
212 |
-
guidance = gr.Slider(
|
213 |
-
1.0,
|
214 |
-
7.5,
|
215 |
-
value=2.5,
|
216 |
-
step=0.1,
|
217 |
-
label="Guidance Scale",
|
218 |
-
info="ํ๋กฌํํธ ์ค์ ์ ๋",
|
219 |
-
)
|
220 |
-
seed = gr.Number(label="Seed (0 = Random)", value=0)
|
221 |
-
|
222 |
-
generate_btn = gr.Button(
|
223 |
-
"๐จ Transform Image", variant="primary", size="lg"
|
224 |
-
)
|
225 |
|
226 |
with gr.Column(scale=1):
|
227 |
output_image = gr.Image(label="Styled Result", type="pil", height=400)
|
228 |
-
|
229 |
-
|
230 |
-
|
231 |
-
|
232 |
-
|
233 |
-
|
234 |
-
|
235 |
-
|
236 |
-
|
237 |
-
|
238 |
-
|
239 |
-
|
240 |
-
|
241 |
-
|
242 |
-
|
243 |
-
|
244 |
-
|
245 |
-
|
246 |
-
|
247 |
-
guidance,
|
248 |
-
seed,
|
249 |
],
|
250 |
-
|
|
|
|
|
|
|
251 |
)
|
252 |
|
253 |
-
|
254 |
-
|
255 |
-
|
256 |
-
|
257 |
-
|
258 |
-
"""
|
259 |
)
|
260 |
|
|
|
|
|
|
|
|
|
|
|
261 |
if __name__ == "__main__":
|
262 |
-
demo.launch()
|
|
|
1 |
+
"""
|
2 |
+
FLUX.1 Kontext Style Transfer
|
3 |
+
==============================
|
4 |
+
Updated: 2025โ07โ12
|
5 |
+
---------------------------------
|
6 |
+
์ด ์คํฌ๋ฆฝํธ๋ HuggingโฏFace **FLUX.1โKontextโdev** ๋ชจ๋ธ๊ณผ
|
7 |
+
22โฏ์ข
์ ์คํ์ผ LoRA ๊ฐ์ค์น๋ฅผ ์ด์ฉํด ์ด๋ฏธ์ง๋ฅผ ๋ค์ํ ์์
|
8 |
+
์คํ์ผ๋ก ๋ณํํ๋ Gradio ๋ฐ๋ชจ์
๋๋ค.
|
9 |
+
|
10 |
+
์ฃผ์ ๊ฐ์ ์ฌํญ
|
11 |
+
--------------
|
12 |
+
1. **๋ชจ๋ธ ์บ์ฑ**โโย `snapshot_download()`๋ก ์คํ ์์ ์ ํ ๋ฒ๋ง
|
13 |
+
๋ชจ๋ธ๊ณผ LoRA๋ฅผ ์บ์ฑํด ์ดํ GPU ์ก์์๋ ์ฌ๋ค์ด๋ก๋๊ฐ ์๋๋ก
|
14 |
+
ํจ.
|
15 |
+
2. **GPUโฏVRAM ์๋ ํ๋ณ**โโย GPUโฏVRAM์ด 24โฏGBโฏ๋ฏธ๋ง์ด๋ฉด
|
16 |
+
`torch.float16`ย / `enable_sequential_cpu_offload()`๋ฅผ ์๋ ์ ์ฉ.
|
17 |
+
3. **๋จ์ผ ๋ก๋ฉ ๋ฉ์์ง**โโย Gradioย `gr.Info()` ๋ฉ์์ง๊ฐ ์ต์ด 1ํ๋ง
|
18 |
+
ํ์๋๋๋ก ์์ .
|
19 |
+
4. **๋ฒ๊ทธ ํฝ์ค**โโย seed ์ฒ๋ฆฌ, LoRA ์ธ๋ก๋, ์ด๋ฏธ์ง ๋ฆฌ์ฌ์ด์ฆ ๋ก์ง
|
20 |
+
๋ฑ ์ธ๋ถ ์ค๋ฅ ์์ .
|
21 |
+
|
22 |
+
------------------------------------------------------------
|
23 |
+
"""
|
24 |
+
import os
|
25 |
import gradio as gr
|
26 |
import spaces
|
27 |
import torch
|
28 |
+
from huggingface_hub import snapshot_download
|
29 |
from diffusers import FluxKontextPipeline
|
30 |
from diffusers.utils import load_image
|
31 |
from PIL import Image
|
|
|
32 |
|
33 |
+
# ------------------------------------------------------------------
|
34 |
+
# ํ๊ฒฝ ์ค์ & ๋ชจ๋ธย /ย LoRA ์ฌ์ ๋ค์ด๋ก๋
|
35 |
+
# ------------------------------------------------------------------
|
36 |
+
# ํฐ ํ์ผ์ ๋น ๋ฅด๊ฒ ๋ฐ๋๋ก ๊ฐ์ ํ๋๊ทธ ํ์ฑํ
|
37 |
+
os.environ.setdefault("HF_HUB_ENABLE_HF_TRANSFER", "1")
|
38 |
+
|
39 |
+
MODEL_ID = "black-forest-labs/FLUX.1-Kontext-dev"
|
40 |
+
LORA_REPO = "Owen777/Kontext-Style-Loras"
|
41 |
+
CACHE_DIR = os.getenv("HF_HOME", os.path.expanduser("~/.cache/huggingface"))
|
42 |
+
|
43 |
+
# --- ์ต์ด ์คํ ์์๋ง ๋ค์ด๋ก๋(์ด๋ฏธ ์บ์์ ์์ผ๋ฉด ๊ฑด๋๋) ---
|
44 |
+
MODEL_DIR = snapshot_download(
|
45 |
+
repo_id=MODEL_ID,
|
46 |
+
cache_dir=CACHE_DIR,
|
47 |
+
resume_download=True,
|
48 |
+
token=True # HF ํ ํฐ(ํ์ ์ ํ๊ฒฝ๋ณ์ HF_TOKEN ์ง์ )
|
49 |
+
)
|
50 |
+
LORA_DIR = snapshot_download(
|
51 |
+
repo_id=LORA_REPO,
|
52 |
+
cache_dir=CACHE_DIR,
|
53 |
+
resume_download=True,
|
54 |
+
token=True
|
55 |
+
)
|
56 |
+
|
57 |
+
# ------------------------------------------------------------------
|
58 |
+
# ์คํ์ผย โย LoRA ํ์ผ ๋งคํ & ์ค๋ช
|
59 |
+
# ------------------------------------------------------------------
|
60 |
STYLE_LORA_MAP = {
|
61 |
"3D_Chibi": "3D_Chibi_lora_weights.safetensors",
|
62 |
"American_Cartoon": "American_Cartoon_lora_weights.safetensors",
|
|
|
79 |
"Vector": "Vector_lora_weights.safetensors",
|
80 |
"Picasso": "Picasso_lora_weights.safetensors",
|
81 |
"Macaron": "Macaron_lora_weights.safetensors",
|
82 |
+
"Rick_Morty": "Rick_Morty_lora_weights.safetensors",
|
83 |
}
|
84 |
|
|
|
|
|
|
|
85 |
STYLE_DESCRIPTIONS = {
|
86 |
+
"3D_Chibi": "Cute, miniature 3D character style with big heads",
|
87 |
+
"American_Cartoon": "Classic American animation style",
|
88 |
+
"Chinese_Ink": "Traditional Chinese ink painting aesthetic",
|
89 |
+
"Clay_Toy": "Playful clay/plasticine toy appearance",
|
90 |
+
"Fabric": "Soft, textile-like rendering",
|
91 |
+
"Ghibli": "Studio Ghibli's distinctive anime style",
|
92 |
+
"Irasutoya": "Simple, flat Japanese illustration style",
|
93 |
+
"Jojo": "JoJo's Bizarre Adventure manga style",
|
94 |
+
"Oil_Painting": "Classic oil painting texture and strokes",
|
95 |
+
"Pixel": "Retro pixel art style",
|
96 |
+
"Snoopy": "Peanuts comic strip style",
|
97 |
+
"Poly": "Low-poly 3D geometric style",
|
98 |
+
"LEGO": "LEGO brick construction style",
|
99 |
+
"Origami": "Paper folding art style",
|
100 |
+
"Pop_Art": "Bold, colorful pop art style",
|
101 |
+
"Van_Gogh": "Van Gogh's expressive brushstroke style",
|
102 |
+
"Paper_Cutting": "Paper cut-out art style",
|
103 |
+
"Line": "Clean line art/sketch style",
|
104 |
+
"Vector": "Clean vector graphics style",
|
105 |
+
"Picasso": "Cubist art style inspired by Picasso",
|
106 |
+
"Macaron": "Soft, pastel macaron-like style",
|
107 |
+
"Rick_Morty": "Rick and Morty cartoon style",
|
108 |
}
|
109 |
|
110 |
+
# ------------------------------------------------------------------
|
111 |
+
# ํ์ดํ๋ผ์ธ ๋ก๋ (๋จ์ผ ์ธ์คํด์ค)
|
112 |
+
# ------------------------------------------------------------------
|
113 |
+
_pipeline = None # ๋ด๋ถ ๊ธ๋ก๋ฒ ์บ์
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
114 |
|
115 |
|
116 |
def load_pipeline():
|
117 |
+
"""Load (or return cached) FluxKontextPipeline."""
|
118 |
+
global _pipeline
|
119 |
+
if _pipeline is not None:
|
120 |
+
return _pipeline
|
121 |
+
|
122 |
+
# VRAM์ด 24โฏGBย ๋ฏธ๋ง์ด๋ฉด FP16 ์ฌ์ฉ + CPU ์คํ๋ก๋ฉ
|
123 |
+
dtype = torch.bfloat16
|
124 |
+
vram_gb = torch.cuda.get_device_properties(0).total_memory / 1024**3
|
125 |
+
if vram_gb < 24:
|
126 |
+
dtype = torch.float16
|
127 |
+
|
128 |
+
gr.Info("FLUX.1โKontext ํ์ดํ๋ผ์ธ ๋ก๋ฉ ์คโฆย (์ต์ด 1ํ)")
|
129 |
+
|
130 |
+
pipe = FluxKontextPipeline.from_pretrained(
|
131 |
+
MODEL_DIR,
|
132 |
+
torch_dtype=dtype,
|
133 |
+
local_files_only=True,
|
134 |
+
)
|
135 |
|
136 |
+
pipe.to("cuda")
|
137 |
|
138 |
+
if vram_gb < 24:
|
139 |
+
pipe.enable_sequential_cpu_offload()
|
140 |
+
else:
|
141 |
+
pipe.enable_model_cpu_offload()
|
142 |
|
143 |
+
_pipeline = pipe
|
144 |
+
return _pipeline
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
145 |
|
146 |
+
# ------------------------------------------------------------------
|
147 |
+
# ์คํ์ผ ๋ณํ ํจ์ (Spaces GPU ์ก)
|
148 |
+
# ------------------------------------------------------------------
|
149 |
+
@spaces.GPU(duration=600)
|
150 |
+
def style_transfer(input_image, style_name, prompt_suffix, num_inference_steps, guidance_scale, seed):
|
151 |
+
"""Apply selected style to the uploaded image."""
|
152 |
if input_image is None:
|
153 |
+
gr.Warning("Please upload an image first!")
|
154 |
return None
|
155 |
|
156 |
try:
|
157 |
pipe = load_pipeline()
|
158 |
|
159 |
+
# --- Torchย Generator ์ค์ ---
|
160 |
+
if seed > 0:
|
161 |
+
generator = torch.Generator(device="cuda").manual_seed(int(seed))
|
162 |
+
else:
|
163 |
+
generator = None # random
|
164 |
|
165 |
+
# --- ์
๋ ฅ ์ด๋ฏธ์ง ์ ์ฒ๋ฆฌ ---
|
166 |
+
img = input_image if isinstance(input_image, Image.Image) else load_image(input_image)
|
167 |
img = img.convert("RGB").resize((1024, 1024), Image.Resampling.LANCZOS)
|
168 |
|
169 |
+
# --- LoRA ๋ก๋ ---
|
170 |
lora_file = STYLE_LORA_MAP[style_name]
|
171 |
adapter_name = "style"
|
172 |
+
pipe.load_lora_weights(LORA_DIR, weight_name=lora_file, adapter_name=adapter_name)
|
173 |
+
pipe.set_adapters([adapter_name], [1.0])
|
|
|
|
|
|
|
|
|
174 |
|
175 |
+
# --- ํ๋กฌํํธ ๋น๋ ---
|
176 |
+
human_readable_style = style_name.replace("_", " ")
|
177 |
+
prompt = f"Turn this image into the {human_readable_style} style."
|
178 |
if prompt_suffix and prompt_suffix.strip():
|
179 |
prompt += f" {prompt_suffix.strip()}"
|
180 |
|
181 |
+
gr.Info("Generating styled imageโฆ (24โ60โฏs)")
|
182 |
|
183 |
result = pipe(
|
184 |
image=img,
|
|
|
190 |
width=1024,
|
191 |
)
|
192 |
|
193 |
+
# --- LoRA ์ธ๋ก๋ & GPU ๋ฉ๋ชจ๋ฆฌ ํด์ ---
|
194 |
+
pipe.unload_lora_weights(adapter_name=adapter_name)
|
195 |
torch.cuda.empty_cache()
|
196 |
|
197 |
return result.images[0]
|
198 |
|
199 |
except Exception as e:
|
|
|
200 |
torch.cuda.empty_cache()
|
201 |
+
gr.Error(f"Error during style transfer: {e}")
|
202 |
return None
|
203 |
|
204 |
+
# ------------------------------------------------------------------
|
205 |
+
# Gradio UI ์ ์
|
206 |
+
# ------------------------------------------------------------------
|
|
|
|
|
207 |
with gr.Blocks(title="FLUX.1 Kontext Style Transfer", theme=gr.themes.Soft()) as demo:
|
208 |
+
gr.Markdown("""
|
209 |
+
# ๐จ FLUX.1 Kontext Style Transfer
|
210 |
+
|
211 |
+
์
๋ก๋ํ ์ด๋ฏธ์ง๋ฅผ 22โฏ์ข
์ ์์ ์คํ์ผ๋ก ๋ณํํ์ธ์!
|
212 |
+
(๋ชจ๋ธโฏ/โฏLoRA๋ ์ต์ด ์คํ ์์๋ง ๋ค์ด๋ก๋๋๋ฉฐ, ์ดํ ์คํ์ ๋น ๋ฆ
๋๋ค.)
|
213 |
+
""")
|
214 |
|
215 |
with gr.Row():
|
216 |
with gr.Column(scale=1):
|
217 |
input_image = gr.Image(label="Upload Image", type="pil", height=400)
|
|
|
218 |
style_dropdown = gr.Dropdown(
|
219 |
choices=list(STYLE_LORA_MAP.keys()),
|
220 |
value="Ghibli",
|
221 |
label="Select Style",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
222 |
)
|
223 |
+
style_info = gr.Textbox(label="Style Description", value=STYLE_DESCRIPTIONS["Ghibli"], interactive=False, lines=2)
|
224 |
+
prompt_suffix = gr.Textbox(label="Additional Instructions (Optional)", placeholder="e.g. add dramatic lighting", lines=2)
|
225 |
|
226 |
with gr.Accordion("Advanced Settings", open=False):
|
227 |
+
num_steps = gr.Slider(minimum=10, maximum=50, value=24, step=1, label="Inference Steps")
|
228 |
+
guidance = gr.Slider(minimum=1.0, maximum=7.5, value=2.5, step=0.1, label="Guidance Scale")
|
229 |
+
seed = gr.Number(label="Seed (0 = random)", value=42)
|
230 |
+
|
231 |
+
generate_btn = gr.Button("๐จ Transform Image", variant="primary", size="lg")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
232 |
|
233 |
with gr.Column(scale=1):
|
234 |
output_image = gr.Image(label="Styled Result", type="pil", height=400)
|
235 |
+
gr.Markdown("""
|
236 |
+
### ๐ก Tips
|
237 |
+
* ์ด๋ฏธ์ง ํฌ๊ธฐ๋ 1024ร1024๋ก ๋ฆฌ์ฌ์ด์ฆ๋ฉ๋๋ค.
|
238 |
+
* ์ต์ด 1ํย ๋ชจ๋ธย +ย LoRA ๋ค์ด๋ก๋ ํ์๋ **์บ์**๋ฅผ ์ฌ์ฉํ๋ฏ๋ก 10โ20โฏs ๋ด ์๋ฃ๋ฉ๋๋ค.
|
239 |
+
* "Additional Instructions"์ ์๊ฐยท์กฐ๋ช
ยทํจ๊ณผ ๋ฑ์ ์์ด๋ก ๊ฐ๋จํ ์ ์ผ๋ฉด ๊ฒฐ๊ณผ๋ฅผ ์ธ๋ฐํ๊ฒ ์ ์ดํ ์ ์์ต๋๋ค.
|
240 |
+
""")
|
241 |
+
|
242 |
+
# --- ์คํ์ผ ์ค๋ช
์๋ ์
๋ฐ์ดํธ ---
|
243 |
+
def _update_desc(style):
|
244 |
+
return STYLE_DESCRIPTIONS.get(style, "")
|
245 |
+
|
246 |
+
style_dropdown.change(fn=_update_desc, inputs=[style_dropdown], outputs=[style_info])
|
247 |
+
|
248 |
+
# --- ์์ ---
|
249 |
+
gr.Examples(
|
250 |
+
examples=[
|
251 |
+
["https://huggingface.co/datasets/black-forest-labs/kontext-bench/resolve/main/test/images/0003.jpg", "Ghibli", ""],
|
252 |
+
["https://huggingface.co/datasets/black-forest-labs/kontext-bench/resolve/main/test/images/0003.jpg", "3D_Chibi", "make it extra cute"],
|
253 |
+
["https://huggingface.co/datasets/black-forest-labs/kontext-bench/resolve/main/test/images/0003.jpg", "Van_Gogh", "with swirling sky"],
|
|
|
|
|
254 |
],
|
255 |
+
inputs=[input_image, style_dropdown, prompt_suffix],
|
256 |
+
outputs=output_image,
|
257 |
+
fn=lambda img, style, prompt: style_transfer(img, style, prompt, 24, 2.5, 42),
|
258 |
+
cache_examples=False,
|
259 |
)
|
260 |
|
261 |
+
# --- ๋ฒํผ ์ฐ๊ฒฐ ---
|
262 |
+
generate_btn.click(
|
263 |
+
fn=style_transfer,
|
264 |
+
inputs=[input_image, style_dropdown, prompt_suffix, num_steps, guidance, seed],
|
265 |
+
outputs=output_image,
|
|
|
266 |
)
|
267 |
|
268 |
+
gr.Markdown("""
|
269 |
+
---
|
270 |
+
**Created with โค๏ธ by GiniGEN (2025)**
|
271 |
+
""")
|
272 |
+
|
273 |
if __name__ == "__main__":
|
274 |
+
demo.launch(inline=False)
|