seawolf2357 commited on
Commit
504169f
ยท
verified ยท
1 Parent(s): e14d9c5

Update app-backup.py

Browse files
Files changed (1) hide show
  1. app-backup.py +241 -227
app-backup.py CHANGED
@@ -1,280 +1,294 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  import random
2
  import os
3
  import uuid
 
 
4
  from datetime import datetime
 
5
  import gradio as gr
6
  import numpy as np
7
- import spaces
8
  import torch
9
  from diffusers import DiffusionPipeline
10
  from PIL import Image
11
 
12
- # Create permanent storage directory
13
- SAVE_DIR = "saved_images" # Gradio will handle the persistence
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
14
  if not os.path.exists(SAVE_DIR):
15
  os.makedirs(SAVE_DIR, exist_ok=True)
16
 
 
17
  device = "cuda" if torch.cuda.is_available() else "cpu"
 
 
18
  repo_id = "black-forest-labs/FLUX.1-dev"
19
- adapter_id = "seawolf2357/kim-korea" # ํŠน์ • ์ •์น˜์ธ์„ ํ•™์Šตํ•œ LoRA ๋ชจ๋ธ
20
 
21
- pipeline = DiffusionPipeline.from_pretrained(repo_id, torch_dtype=torch.bfloat16)
22
- pipeline.load_lora_weights(adapter_id)
23
- pipeline = pipeline.to(device)
 
 
 
 
 
 
24
 
25
  MAX_SEED = np.iinfo(np.int32).max
26
  MAX_IMAGE_SIZE = 1024
27
 
28
- def save_generated_image(image, prompt):
29
- # Generate unique filename with timestamp
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
30
  timestamp = datetime.now().strftime("%Y%m%d_%H%M%S")
31
  unique_id = str(uuid.uuid4())[:8]
32
  filename = f"{timestamp}_{unique_id}.png"
33
  filepath = os.path.join(SAVE_DIR, filename)
34
-
35
- # Save the image
36
  image.save(filepath)
37
-
38
- # Save metadata
39
  metadata_file = os.path.join(SAVE_DIR, "metadata.txt")
40
  with open(metadata_file, "a", encoding="utf-8") as f:
41
  f.write(f"{filename}|{prompt}|{timestamp}\n")
42
-
43
  return filepath
44
 
45
- @spaces.GPU(duration=60)
46
- def inference(
47
- prompt,
48
- seed=42,
49
- randomize_seed=True,
50
- width=1024,
51
- height=768,
52
- guidance_scale=3.5,
53
- num_inference_steps=30,
54
- lora_scale=1.0,
55
- progress=None,
56
- ):
57
- if randomize_seed:
58
- seed = random.randint(0, MAX_SEED)
59
- generator = torch.Generator(device=device).manual_seed(int(seed))
60
 
61
- image = pipeline(
 
62
  prompt=prompt,
63
  guidance_scale=guidance_scale,
64
- num_inference_steps=num_inference_steps,
65
  width=width,
66
  height=height,
67
  generator=generator,
68
  joint_attention_kwargs={"scale": lora_scale},
69
  ).images[0]
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
70
 
71
- # Save the generated image
72
- filepath = save_generated_image(image, prompt)
73
-
74
- # Return just the image and seed
75
- return image, seed
76
 
77
- # ์˜ˆ์‹œ ๋ฌธ๊ตฌ: ํŠน์ • ์ •์น˜์ธ Mr. KIM์˜ ๋‹ค์–‘ํ•œ ์ƒํ™ฉ์„ ๋ฌ˜์‚ฌ
78
 
