ginipick commited on
Commit
5ce58bf
โ€ข
1 Parent(s): 44731e7

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +106 -41
app.py CHANGED
@@ -12,6 +12,44 @@ import copy
12
  import random
13
  import time
14
  from transformers import pipeline
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
15
 
16
  # ๋ฒˆ์—ญ ๋ชจ๋ธ ์ดˆ๊ธฐํ™”
17
  translator = pipeline("translation", model="Helsinki-NLP/opus-mt-ko-en")
@@ -143,7 +181,10 @@ def run_lora(prompt, cfg_scale, steps, selected_index, randomize_seed, seed, wid
143
  final_image = image
144
  progress_bar = f'<div class="progress-container"><div class="progress-bar" style="--current: {step_counter}; --total: {steps};"></div></div>'
145
  yield image, seed, gr.update(value=progress_bar, visible=True), original_prompt, english_prompt
146
-
 
 
 
147
  yield final_image, seed, gr.update(value=progress_bar, visible=False), original_prompt, english_prompt
148
 
149
 
@@ -222,6 +263,7 @@ def add_custom_lora(custom_lora):
222
  def remove_custom_lora():
223
  return gr.update(visible=False), gr.update(visible=False), gr.update(), "", None, ""
224
 
 
225
  run_lora.zerogpu = True
226
 
227
  css = """
@@ -230,52 +272,70 @@ footer {
230
  }
231
  """
232
 
 
 
 
 
 
 
233
 
234
  with gr.Blocks(theme="Nymbo/Nymbo_Theme", css=css) as app:
235
 
236
  selected_index = gr.State(None)
237
- with gr.Row():
238
- with gr.Column(scale=3):
239
- prompt = gr.Textbox(label="ํ”„๋กฌํ”„ํŠธ", lines=1, placeholder="LoRA๋ฅผ ์„ ํƒํ•œ ํ›„ ํ”„๋กฌํ”„ํŠธ๋ฅผ ์ž…๋ ฅํ•˜์„ธ์š” (ํ•œ๊ธ€ ๋˜๋Š” ์˜์–ด)")
240
- with gr.Column(scale=1, elem_id="gen_column"):
241
- generate_button = gr.Button("์ƒ์„ฑ", variant="primary", elem_id="gen_btn")
242
- with gr.Row():
243
- with gr.Column():
244
- selected_info = gr.Markdown("")
245
- gallery = gr.Gallery(
246
- [(item["image"], item["title"]) for item in loras],
247
- label="LoRA ๊ฐค๋Ÿฌ๋ฆฌ",
248
- allow_preview=False,
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
249
  columns=3,
250
- elem_id="gallery"
 
251
  )
252
- with gr.Group():
253
- custom_lora = gr.Textbox(label="์ปค์Šคํ…€ LoRA", info="LoRA Hugging Face ๊ฒฝ๋กœ", placeholder="multimodalart/vintage-ads-flux")
254
- gr.Markdown("[FLUX LoRA ๋ชฉ๋ก ํ™•์ธ](https://huggingface.co/models?other=base_model:adapter:black-forest-labs/FLUX.1-dev)", elem_id="lora_list")
255
- custom_lora_info = gr.HTML(visible=False)
256
- custom_lora_button = gr.Button("์ปค์Šคํ…€ LoRA ์ œ๊ฑฐ", visible=False)
257
- with gr.Column():
258
- progress_bar = gr.Markdown(elem_id="progress",visible=False)
259
- result = gr.Image(label="์ƒ์„ฑ๋œ ์ด๋ฏธ์ง€")
260
- original_prompt_display = gr.Textbox(label="์›๋ณธ ํ”„๋กฌํ”„ํŠธ")
261
- english_prompt_display = gr.Textbox(label="์˜์–ด ํ”„๋กฌํ”„ํŠธ")
262
-
263
- with gr.Row():
264
- with gr.Accordion("๊ณ ๊ธ‰ ์„ค์ •", open=False):
265
- with gr.Column():
266
- with gr.Row():
267
- cfg_scale = gr.Slider(label="CFG ์Šค์ผ€์ผ", minimum=1, maximum=20, step=0.5, value=3.5)
268
- steps = gr.Slider(label="์Šคํ…", minimum=1, maximum=50, step=1, value=28)
269
-
270
- with gr.Row():
271
- width = gr.Slider(label="๋„ˆ๋น„", minimum=256, maximum=1536, step=64, value=1024)
272
- height = gr.Slider(label="๋†’์ด", minimum=256, maximum=1536, step=64, value=1024)
273
-
274
- with gr.Row():
275
- randomize_seed = gr.Checkbox(True, label="์‹œ๋“œ ๋ฌด์ž‘์œ„ํ™”")
276
- seed = gr.Slider(label="์‹œ๋“œ", minimum=0, maximum=MAX_SEED, step=1, value=0, randomize=True)
277
- lora_scale = gr.Slider(label="LoRA ์Šค์ผ€์ผ", minimum=0, maximum=3, step=0.01, value=0.95)
278
-
279
 
280
  gallery.select(
281
  update_selection,
@@ -299,5 +359,10 @@ with gr.Blocks(theme="Nymbo/Nymbo_Theme", css=css) as app:
299
  outputs=[result, seed, progress_bar, original_prompt_display, english_prompt_display]
300
  )
301
 
 
 
 
 
 
302
  app.queue()
303
  app.launch()
 
12
  import random
13
  import time
14
  from transformers import pipeline
15
+ import sqlite3
16
+ from datetime import datetime
17
+
18
+ # ๋ฐ์ดํ„ฐ๋ฒ ์ด์Šค ์ดˆ๊ธฐํ™”
19
+ def init_db():
20
+ conn = sqlite3.connect('gallery.db')
21
+ c = conn.cursor()
22
+ c.execute('''CREATE TABLE IF NOT EXISTS images
23
+ (id INTEGER PRIMARY KEY AUTOINCREMENT,
24
+ model_name TEXT,
25
+ prompt TEXT,
26
+ image_path TEXT,
27
+ created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP)''')
28
+ conn.commit()
29
+ conn.close()
30
+
31
+ # ์ด๋ฏธ์ง€ ์ €์žฅ ํ•จ์ˆ˜
32
+ def save_image(image, model_name, prompt):
33
+ timestamp = datetime.now().strftime("%Y%m%d_%H%M%S")
34
+ filename = f"gallery_{timestamp}.png"
35
+ image.save(os.path.join("gallery", filename))
36
+
37
+ conn = sqlite3.connect('gallery.db')
38
+ c = conn.cursor()
39
+ c.execute("INSERT INTO images (model_name, prompt, image_path) VALUES (?, ?, ?)",
40
+ (model_name, prompt, filename))
41
+ conn.commit()
42
+ conn.close()
43
+
44
+ # ๊ฐค๋Ÿฌ๋ฆฌ ์ด๋ฏธ์ง€ ๋กœ๋“œ ํ•จ์ˆ˜
45
+ def load_gallery_images():
46
+ conn = sqlite3.connect('gallery.db')
47
+ c = conn.cursor()
48
+ c.execute("SELECT model_name, prompt, image_path FROM images ORDER BY created_at DESC")
49
+ rows = c.fetchall()
50
+ conn.close()
51
+
52
+ return [(os.path.join("gallery", row[2]), f"{row[0]}: {row[1]}") for row in rows]
53
 
54
  # ๋ฒˆ์—ญ ๋ชจ๋ธ ์ดˆ๊ธฐํ™”
55
  translator = pipeline("translation", model="Helsinki-NLP/opus-mt-ko-en")
 
181
  final_image = image
182
  progress_bar = f'<div class="progress-container"><div class="progress-bar" style="--current: {step_counter}; --total: {steps};"></div></div>'
183
  yield image, seed, gr.update(value=progress_bar, visible=True), original_prompt, english_prompt
184
+
185
+ # ๊ฐค๋Ÿฌ๋ฆฌ์— ์ด๋ฏธ์ง€ ์ €์žฅ
186
+ save_image(final_image, selected_lora['title'], original_prompt)
187
+
188
  yield final_image, seed, gr.update(value=progress_bar, visible=False), original_prompt, english_prompt
189
 
190
 
 
263
  def remove_custom_lora():
264
  return gr.update(visible=False), gr.update(visible=False), gr.update(), "", None, ""
265
 
266
+
267
  run_lora.zerogpu = True
268
 
269
  css = """
 
272
  }
273
  """
274
 
275
+ # ๊ฐค๋Ÿฌ๋ฆฌ ๋””๋ ‰ํ† ๋ฆฌ ์ƒ์„ฑ
276
+ if not os.path.exists('gallery'):
277
+ os.makedirs('gallery')
278
+
279
+ # ๋ฐ์ดํ„ฐ๋ฒ ์ด์Šค ์ดˆ๊ธฐํ™”
280
+ init_db()
281
 
282
  with gr.Blocks(theme="Nymbo/Nymbo_Theme", css=css) as app:
283
 
284
  selected_index = gr.State(None)
285
+
286
+ with gr.Tabs():
287
+ with gr.TabItem("์ƒ์„ฑ"):
288
+ with gr.Row():
289
+ with gr.Column(scale=3):
290
+ prompt = gr.Textbox(label="ํ”„๋กฌํ”„ํŠธ", lines=1, placeholder="LoRA๋ฅผ ์„ ํƒํ•œ ํ›„ ํ”„๋กฌํ”„ํŠธ๋ฅผ ์ž…๋ ฅํ•˜์„ธ์š” (ํ•œ๊ธ€ ๋˜๋Š” ์˜์–ด)")
291
+ with gr.Column(scale=1, elem_id="gen_column"):
292
+ generate_button = gr.Button("์ƒ์„ฑ", variant="primary", elem_id="gen_btn")
293
+ with gr.Row():
294
+ with gr.Column():
295
+ selected_info = gr.Markdown("")
296
+ gallery = gr.Gallery(
297
+ [(item["image"], item["title"]) for item in loras],
298
+ label="LoRA ๊ฐค๋Ÿฌ๋ฆฌ",
299
+ allow_preview=False,
300
+ columns=3,
301
+ elem_id="gallery"
302
+ )
303
+ with gr.Group():
304
+ custom_lora = gr.Textbox(label="์ปค์Šคํ…€ LoRA", info="LoRA Hugging Face ๊ฒฝ๋กœ", placeholder="multimodalart/vintage-ads-flux")
305
+ gr.Markdown("[FLUX LoRA ๋ชฉ๋ก ํ™•์ธ](https://huggingface.co/models?other=base_model:adapter:black-forest-labs/FLUX.1-dev)", elem_id="lora_list")
306
+ custom_lora_info = gr.HTML(visible=False)
307
+ custom_lora_button = gr.Button("์ปค์Šคํ…€ LoRA ์ œ๊ฑฐ", visible=False)
308
+ with gr.Column():
309
+ progress_bar = gr.Markdown(elem_id="progress",visible=False)
310
+ result = gr.Image(label="์ƒ์„ฑ๋œ ์ด๋ฏธ์ง€")
311
+ original_prompt_display = gr.Textbox(label="์›๋ณธ ํ”„๋กฌํ”„ํŠธ")
312
+ english_prompt_display = gr.Textbox(label="์˜์–ด ํ”„๋กฌํ”„ํŠธ")
313
+
314
+ with gr.Row():
315
+ with gr.Accordion("๊ณ ๊ธ‰ ์„ค์ •", open=False):
316
+ with gr.Column():
317
+ with gr.Row():
318
+ cfg_scale = gr.Slider(label="CFG ์Šค์ผ€์ผ", minimum=1, maximum=20, step=0.5, value=3.5)
319
+ steps = gr.Slider(label="์Šคํ…", minimum=1, maximum=50, step=1, value=28)
320
+
321
+ with gr.Row():
322
+ width = gr.Slider(label="๋„ˆ๋น„", minimum=256, maximum=1536, step=64, value=1024)
323
+ height = gr.Slider(label="๋†’์ด", minimum=256, maximum=1536, step=64, value=1024)
324
+
325
+ with gr.Row():
326
+ randomize_seed = gr.Checkbox(True, label="์‹œ๋“œ ๋ฌด์ž‘์œ„ํ™”")
327
+ seed = gr.Slider(label="์‹œ๋“œ", minimum=0, maximum=MAX_SEED, step=1, value=0, randomize=True)
328
+ lora_scale = gr.Slider(label="LoRA ์Šค์ผ€์ผ", minimum=0, maximum=3, step=0.01, value=0.95)
329
+
330
+ with gr.TabItem("๊ฐค๋Ÿฌ๋ฆฌ"):
331
+ gallery_images = gr.Gallery(
332
+ load_gallery_images(),
333
+ label="์ƒ์„ฑ๋œ ์ด๋ฏธ์ง€ ๊ฐค๋Ÿฌ๋ฆฌ",
334
  columns=3,
335
+ rows=3,
336
+ height="auto"
337
  )
338
+ refresh_button = gr.Button("๊ฐค๋Ÿฌ๋ฆฌ ์ƒˆ๋กœ๊ณ ์นจ")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
339
 
340
  gallery.select(
341
  update_selection,
 
359
  outputs=[result, seed, progress_bar, original_prompt_display, english_prompt_display]
360
  )
361
 
362
+ refresh_button.click(
363
+ lambda: gr.update(value=load_gallery_images()),
364
+ outputs=[gallery_images]
365
+ )
366
+
367
  app.queue()
368
  app.launch()