ginipick commited on
Commit
614753e
·
verified ·
1 Parent(s): dc5f20e

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +35 -23
app.py CHANGED
@@ -12,6 +12,8 @@ import torch
12
  from diffusers import FluxPipeline
13
  from PIL import Image
14
  from transformers import pipeline
 
 
15
 
16
  translator = pipeline("translation", model="Helsinki-NLP/opus-mt-ko-en")
17
 
@@ -268,37 +270,47 @@ with gr.Blocks(
268
  value="3d.webp"
269
  )
270
 
271
- # Gallery 섹션
272
  with gr.Row(elem_classes="gallery-container"):
273
  gr.HTML("<h2 class='gallery-title'>Gallery</h2>")
274
  gallery_html = "<div style='display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 20px;'>"
275
 
276
- for img_file, sample_prompt in SAMPLE_IMAGES.items():
277
- if os.path.exists(img_file):
278
- gallery_html += f"""
279
- <div style='
280
- border: 1px solid #ddd;
281
- border-radius: 10px;
282
- padding: 10px;
283
- background: white;
284
- box-shadow: 0 4px 8px rgba(0,0,0,0.1);
285
- '>
286
- <img src='file/{img_file}'
287
- style='width: 100%;
288
- border-radius: 8px;
289
- margin-bottom: 10px;'
290
- >
291
- <p style='
292
- margin: 5px 0;
293
- font-weight: bold;
294
- color: #333;
295
  padding: 10px;
296
- '>Prompt: {sample_prompt}</p>
297
- </div>
298
- """
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
299
 
300
  gallery_html += "</div>"
301
  gr.HTML(gallery_html)
 
 
302
 
303
  # 이벤트 바인딩
304
  generate_btn.click(
 
12
  from diffusers import FluxPipeline
13
  from PIL import Image
14
  from transformers import pipeline
15
+ import base64
16
+
17
 
18
  translator = pipeline("translation", model="Helsinki-NLP/opus-mt-ko-en")
19
 
 
270
  value="3d.webp"
271
  )
272
 
273
+ # Gallery 섹션
274
  with gr.Row(elem_classes="gallery-container"):
275
  gr.HTML("<h2 class='gallery-title'>Gallery</h2>")
276
  gallery_html = "<div style='display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 20px;'>"
277
 
278
+ for img_file, prompt in SAMPLE_IMAGES.items():
279
+ img_path = os.path.abspath(img_file) # 절대 경로로 변환
280
+ if os.path.exists(img_path):
281
+ try:
282
+ # Base64로 이미지 인코딩
283
+ with open(img_path, "rb") as img:
284
+ img_data = base64.b64encode(img.read()).decode()
285
+
286
+ gallery_html += f"""
287
+ <div style='
288
+ border: 1px solid #ddd;
289
+ border-radius: 10px;
 
 
 
 
 
 
 
290
  padding: 10px;
291
+ background: white;
292
+ box-shadow: 0 4px 8px rgba(0,0,0,0.1);
293
+ '>
294
+ <img src='data:image/webp;base64,{img_data}'
295
+ style='width: 100%;
296
+ border-radius: 8px;
297
+ margin-bottom: 10px;'
298
+ >
299
+ <p style='
300
+ margin: 5px 0;
301
+ font-weight: bold;
302
+ color: #333;
303
+ padding: 10px;
304
+ '>Prompt: {prompt}</p>
305
+ </div>
306
+ """
307
+ except Exception as e:
308
+ print(f"Error loading image {img_file}: {str(e)}")
309
 
310
  gallery_html += "</div>"
311
  gr.HTML(gallery_html)
312
+
313
+
314
 
315
  # 이벤트 바인딩
316
  generate_btn.click(