79
  examples = [
80
- "Mr. KIM holding up a 'Fighting!' banner with both hands, showing patriotic pride and determination for national excellence. ",
81
- "Mr. KIM raising both arms in celebration with a triumphant expression, showing victory and hope for the future.",
82
- "Mr. KIM jogging in a park wearing athletic gear, demonstrating healthy lifestyle and energetic leadership qualities.",
83
- "Mr. KIM warmly shaking hands with female citizens in a crowded street, showing genuine care and connection with women voters. ",
84
- "Mr. KIM at a campaign rally, pointing toward the horizon with an inspiring gesture while female and kids audience members applaud. ",
85
- "Mr. KIM participating in a community event, surrounded by enthusiastic female supporters cheering ",
86
- "Mr. KIM visiting a local market, engaging in friendly conversation with female vendors and shopkeepers. ",
87
- "Mr. KIM walking through a university campus, discussing education policies with female students and professors. ",
88
- "Mr. KIM delivering a powerful speech in front of a large crowd with confident gestures and determined expression. ",
89
  "Mr. KIM in a dynamic interview setting, passionately outlining his visions for the future.",
90
- "Mr. KIM preparing for an important debate, surrounded by paperwork, looking focused and resolute. ",
91
  ]
92
 
93
- # UI๋ฅผ ๋ถ‰์€ ๊ณ„์—ด ๊ทธ๋ผ๋””์—์ด์…˜์œผ๋กœ ๋””์ž์ธ
94
  custom_css = """
95
  :root {
96
- --color-primary: #8F1A3A; /* ๋ถ‰์€ ํ†ค์˜ ๋ฉ”์ธ ์ปฌ๋Ÿฌ */
97
- --color-secondary: #FF4B4B; /* ํฌ์ธํŠธ ์ปฌ๋Ÿฌ(๋ฐ์€ ๋นจ๊ฐ•) */
98
  --background-fill-primary: linear-gradient(to right, #FFF5F5, #FED7D7, #FEB2B2);
99
  }
100
- footer {
101
- visibility: hidden;
102
- }
103
- .gradio-container {
104
- background: var(--background-fill-primary);
105
- }
106
- .title {
107
- color: var(--color-primary) !important;
108
- font-size: 3rem !important;
109
- font-weight: 700 !important;
110
- text-align: center;
111
- margin: 1rem 0;
112
- text-shadow: 2px 2px 4px rgba(0,0,0,0.05);
113
- font-family: 'Playfair Display', serif;
114
- }
115
- .subtitle {
116
- color: #4A5568 !important;
117
- font-size: 1.2rem !important;
118
- text-align: center;
119
- margin-bottom: 1.5rem;
120
- font-style: italic;
121
- }
122
- .collection-link {
123
- text-align: center;
124
- margin-bottom: 2rem;
125
- font-size: 1.1rem;
126
- }
127
- .collection-link a {
128
- color: var(--color-primary);
129
- text-decoration: underline;
130
- transition: color 0.3s ease;
131
- }
132
- .collection-link a:hover {
133
- color: var(--color-secondary);
134
- }
135
- .model-description {
136
- background-color: rgba(255, 255, 255, 0.8);
137
- border-radius: 12px;
138
- padding: 24px;
139
- margin: 20px 0;
140
- box-shadow: 0 4px 12px rgba(0, 0, 0, 0.05);
141
- border-left: 5px solid var(--color-primary);
142
- }
143
- button.primary {
144
- background-color: var(--color-primary) !important;
145
- transition: all 0.3s ease;
146
- color: #fff !important;
147
- }
148
- button:hover {
149
- transform: translateY(-2px);
150
- box-shadow: 0 5px 15px rgba(0,0,0,0.1);
151
- }
152
- .input-container {
153
- border-radius: 10px;
154
- box-shadow: 0 2px 8px rgba(0,0,0,0.05);
155
- background-color: rgba(255, 255, 255, 0.6);
156
- padding: 20px;
157
- margin-bottom: 1rem;
158
- }
159
- .advanced-settings {
160
- margin-top: 1rem;
161
- padding: 1rem;
162
- border-radius: 10px;
163
- background-color: rgba(255, 255, 255, 0.6);
164
- }
165
- .example-region {
166
- background-color: rgba(255, 255, 255, 0.5);
167
- border-radius: 10px;
168
- padding: 1rem;
169
- margin-top: 1rem;
170
- }
171
  """
172
 
