Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -35,7 +35,7 @@ os.environ["TRANSFORMERS_CACHE"] = CACHE_PATH
|
|
| 35 |
os.environ["HF_HUB_CACHE"] = CACHE_PATH
|
| 36 |
os.environ["HF_HOME"] = CACHE_PATH
|
| 37 |
|
| 38 |
-
#
|
| 39 |
class timer:
|
| 40 |
def __init__(self, method_name="timed process"):
|
| 41 |
self.method = method_name
|
|
@@ -65,7 +65,7 @@ pipe.fuse_lora(lora_scale=0.125)
|
|
| 65 |
pipe.to(device="cuda", dtype=torch.bfloat16)
|
| 66 |
|
| 67 |
#######################################
|
| 68 |
-
# 2. Google GenAI
|
| 69 |
#######################################
|
| 70 |
|
| 71 |
def save_binary_file(file_name, data):
|
|
@@ -80,21 +80,16 @@ def generate_by_google_genai(text, file_name, model="gemini-2.0-flash-exp"):
|
|
| 80 |
- file_name: ์๋ณธ ์ด๋ฏธ์ง(์: .png) ๊ฒฝ๋ก
|
| 81 |
- model: ์ฌ์ฉํ gemini ๋ชจ๋ธ ์ด๋ฆ
|
| 82 |
"""
|
| 83 |
-
# (1) ํ๊ฒฝ ๋ณ์์์ API ํค ๊ฐ์ ธ์ค๊ธฐ (ํ์)
|
| 84 |
api_key = os.getenv("GAPI_TOKEN", None)
|
| 85 |
if not api_key:
|
| 86 |
raise ValueError(
|
| 87 |
"GAPI_TOKEN ํ๊ฒฝ ๋ณ์๊ฐ ์ค์ ๋์ง ์์์ต๋๋ค. "
|
| 88 |
-
"Google GenAI API
|
| 89 |
)
|
| 90 |
|
| 91 |
-
# (2) Google Client ์ด๊ธฐํ
|
| 92 |
client = genai.Client(api_key=api_key)
|
| 93 |
-
|
| 94 |
-
# (3) ์ด๋ฏธ์ง ์
๋ก๋
|
| 95 |
files = [client.files.upload(file=file_name)]
|
| 96 |
|
| 97 |
-
# (4) gemini์ ์ ๋ฌํ Content ์ค๋น (์ด๋ฏธ์ง + ํ๋กฌํํธ)
|
| 98 |
contents = [
|
| 99 |
types.Content(
|
| 100 |
role="user",
|
|
@@ -108,7 +103,6 @@ def generate_by_google_genai(text, file_name, model="gemini-2.0-flash-exp"):
|
|
| 108 |
),
|
| 109 |
]
|
| 110 |
|
| 111 |
-
# (5) ์์ฑ/๋ณํ ์ค์
|
| 112 |
generate_content_config = types.GenerateContentConfig(
|
| 113 |
temperature=1,
|
| 114 |
top_p=0.95,
|
|
@@ -121,10 +115,8 @@ def generate_by_google_genai(text, file_name, model="gemini-2.0-flash-exp"):
|
|
| 121 |
text_response = ""
|
| 122 |
image_path = None
|
| 123 |
|
| 124 |
-
# ์์ ํ์ผ๋ก ์ด๋ฏธ์ง ๋ฐ์ ์ค๋น
|
| 125 |
with tempfile.NamedTemporaryFile(suffix=".png", delete=False) as tmp:
|
| 126 |
temp_path = tmp.name
|
| 127 |
-
# ์๋ต ์คํธ๋ฆผ ์ฒ๋ฆฌ
|
| 128 |
for chunk in client.models.generate_content_stream(
|
| 129 |
model=model,
|
| 130 |
contents=contents,
|
|
@@ -134,60 +126,34 @@ def generate_by_google_genai(text, file_name, model="gemini-2.0-flash-exp"):
|
|
| 134 |
continue
|
| 135 |
candidate = chunk.candidates[0].content.parts[0]
|
| 136 |
|
| 137 |
-
# inline_data๊ฐ ์์ผ๋ฉด ์ด๋ฏธ์ง ์๋ต
|
| 138 |
if candidate.inline_data:
|
| 139 |
save_binary_file(temp_path, candidate.inline_data.data)
|
| 140 |
print(f"File of mime type {candidate.inline_data.mime_type} saved to: {temp_path}")
|
| 141 |
image_path = temp_path
|
| 142 |
break
|
| 143 |
else:
|
| 144 |
-
# ์ด๋ฏธ์ง ์์ด ํ
์คํธ๋ง ๋ฐํ๋๋ ๊ฒฝ์ฐ
|
| 145 |
text_response += chunk.text + "\n"
|
| 146 |
|
| 147 |
-
# ์
๋ก๋ํ File ๊ฐ์ฒด ์ ๊ฑฐ
|
| 148 |
del files
|
| 149 |
-
|
| 150 |
return image_path, text_response
|
| 151 |
|
| 152 |
#######################################
|
| 153 |
-
# 3.
|
| 154 |
-
#######################################
|
| 155 |
-
|
| 156 |
-
def generate_random_letters(length: int) -> str:
|
| 157 |
-
"""
|
| 158 |
-
length ๊ธธ์ด์ ์์์ ์ํ๋ฒณ ๋ฌธ์์ด์ ์์ฑํด ๋ฐํ.
|
| 159 |
-
๋๋ฌธ์+์๋ฌธ์(a-z, A-Z) ๋ฒ์์์ ๋๋ค ๋ฝ๊ธฐ.
|
| 160 |
-
"""
|
| 161 |
-
letters = string.ascii_uppercase + string.ascii_lowercase
|
| 162 |
-
return "".join(random.choice(letters) for _ in range(length))
|
| 163 |
-
|
| 164 |
-
def fill_text_input_with_random(new_text: str) -> str:
|
| 165 |
-
"""
|
| 166 |
-
"์๋ก ๋ฐ๊ฟ ํ
์คํธ"์ ๊ธธ์ด๋ฅผ ์ธ์ด, ๊ทธ ๊ธธ์ด๋งํผ ์์์ ์ํ๋ฒณ ๋ฌธ์์ด ์์ฑ ํ ๋ฐํ.
|
| 167 |
-
์ด ๋ฐํ๊ฐ์ด ๊ณง "์ด๋ฏธ์ง ์์ ๋ค์ด๊ฐ ํ
์คํธ" UI(=text_input)์ ํ์๋จ.
|
| 168 |
-
"""
|
| 169 |
-
length = len(new_text)
|
| 170 |
-
random_letters = generate_random_letters(length)
|
| 171 |
-
return random_letters
|
| 172 |
-
|
| 173 |
-
#######################################
|
| 174 |
-
# 4. Gradio ํจ์
|
| 175 |
#######################################
|
| 176 |
|
| 177 |
def generate_initial_image(prompt, text, height, width, steps, scale, seed):
|
| 178 |
"""
|
| 179 |
-
FLUX ํ์ดํ๋ผ์ธ์ ์ฌ์ฉํด '
|
| 180 |
-
|
| 181 |
-
- <text>๊ฐ ์๋ค๋ฉด "with clear readable text that says '<text>'"๋ฅผ ์๋ ๋ถ์
|
| 182 |
"""
|
| 183 |
if "<text>" in prompt:
|
| 184 |
combined_prompt = prompt.replace("<text>", text)
|
| 185 |
else:
|
| 186 |
combined_prompt = f"{prompt} with clear readable text that says '{text}'"
|
| 187 |
|
| 188 |
-
print(
|
| 189 |
|
| 190 |
-
with torch.inference_mode(), torch.autocast("cuda", dtype=torch.bfloat16), timer("
|
| 191 |
result = pipe(
|
| 192 |
prompt=[combined_prompt],
|
| 193 |
generator=torch.Generator().manual_seed(int(seed)),
|
|
@@ -202,9 +168,8 @@ def generate_initial_image(prompt, text, height, width, steps, scale, seed):
|
|
| 202 |
|
| 203 |
def change_text_in_image(original_image, new_text):
|
| 204 |
"""
|
| 205 |
-
|
| 206 |
-
|
| 207 |
-
(์ฌ๊ธฐ์๋ new_text๊ฐ ์ด๋ฏธ ์์์ ์ํ๋ฒณ์ผ๋ก ์ฑ์์ง ์ํ๊ฐ ๋จ)
|
| 208 |
"""
|
| 209 |
try:
|
| 210 |
with tempfile.NamedTemporaryFile(suffix=".png", delete=False) as tmp:
|
|
@@ -220,44 +185,84 @@ def change_text_in_image(original_image, new_text):
|
|
| 220 |
with open(image_path, "rb") as f:
|
| 221 |
image_data = f.read()
|
| 222 |
modified_img = Image.open(io.BytesIO(image_data))
|
| 223 |
-
return modified_img
|
| 224 |
else:
|
| 225 |
-
|
|
|
|
| 226 |
|
| 227 |
except Exception as e:
|
| 228 |
raise gr.Error(f"Error: {e}")
|
| 229 |
|
| 230 |
#######################################
|
| 231 |
-
#
|
| 232 |
#######################################
|
| 233 |
|
| 234 |
-
|
| 235 |
-
|
| 236 |
-
|
| 237 |
-
|
|
|
|
|
|
|
| 238 |
|
| 239 |
-
|
| 240 |
-
|
| 241 |
-
|
| 242 |
-
|
| 243 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 244 |
|
| 245 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 246 |
"""
|
| 247 |
)
|
| 248 |
|
| 249 |
with gr.Row():
|
| 250 |
with gr.Column():
|
| 251 |
-
gr.Markdown("## 1) Step 1: FLUX๋ก ํ
์คํธ ํฌํจ ์ด๋ฏธ์ง ์์ฑ")
|
| 252 |
prompt_input = gr.Textbox(
|
| 253 |
lines=3,
|
| 254 |
-
label="
|
| 255 |
-
placeholder="e.g. A white cat with speech bubble
|
| 256 |
)
|
| 257 |
-
|
| 258 |
lines=1,
|
| 259 |
-
label="
|
| 260 |
-
placeholder="
|
| 261 |
)
|
| 262 |
with gr.Accordion("๊ณ ๊ธ ์ค์ (ํ์ฅ)", open=False):
|
| 263 |
height = gr.Slider(label="Height", minimum=256, maximum=1152, step=64, value=512)
|
|
@@ -266,52 +271,17 @@ with gr.Blocks(title="Flux + Google GenAI + Random Text Replacement") as demo:
|
|
| 266 |
scale = gr.Slider(label="Guidance Scale", minimum=0.0, maximum=10.0, step=0.5, value=3.5)
|
| 267 |
seed = gr.Number(label="Seed (reproducibility)", value=1234, precision=0)
|
| 268 |
|
| 269 |
-
|
| 270 |
-
generated_image = gr.Image(label="Generated Image (with text)", type="pil")
|
| 271 |
|
| 272 |
with gr.Column():
|
| 273 |
-
gr.
|
| 274 |
-
|
| 275 |
-
|
| 276 |
-
|
| 277 |
-
|
| 278 |
-
|
| 279 |
-
|
| 280 |
-
|
| 281 |
-
placeholder="์) Hello123 (๊ธธ์ด 8์ด๋ฉด, 8๊ธ์ ๋๋ค)"
|
| 282 |
-
)
|
| 283 |
-
|
| 284 |
-
# (A) ๋จผ์ "์๋ก ๋ฐ๊ฟ ํ
์คํธ" ๊ธ์์๋ฅผ ์ธ์ด, ๋ฌด์์ ์ํ๋ฒณ์ผ๋ก text_input ์ฑ์ฐ๊ธฐ
|
| 285 |
-
# (B) ๊ทธ๋ฐ ๋ค change_text_in_image() ์คํ
|
| 286 |
-
modify_btn = gr.Button("Generate Random Letters & Change Text in Image", variant="secondary")
|
| 287 |
-
|
| 288 |
-
# ์ต์ข
๊ฒฐ๊ณผ
|
| 289 |
-
output_img = gr.Image(label="Modified Image", type="pil")
|
| 290 |
-
output_txt = gr.Textbox(label="(If only text returned)")
|
| 291 |
-
|
| 292 |
-
###########################
|
| 293 |
-
# 1) Step1 ๋ฒํผ ์ก์
|
| 294 |
-
###########################
|
| 295 |
-
generate_btn.click(
|
| 296 |
-
fn=generate_initial_image,
|
| 297 |
-
inputs=[prompt_input, text_input, height, width, steps, scale, seed],
|
| 298 |
-
outputs=[generated_image]
|
| 299 |
-
)
|
| 300 |
-
|
| 301 |
-
###########################
|
| 302 |
-
# 2) Step2 ๋ฒํผ ์ก์
|
| 303 |
-
###########################
|
| 304 |
-
# (A) ๋ฌด์์ ์ํ๋ฒณ ์์ฑํด text_input์ ๋ฐ์
|
| 305 |
-
chain = modify_btn.click(
|
| 306 |
-
fn=fill_text_input_with_random,
|
| 307 |
-
inputs=[new_text_input],
|
| 308 |
-
outputs=[text_input]
|
| 309 |
-
)
|
| 310 |
-
# (B) ๋ฐฉ๊ธ ์
๋ฐ์ดํธ๋ text_input ๊ฐ์ ์ด์ฉํด, ์ด๋ฏธ์ง ํ
์คํธ ๊ต์ฒด
|
| 311 |
-
chain.then(
|
| 312 |
-
fn=change_text_in_image,
|
| 313 |
-
inputs=[generated_image, text_input],
|
| 314 |
-
outputs=[output_img, output_txt]
|
| 315 |
)
|
| 316 |
|
| 317 |
demo.launch(max_threads=20)
|
|
|
|
| 35 |
os.environ["HF_HUB_CACHE"] = CACHE_PATH
|
| 36 |
os.environ["HF_HOME"] = CACHE_PATH
|
| 37 |
|
| 38 |
+
# ํ์ด๋จธ ํด๋์ค
|
| 39 |
class timer:
|
| 40 |
def __init__(self, method_name="timed process"):
|
| 41 |
self.method = method_name
|
|
|
|
| 65 |
pipe.to(device="cuda", dtype=torch.bfloat16)
|
| 66 |
|
| 67 |
#######################################
|
| 68 |
+
# 2. Google GenAI ๋ชจ๋ธ๋ก ํ
์คํธ ๋ณํ ํจ์
|
| 69 |
#######################################
|
| 70 |
|
| 71 |
def save_binary_file(file_name, data):
|
|
|
|
| 80 |
- file_name: ์๋ณธ ์ด๋ฏธ์ง(์: .png) ๊ฒฝ๋ก
|
| 81 |
- model: ์ฌ์ฉํ gemini ๋ชจ๋ธ ์ด๋ฆ
|
| 82 |
"""
|
|
|
|
| 83 |
api_key = os.getenv("GAPI_TOKEN", None)
|
| 84 |
if not api_key:
|
| 85 |
raise ValueError(
|
| 86 |
"GAPI_TOKEN ํ๊ฒฝ ๋ณ์๊ฐ ์ค์ ๋์ง ์์์ต๋๋ค. "
|
| 87 |
+
"Google GenAI API ์ฌ์ฉ์ ์ํด์๋ GAPI_TOKEN์ด ํ์ํฉ๋๋ค."
|
| 88 |
)
|
| 89 |
|
|
|
|
| 90 |
client = genai.Client(api_key=api_key)
|
|
|
|
|
|
|
| 91 |
files = [client.files.upload(file=file_name)]
|
| 92 |
|
|
|
|
| 93 |
contents = [
|
| 94 |
types.Content(
|
| 95 |
role="user",
|
|
|
|
| 103 |
),
|
| 104 |
]
|
| 105 |
|
|
|
|
| 106 |
generate_content_config = types.GenerateContentConfig(
|
| 107 |
temperature=1,
|
| 108 |
top_p=0.95,
|
|
|
|
| 115 |
text_response = ""
|
| 116 |
image_path = None
|
| 117 |
|
|
|
|
| 118 |
with tempfile.NamedTemporaryFile(suffix=".png", delete=False) as tmp:
|
| 119 |
temp_path = tmp.name
|
|
|
|
| 120 |
for chunk in client.models.generate_content_stream(
|
| 121 |
model=model,
|
| 122 |
contents=contents,
|
|
|
|
| 126 |
continue
|
| 127 |
candidate = chunk.candidates[0].content.parts[0]
|
| 128 |
|
|
|
|
| 129 |
if candidate.inline_data:
|
| 130 |
save_binary_file(temp_path, candidate.inline_data.data)
|
| 131 |
print(f"File of mime type {candidate.inline_data.mime_type} saved to: {temp_path}")
|
| 132 |
image_path = temp_path
|
| 133 |
break
|
| 134 |
else:
|
|
|
|
| 135 |
text_response += chunk.text + "\n"
|
| 136 |
|
|
|
|
| 137 |
del files
|
|
|
|
| 138 |
return image_path, text_response
|
| 139 |
|
| 140 |
#######################################
|
| 141 |
+
# 3. Diffusion + GoogleGenAI๋ฅผ ์ฐ๊ฒฐ
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 142 |
#######################################
|
| 143 |
|
| 144 |
def generate_initial_image(prompt, text, height, width, steps, scale, seed):
|
| 145 |
"""
|
| 146 |
+
1) FLUX ํ์ดํ๋ผ์ธ์ ์ฌ์ฉํด 'text'๊ฐ ๋ค์ด๊ฐ ์ด๋ฏธ์ง๋ฅผ ์์ฑ
|
| 147 |
+
- prompt ๋ด <text>๊ฐ ์์ผ๋ฉด ์นํ, ์์ผ๋ฉด ์๋ ์ถ๊ฐ
|
|
|
|
| 148 |
"""
|
| 149 |
if "<text>" in prompt:
|
| 150 |
combined_prompt = prompt.replace("<text>", text)
|
| 151 |
else:
|
| 152 |
combined_prompt = f"{prompt} with clear readable text that says '{text}'"
|
| 153 |
|
| 154 |
+
print("[DEBUG] combined_prompt:", combined_prompt)
|
| 155 |
|
| 156 |
+
with torch.inference_mode(), torch.autocast("cuda", dtype=torch.bfloat16), timer("GenerateInitialImage"):
|
| 157 |
result = pipe(
|
| 158 |
prompt=[combined_prompt],
|
| 159 |
generator=torch.Generator().manual_seed(int(seed)),
|
|
|
|
| 168 |
|
| 169 |
def change_text_in_image(original_image, new_text):
|
| 170 |
"""
|
| 171 |
+
2) Gemini ๋ชจ๋ธ์ ํตํด,
|
| 172 |
+
original_image ๋ด ํ
์คํธ๋ฅผ `new_text`๋ก ๋ณ๊ฒฝํ ์ด๋ฏธ์ง ๋ฐํ
|
|
|
|
| 173 |
"""
|
| 174 |
try:
|
| 175 |
with tempfile.NamedTemporaryFile(suffix=".png", delete=False) as tmp:
|
|
|
|
| 185 |
with open(image_path, "rb") as f:
|
| 186 |
image_data = f.read()
|
| 187 |
modified_img = Image.open(io.BytesIO(image_data))
|
| 188 |
+
return modified_img
|
| 189 |
else:
|
| 190 |
+
# ์ด๋ฏธ์ง๊ฐ ์์ด ํ
์คํธ๋ง ์๋ต๋ ๊ฒฝ์ฐ
|
| 191 |
+
return None
|
| 192 |
|
| 193 |
except Exception as e:
|
| 194 |
raise gr.Error(f"Error: {e}")
|
| 195 |
|
| 196 |
#######################################
|
| 197 |
+
# 4. ์์ ์ํ๋ฒณ ์์ฑ
|
| 198 |
#######################################
|
| 199 |
|
| 200 |
+
def generate_random_letters(length: int) -> str:
|
| 201 |
+
"""
|
| 202 |
+
length ๊ธธ์ด์ ์์ ์ํ๋ฒณ(๋์๋ฌธ์) ๋ฌธ์์ด ์์ฑ
|
| 203 |
+
"""
|
| 204 |
+
letters = string.ascii_lowercase + string.ascii_uppercase
|
| 205 |
+
return "".join(random.choice(letters) for _ in range(length))
|
| 206 |
|
| 207 |
+
#######################################
|
| 208 |
+
# 5. ์ต์ข
ํจ์: ๋ฒํผ ํ ๋ฒ์ผ๋ก
|
| 209 |
+
# (1) ๋ฌด์์ ์ํ๋ฒณ์ผ๋ก 1์ฐจ ์ด๋ฏธ์ง ์์ฑ
|
| 210 |
+
# (2) ์ง์ง "์๋ก ๋ฐ๊ฟ ํ
์คํธ"๋ก 2์ฐจ ์ด๋ฏธ์ง ์์ฑ
|
| 211 |
+
#######################################
|
| 212 |
+
|
| 213 |
+
def run_full_process(prompt, final_text, height, width, steps, scale, seed):
|
| 214 |
+
"""
|
| 215 |
+
- final_text์ ๊ธธ์ด์ ๋ง์ถฐ ๋๋ค ์ํ๋ฒณ์ ์์ฑ -> 1์ฐจ ์ด๋ฏธ์ง
|
| 216 |
+
- ๊ทธ 1์ฐจ ์ด๋ฏธ์ง๋ฅผ ๋ฐํ์ผ๋ก, final_text๋ก ๊ต์ฒด -> 2์ฐจ ์ต์ข
์ด๋ฏธ์ง
|
| 217 |
+
"""
|
| 218 |
+
# (A) ์๋ก ๋ฐ๊ฟ ํ
์คํธ(final_text) ๊ธ์์๋งํผ ์์ ์ํ๋ฒณ ์์ฑ
|
| 219 |
+
random_len = len(final_text)
|
| 220 |
+
random_text = generate_random_letters(random_len)
|
| 221 |
+
print(f"[STEP] final_text='{final_text}' => random_text='{random_text}'")
|
| 222 |
|
| 223 |
+
# (B) 1์ฐจ ์ด๋ฏธ์ง: ๋ฌด์์ ์ํ๋ฒณ์ผ๋ก ์์ฑ
|
| 224 |
+
random_image = generate_initial_image(prompt, random_text, height, width, steps, scale, seed)
|
| 225 |
+
|
| 226 |
+
# (C) 2์ฐจ ์ด๋ฏธ์ง: ์ค์ final_text๋ก ๊ต์ฒด
|
| 227 |
+
final_image = change_text_in_image(random_image, final_text)
|
| 228 |
+
|
| 229 |
+
return [random_image, final_image]
|
| 230 |
+
|
| 231 |
+
#######################################
|
| 232 |
+
# 6. Gradio UI
|
| 233 |
+
#######################################
|
| 234 |
+
|
| 235 |
+
with gr.Blocks(title="Flux + Google GenAI (Random & Then Real Text)") as demo:
|
| 236 |
+
gr.Markdown(
|
| 237 |
+
"""
|
| 238 |
+
# Flux + Google GenAI: ๋ ๋จ๊ณ์ ๊ฑธ์น ํ
์คํธ ๊ต์ฒด
|
| 239 |
+
|
| 240 |
+
**์ฌ์ฉ ํ๋ฆ**
|
| 241 |
+
1) Prompt์ ์ฅ๋ฉด์ด๋ ์คํ์ผ์ ์์ฑ (ํ์ํ๋ฉด `<text>` ๊ตฌ๋ถ์ ์ฌ์ฉ)
|
| 242 |
+
2) "์๋ก ๋ฐ๊ฟ ํ
์คํธ" ์ ์ต์ข
์ํ๋ ๋ฌธ์์ด์ ์
๋ ฅ (์: "์๋
ํ์ธ์")
|
| 243 |
+
3) "Generate Images" ๋ฒํผ์ ๋๋ฅด๋ฉด,
|
| 244 |
+
- ๋จผ์ "์๋ก ๋ฐ๊ฟ ํ
์คํธ" ๊ธธ์ด์ ๋ง๋ **๋ฌด์์ ์ํ๋ฒณ**์ ๋ฃ์ด ์ด๋ฏธ์ง ์์ฑ (1์ฐจ ์ด๋ฏธ์ง)
|
| 245 |
+
- ์ด์ด์ **์ง์ง** "์๋ก ๋ฐ๊ฟ ํ
์คํธ"๋ก ๋ค์ ๊ต์ฒด(2์ฐจ ์ต์ข
์ด๋ฏธ์ง)
|
| 246 |
+
4) ๊ฒฐ๊ณผ๋ก ๋ ์ฅ์ ์ด๋ฏธ์ง๋ฅผ ํ์ธํ ์ ์์ต๋๋ค.
|
| 247 |
+
|
| 248 |
+
**์ฃผ์ ํฌ์ธํธ**
|
| 249 |
+
- "์ด๋ฏธ์ง ์์ ๋ค์ด๊ฐ ํ
์คํธ"๋ **UI์ ๋
ธ์ถ๋์ง ์์ผ๋ฉฐ**(์ฌ์ฉ์ ์
๋ ฅ ๋ถ๊ฐ), ์ค์ง ๋ด๋ถ์์ ์๋ ์ค์ ๋ฉ๋๋ค.
|
| 250 |
+
- 1์ฐจ ์ด๋ฏธ์ง๋ ์์ ํ ์์์ ์ํ๋ฒณ ํ
์คํธ๋ฅผ ํฌํจํฉ๋๋ค.
|
| 251 |
+
- 2์ฐจ ์ด๋ฏธ์ง๋ ์ต์ข
์ ์ผ๋ก ์ฌ์ฉ์๊ฐ ์
๋ ฅํ "์๋ก ๋ฐ๊ฟ ํ
์คํธ"๋ฅผ ํฌํจํฉ๋๋ค.
|
| 252 |
"""
|
| 253 |
)
|
| 254 |
|
| 255 |
with gr.Row():
|
| 256 |
with gr.Column():
|
|
|
|
| 257 |
prompt_input = gr.Textbox(
|
| 258 |
lines=3,
|
| 259 |
+
label="Prompt (use `<text>` if you want)",
|
| 260 |
+
placeholder="e.g. A white cat with a speech bubble <text>"
|
| 261 |
)
|
| 262 |
+
final_text_input = gr.Textbox(
|
| 263 |
lines=1,
|
| 264 |
+
label="์๋ก ๋ฐ๊ฟ ํ
์คํธ",
|
| 265 |
+
placeholder="์) ์๋
ํ์ธ์"
|
| 266 |
)
|
| 267 |
with gr.Accordion("๊ณ ๊ธ ์ค์ (ํ์ฅ)", open=False):
|
| 268 |
height = gr.Slider(label="Height", minimum=256, maximum=1152, step=64, value=512)
|
|
|
|
| 271 |
scale = gr.Slider(label="Guidance Scale", minimum=0.0, maximum=10.0, step=0.5, value=3.5)
|
| 272 |
seed = gr.Number(label="Seed (reproducibility)", value=1234, precision=0)
|
| 273 |
|
| 274 |
+
run_btn = gr.Button("Generate Images", variant="primary")
|
|
|
|
| 275 |
|
| 276 |
with gr.Column():
|
| 277 |
+
random_image_output = gr.Image(label="1) Random Text Image", type="pil")
|
| 278 |
+
final_image_output = gr.Image(label="2) Final Text Image", type="pil")
|
| 279 |
+
|
| 280 |
+
# ๋ฒํผ ์ก์
: ์ ๋จ๊ณ๋ค์ ๋ชจ๋ ์คํ -> ๊ฒฐ๊ณผ 2์ฅ ์ถ๋ ฅ
|
| 281 |
+
run_btn.click(
|
| 282 |
+
fn=run_full_process,
|
| 283 |
+
inputs=[prompt_input, final_text_input, height, width, steps, scale, seed],
|
| 284 |
+
outputs=[random_image_output, final_image_output]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 285 |
)
|
| 286 |
|
| 287 |
demo.launch(max_threads=20)
|