173
- with gr.Blocks(css=custom_css, analytics_enabled=False) as demo:
174
- gr.HTML('<div class="title">Mr. KIM in KOREA</div>')
175
-
176
- # ์ปฌ๋ ‰์…˜ ๋งํฌ ๋˜๋Š” ์•ˆ๋‚ด๋ฌธ์„ ํ•„์š” ์‹œ ์ˆ˜์ •/์‚ญ์ œ
177
- gr.HTML('<div class="collection-link"><a href="https://huggingface.co/collections/openfree/painting-art-ai-681453484ec15ef5978bbeb1" target="_blank">Visit the LoRA Model Collection</a></div>')
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
178
 
179
- # ๋ชจ๋ธ ์„ค๋ช…: ํŠน์ • ์ •์น˜์ธ์— ๋Œ€ํ•œ LoRA ๋ชจ๋ธ์ž„์„ ์–ธ๊ธ‰
180
- with gr.Group(elem_classes="model-description"):
181
- gr.HTML("""
182
- <p>
183
- ๋ณธ ๋ชจ๋ธ์€ ์—ฐ๊ตฌ ๋ชฉ์ ์œผ๋กœ ํŠน์ •์ธ์˜ ์–ผ๊ตด๊ณผ ์™ธ๋ชจ๋ฅผ ํ•™์Šตํ•œ LoRA ๋ชจ๋ธ์ž…๋‹ˆ๋‹ค.<br>
184
- ๋ชฉ์ ์™ธ์˜ ์šฉ๋„๋กœ ๋ฌด๋‹จ ์‚ฌ์šฉ ์•Š๋„๋ก ์œ ์˜ํ•ด ์ฃผ์„ธ์š”.<br>
185
- (์˜ˆ์‹œ prompt ์‚ฌ์šฉ ์‹œ ๋ฐ˜๋“œ์‹œ 'kim'์„ ํฌํ•จํ•˜์—ฌ์•ผ ์ตœ์ ์˜ ๊ฒฐ๊ณผ๋ฅผ ์–ป์„ ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.)
186
- </p>
187
- """)
188
-
189
- # ๋ฉ”์ธ UI
190
- with gr.Column(elem_id="col-container"):
191
- with gr.Row(elem_classes="input-container"):
192
- prompt = gr.Text(
193
- label="Prompt",
194
- max_lines=1,
195
- placeholder="Enter your prompt (add [trigger] at the end)",
196
- value=examples[0] # ๊ธฐ๋ณธ ์˜ˆ์‹œ
197
- )
198
- run_button = gr.Button("Generate", variant="primary", scale=0)
199
-
200
- result = gr.Image(label="Generated Image")
201
- seed_output = gr.Number(label="Seed", visible=True)
202
-
203
- with gr.Accordion("Advanced Settings", open=False, elem_classes="advanced-settings"):
204
- seed = gr.Slider(
205
- label="Seed",
206
- minimum=0,
207
- maximum=MAX_SEED,
208
- step=1,
209
- value=42,
210
- )
211
- randomize_seed = gr.Checkbox(label="Randomize seed", value=True)
212
-
213
- with gr.Row():
214
- width = gr.Slider(
215
- label="Width",
216
- minimum=256,
217
- maximum=MAX_IMAGE_SIZE,
218
- step=32,
219
- value=1024,
220
- )
221
- height = gr.Slider(
222
- label="Height",
223
- minimum=256,
224
- maximum=MAX_IMAGE_SIZE,
225
- step=32,
226
- value=768,
227
- )
228
-
229
- with gr.Row():
230
- guidance_scale = gr.Slider(
231
- label="Guidance scale",
232
- minimum=0.0,
233
- maximum=10.0,
234
- step=0.1,
235
- value=3.5,
236
- )
237
- num_inference_steps = gr.Slider(
238
- label="Number of inference steps",
239
- minimum=1,
240
- maximum=50,
241
- step=1,
242
- value=30,
243
- )
244
- lora_scale = gr.Slider(
245
- label="LoRA scale",
246
- minimum=0.0,
247
- maximum=1.0,
248
- step=0.1,
249
- value=1.0,
250
- )
251
-
252
- with gr.Group(elem_classes="example-region"):
253
- gr.Markdown("### Examples")
254
- gr.Examples(
255
- examples=examples,
256
- inputs=prompt,
257
- outputs=None, # Don't auto-run examples
258
- fn=None, # No function to run for examples - just fill the prompt
259
- cache_examples=False,
260
- )
261
 
262
- # ์ด๋ฒคํŠธ ํ•ธ๋“ค๋Ÿฌ
263
- gr.on(
264
- triggers=[run_button.click, prompt.submit],
265
- fn=inference,
266
- inputs=[
267
- prompt,
268
- seed,
269
- randomize_seed,
270
- width,
271
- height,
272
- guidance_scale,
273
- num_inference_steps,
274
- lora_scale,
275
- ],
276
- outputs=[result, seed_output],
277
- )
278
-
279
- demo.queue()
280
- demo.launch()
 
1
+ # ===== CRITICAL: Import spaces FIRST before any CUDA operations =====
2
+ try:
3
+ import spaces
4
+ HF_SPACES = True
5
+ except ImportError:
6
+ # If running locally, create a dummy decorator
7
+ def spaces_gpu_decorator(duration=60):
8
+ def decorator(func):
9
+ return func
10
+ return decorator
11
+ spaces = type('spaces', (), {'GPU': spaces_gpu_decorator})()
12
+ HF_SPACES = False
13
+ print("Warning: Running without Hugging Face Spaces GPU allocation")
14
+
15
+ # ===== Now import other libraries =====
16
  import random
17
  import os
18
  import uuid
19
+ import re
20
+ import time
21
  from datetime import datetime
22
+
23
  import gradio as gr
24
  import numpy as np
25
+ import requests
26
  import torch
27
  from diffusers import DiffusionPipeline
28
  from PIL import Image
29
 
30
+ # ===== OpenAI ์„ค์ • =====
31
+ from openai import OpenAI
32
+
33
+ # Add error handling for API key
34
+ try:
35
+ client = OpenAI(api_key=os.getenv("LLM_API"))
36
+ except Exception as e:
37
+ print(f"Warning: OpenAI client initialization failed: {e}")
38
+ client = None
39
+
40
+ # ===== ํ”„๋กฌํ”„ํŠธ ์ฆ๊ฐ•์šฉ ์Šคํƒ€์ผ ํ”„๋ฆฌ์…‹ =====
41
+ STYLE_PRESETS = {
42
+ "None": "",
43
+ "Realistic Photo": "photorealistic, 8k, ultra-detailed, cinematic lighting, realistic skin texture",
44
+ "Oil Painting": "oil painting, rich brush strokes, canvas texture, baroque lighting",
45
+ "Comic Book": "comic book style, bold ink outlines, cel shading, vibrant colors",
46
+ "Watercolor": "watercolor illustration, soft gradients, splatter effect, pastel palette",
47
+ }
48
+
49
+ # ===== ์ €์žฅ ํด๋” =====
50
+ SAVE_DIR = "saved_images"
51
  if not os.path.exists(SAVE_DIR):
52
  os.makedirs(SAVE_DIR, exist_ok=True)
53
 
54
+ # ===== ๋””๋ฐ”์ด์Šค & ๋ชจ๋ธ ๋กœ๋“œ =====
55
  device = "cuda" if torch.cuda.is_available() else "cpu"
56
+ print(f"Using device: {device}")
57
+
58
  repo_id = "black-forest-labs/FLUX.1-dev"
59
+ adapter_id = "seawolf2357/kim-korea"
60
 
61
+ # Add error handling for model loading
62
+ try:
63
+ pipeline = DiffusionPipeline.from_pretrained(repo_id, torch_dtype=torch.bfloat16)
64
+ pipeline.load_lora_weights(adapter_id)
65
+ pipeline = pipeline.to(device)
66
+ print("Model loaded successfully")
67
+ except Exception as e:
68
+ print(f"Error loading model: {e}")
69
+ pipeline = None
70
 
71
  MAX_SEED = np.iinfo(np.int32).max
72
  MAX_IMAGE_SIZE = 1024
73
 
74
+ # ===== ํ•œ๊ธ€ ์—ฌ๋ถ€ ํŒ๋ณ„ =====
75
+ HANGUL_RE = re.compile(r"[\u3131-\u318E\uAC00-\uD7A3]+")
76
+
77
+ def is_korean(text: str) -> bool:
78
+ return bool(HANGUL_RE.search(text))
79
+
80
+ # ===== ๋ฒˆ์—ญ & ์ฆ๊ฐ• ํ•จ์ˆ˜ =====
81
+
82
+ def openai_translate(text: str, retries: int = 3) -> str:
83
+ """ํ•œ๊ธ€์„ ์˜์–ด๋กœ ๋ฒˆ์—ญ (OpenAI GPT-4o-mini ์‚ฌ์šฉ). ์˜์–ด ์ž…๋ ฅ์ด๋ฉด ๊ทธ๋Œ€๋กœ ๋ฐ˜ํ™˜."""
84
+ if not is_korean(text):
85
+ return text
86
+
87
+ if client is None:
88
+ print("Warning: OpenAI client not available, returning original text")
89
+ return text
90
+
91
+ for attempt in range(retries):
92
+ try:
93
+ res = client.chat.completions.create(
94
+ model="gpt-4o-mini",
95
+ messages=[
96
+ {
97
+ "role": "system",
98
+ "content": "Translate the following Korean prompt into concise, descriptive English suitable for an image generation model. Keep the meaning, do not add new concepts."
99
+ },
100
+ {"role": "user", "content": text}
101
+ ],
102
+ temperature=0.3,
103
+ max_tokens=256,
104
+ )
105
+ return res.choices[0].message.content.strip()
106
+ except Exception as e:
107
+ print(f"[translate] attempt {attempt + 1} failed: {e}")
108
+ time.sleep(2)
109
+ return text # ๋ฒˆ์—ญ ์‹คํŒจ ์‹œ ์›๋ฌธ ๊ทธ๋Œ€๋กœ
110
+
111
+ def prepare_prompt(user_prompt: str, style_key: str) -> str:
112
+ """ํ•œ๊ธ€์ด๋ฉด ๋ฒˆ์—ญํ•˜๊ณ , ์„ ํƒํ•œ ์Šคํƒ€์ผ ํ”„๋ฆฌ์…‹์„ ๋ถ™์—ฌ์„œ ์ตœ์ข… ํ”„๋กฌํ”„ํŠธ๋ฅผ ๋งŒ๋“ ๋‹ค."""
113
+ prompt_en = openai_translate(user_prompt)
114
+ style_suffix = STYLE_PRESETS.get(style_key, "")
115
+ if style_suffix:
116
+ final_prompt = f"{prompt_en}, {style_suffix}"
117
+ else:
118
+ final_prompt = prompt_en
119
+ return final_prompt
120
+
121
+ # ===== ์ด๋ฏธ์ง€ ์ €์žฅ =====
122
+
123
+ def save_generated_image(image: Image.Image, prompt: str) -> str:
124
  timestamp = datetime.now().strftime("%Y%m%d_%H%M%S")
125
  unique_id = str(uuid.uuid4())[:8]
126
  filename = f"{timestamp}_{unique_id}.png"
127
  filepath = os.path.join(SAVE_DIR, filename)
 
 
128
  image.save(filepath)
129
+
130
+ # ๋ฉ”ํƒ€๋ฐ์ดํ„ฐ ์ €์žฅ
131
  metadata_file = os.path.join(SAVE_DIR, "metadata.txt")
132
  with open(metadata_file, "a", encoding="utf-8") as f:
133
  f.write(f"{filename}|{prompt}|{timestamp}\n")
 
134
  return filepath
135
 
136
+ # ===== Diffusion ํ˜ธ์ถœ =====
137
+
138
+ def run_pipeline(prompt: str, seed: int, width: int, height: int, guidance_scale: float, num_steps: int, lora_scale: float):
139
+ if pipeline is None:
140
+ raise ValueError("Model pipeline not loaded")
 
 
 
 
 
 
 
 
 
 
141
 
142
+ generator = torch.Generator(device=device).manual_seed(int(seed))
143
+ result = pipeline(
144
  prompt=prompt,
145
  guidance_scale=guidance_scale,
146
+ num_inference_steps=num_steps,
147
  width=width,
148
  height=height,
149
  generator=generator,
150
  joint_attention_kwargs={"scale": lora_scale},
151
  ).images[0]
152
+ return result
153
+
154
+ # ===== Gradio inference ๋ž˜ํผ =====
155
+
156
+ @spaces.GPU(duration=60)
157
+ def generate_image(
158
+ user_prompt: str,
159
+ style_key: str,
160
+ seed: int = 42,
161
+ randomize_seed: bool = True,
162
+ width: int = 1024,
163
+ height: int = 768,
164
+ guidance_scale: float = 3.5,
165
+ num_inference_steps: int = 30,
166
+ lora_scale: float = 1.0,
167
+ progress=None,
168
+ ):
169
+ try:
170
+ if randomize_seed:
171
+ seed = random.randint(0, MAX_SEED)
172
+
173
+ # 1) ๋ฒˆ์—ญ + ์ฆ๊ฐ•
174
+ final_prompt = prepare_prompt(user_prompt, style_key)
175
+ print(f"Final prompt: {final_prompt}")
176
+
177
+ # 2) ํŒŒ์ดํ”„๋ผ์ธ ํ˜ธ์ถœ
178
+ image = run_pipeline(final_prompt, seed, width, height, guidance_scale, num_inference_steps, lora_scale)
179
+
180
+ # 3) ์ €์žฅ
181
+ save_generated_image(image, final_prompt)
182
+
183
+ return image, seed
184
 
185
+ except Exception as e:
186
+ print(f"Error generating image: {e}")
187
+ # Return a placeholder or error message
188
+ error_image = Image.new('RGB', (width, height), color='red')
189
+ return error_image, seed
190
 
191
+ # ===== ์˜ˆ์‹œ ํ”„๋กฌํ”„ํŠธ (ํ•œ๊ตญ์–ด/์˜์–ด ํ˜ผ์šฉ ํ—ˆ์šฉ) =====
192
 
193
  examples = [
194
+ "Mr. KIM์ด ๋‘ ์†์œผ๋กœ 'Fighting!' ํ˜„์ˆ˜๋ง‰์„ ๋“ค๊ณ  ์žˆ๋Š” ๋ชจ์Šต, ์• ๊ตญ์‹ฌ๊ณผ ๊ตญ๊ฐ€ ๋ฐœ์ „์— ๋Œ€ํ•œ ์˜์ง€๋ฅผ ๋ณด์—ฌ์ฃผ๊ณ  ์žˆ๋‹ค.",
195
+ "Mr. KIM์ด ์–‘ํŒ”์„ ๋“ค์–ด ์˜ฌ๋ฆฌ๋ฉฐ ์Šน๋ฆฌ์˜ ํ‘œ์ •์œผ๋กœ ํ™˜ํ˜ธํ•˜๋Š” ๋ชจ์Šต, ์Šน๋ฆฌ์™€ ๋ฏธ๋ž˜์— ๋Œ€ํ•œ ํฌ๋ง์„ ๋ณด์—ฌ์ฃผ๊ณ  ์žˆ๋‹ค.",
196
+ "Mr. KIM์ด ์šด๋™๋ณต์„ ์ž…๊ณ  ๊ณต์›์—์„œ ์กฐ๊น…ํ•˜๋Š” ๋ชจ์Šต, ๊ฑด๊ฐ•ํ•œ ์ƒํ™œ์Šต๊ด€๊ณผ ํ™œ๊ธฐ์ฐฌ ๋ฆฌ๋”์‹ญ์„ ๋ณด์—ฌ์ฃผ๊ณ  ์žˆ๋‹ค.",
197
+ "Mr. KIM์ด ๋ถ๋น„๋Š” ๊ฑฐ๋ฆฌ์—์„œ ์—ฌ์„ฑ ์‹œ๋ฏผ๋“ค๊ณผ ๋”ฐ๋œปํ•˜๊ฒŒ ์•…์ˆ˜ํ•˜๋Š” ๋ชจ์Šต, ์—ฌ์„ฑ ์œ ๊ถŒ์ž๋“ค์— ๋Œ€ํ•œ ์ง„์ •ํ•œ ๊ด€์‹ฌ๊ณผ ์†Œํ†ต์„ ๋ณด์—ฌ์ฃผ๊ณ  ์žˆ๋‹ค.",
198
+ "Mr. KIM์ด ์„ ๊ฑฐ ์œ ์„ธ์žฅ์—์„œ ์ง€ํ‰์„ ์„ ํ–ฅํ•ด ์†๊ฐ€๋ฝ์œผ๋กœ ๊ฐ€๋ฆฌํ‚ค๋ฉฐ ์˜๊ฐ์„ ์ฃผ๋Š” ์ œ์Šค์ฒ˜๋ฅผ ์ทจํ•˜๊ณ  ์žˆ๊ณ , ์—ฌ์„ฑ๋“ค๊ณผ ์•„์ด๋“ค์ด ๋ฐ•์ˆ˜๋ฅผ ์น˜๊ณ  ์žˆ๋‹ค.",
199
+ "Mr. KIM์ด ์ง€์—ญ ํ–‰์‚ฌ์— ์ฐธ์—ฌํ•˜์—ฌ ์—ด์ •์ ์œผ๋กœ ์‘์›ํ•˜๋Š” ์—ฌ์„ฑ ์ง€์ง€์ž๋“ค์—๊ฒŒ ๋‘˜๋Ÿฌ์‹ธ์—ฌ ์žˆ๋Š” ๋ชจ์Šต.",
200
+ "Mr. KIM visiting a local market, engaging in friendly conversation with female vendors and shopkeepers.",
201
+ "Mr. KIM walking through a university campus, discussing education policies with female students and professors.",
202
+ "Mr. KIM delivering a powerful speech in front of a large crowd with confident gestures and determined expression.",
203
  "Mr. KIM in a dynamic interview setting, passionately outlining his visions for the future.",
204
+ "Mr. KIM preparing for an important debate, surrounded by paperwork, looking focused and resolute.",
205
  ]
206
 
207
+ # ===== ์ปค์Šคํ…€ CSS (๋ถ‰์€ ํ†ค ์œ ์ง€) =====
208
  custom_css = """
209
  :root {
210
+ --color-primary: #8F1A3A;
211
+ --color-secondary: #FF4B4B;
212
  --background-fill-primary: linear-gradient(to right, #FFF5F5, #FED7D7, #FEB2B2);
213
  }
214
+ footer {visibility: hidden;}
215
+ .gradio-container {background: var(--background-fill-primary);}
216
+ .title {color: var(--color-primary)!important; font-size:3rem!important; font-weight:700!important; text-align:center; margin:1rem 0; font-family:'Playfair Display',serif;}
217
+ .subtitle {color:#4A5568!important; font-size:1.2rem!important; text-align:center; margin-bottom:1.5rem; font-style:italic;}
218
+ .collection-link {text-align:center; margin-bottom:2rem; font-size:1.1rem;}
219
+ .collection-link a {color:var(--color-primary); text-decoration:underline; transition:color .3s ease;}
220
+ .collection-link a:hover {color:var(--color-secondary);}
221
+ .model-description{background:rgba(255,255,255,.8); border-radius:12px; padding:24px; margin:20px 0; box-shadow:0 4px 12px rgba(0,0,0,.05); border-left:5px solid var(--color-primary);}
222
+ button.primary{background:var(--color-primary)!important; color:#fff!important; transition:all .3s ease;}
223
+ button:hover{transform:translateY(-2px); box-shadow:0 5px 15px rgba(0,0,0,.1);}
224
+ .input-container{border-radius:10px; box-shadow:0 2px 8px rgba(0,0,0,.05); background:rgba(255,255,255,.6); padding:20px; margin-bottom:1rem;}
225
+ .advanced-settings{margin-top:1rem; padding:1rem; border-radius:10px; background:rgba(255,255,255,.6);}
226
+ .example-region{background:rgba(255,255,255,.5); border-radius:10px; padding:1rem; margin-top:1rem;}
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
227
  """
228
 
229
+ # ===== Gradio UI =====
230
+ def create_interface():
231
+ with gr.Blocks(css=custom_css, analytics_enabled=False) as demo:
232
+ gr.HTML('<div class="title">Mr. KIM in KOREA</div>')
233
+ gr.HTML('<div class="collection-link"><a href="https://huggingface.co/collections/openfree/painting-art-ai-681453484ec15ef5978bbeb1" target="_blank">Visit the LoRA Model Collection</a></div>')
234
+
235
+ with gr.Group(elem_classes="model-description"):
236
+ gr.HTML("""
237
+ <p>
238
+ ๋ณธ ๋ชจ๋ธ์€ ์—ฐ๊ตฌ ๋ชฉ์ ์œผ๋กœ ํŠน์ •์ธ์˜ ์–ผ๊ตด๊ณผ ์™ธ๋ชจ๋ฅผ ํ•™์Šตํ•œ LoRA ๋ชจ๋ธ์ž…๋‹ˆ๋‹ค.<br>
239
+ ๋ชฉ์ ์™ธ์˜ ์šฉ๋„๋กœ ๋ฌด๋‹จ ์‚ฌ์šฉ ์•Š๋„๋ก ์œ ์˜ํ•ด ์ฃผ์„ธ์š”.<br>
240
+ (์˜ˆ์‹œ prompt ์‚ฌ์šฉ ์‹œ ๋ฐ˜๋“œ์‹œ 'kim'์„ ํฌํ•จํ•˜์—ฌ์•ผ ์ตœ์ ์˜ ๊ฒฐ๊ณผ๋ฅผ ์–ป์„ ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.)
241
+ </p>
242
+ """)
243
+
244
+ # ===== ๋ฉ”์ธ ์ž…๋ ฅ =====
245
+ with gr.Column():
246
+ with gr.Row(elem_classes="input-container"):
247
+ user_prompt = gr.Text(label="Prompt", max_lines=1, value=examples[0])
248
+ style_select = gr.Radio(label="Style Preset", choices=list(STYLE_PRESETS.keys()), value="None", interactive=True)
249
+ run_button = gr.Button("Generate", variant="primary")
250
+
251
+ result_image = gr.Image(label="Generated Image")
252
+ seed_output = gr.Number(label="Seed")
253
+
254
+ # ===== ๊ณ ๊ธ‰ ์„ค์ • =====
255
+ with gr.Accordion("Advanced Settings", open=False, elem_classes="advanced-settings"):
256
+ seed = gr.Slider(label="Seed", minimum=0, maximum=MAX_SEED, step=1, value=42)
257
+ randomize_seed = gr.Checkbox(label="Randomize seed", value=True)
258
+ with gr.Row():
259
+ width = gr.Slider(label="Width", minimum=256, maximum=MAX_IMAGE_SIZE, step=32, value=1024)
260
+ height = gr.Slider(label="Height", minimum=256, maximum=MAX_IMAGE_SIZE, step=32, value=768)
261
+ with gr.Row():
262
+ guidance_scale = gr.Slider(label="Guidance scale", minimum=0.0, maximum=10.0, step=0.1, value=3.5)
263
+ num_inference_steps = gr.Slider(label="Inference steps", minimum=1, maximum=50, step=1, value=30)
264
+ lora_scale = gr.Slider(label="LoRA scale", minimum=0.0, maximum=1.0, step=0.1, value=1.0)
265
+
266
+ # ===== ์˜ˆ์‹œ ์˜์—ญ =====
267
+ with gr.Group(elem_classes="example-region"):
268
+ gr.Markdown("### Examples")
269
+ gr.Examples(examples=examples, inputs=user_prompt, cache_examples=False)
270
+
271
+ # ===== ์ด๋ฒคํŠธ =====
272
+ run_button.click(
273
+ fn=generate_image,
274
+ inputs=[
275
+ user_prompt,
276
+ style_select,
277
+ seed,
278
+ randomize_seed,
279
+ width,
280
+ height,
281
+ guidance_scale,
282
+ num_inference_steps,
283
+ lora_scale,
284
+ ],
285
+ outputs=[result_image, seed_output],
286
+ )
287
 
288
+ return demo
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
289
 
290
+ # ===== ์• ํ”Œ๋ฆฌ์ผ€์ด์…˜ ์‹คํ–‰ =====
291
+ if __name__ == "__main__":
292
+ demo = create_interface()
293
+ demo.queue()
294
+ demo.launch()