ginipick commited on
Commit
18c2419
ยท
verified ยท
1 Parent(s): 5659cec

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +11 -42
app.py CHANGED
@@ -14,7 +14,6 @@ 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
 
20
  # Hugging Face ํ† ํฐ ์„ค์ •
@@ -124,7 +123,7 @@ def process_and_save_image(height=1024, width=1024, steps=8, scales=3.5, prompt=
124
  translated = translator(prompt)[0]['translation_text']
125
  prompt = translated
126
 
127
- formatted_prompt = f"wbgmsst, 3D, {prompt} ,white background"
128
 
129
  with torch.inference_mode(), torch.autocast("cuda", dtype=torch.bfloat16), timer("inference"):
130
  try:
@@ -147,19 +146,9 @@ def process_and_save_image(height=1024, width=1024, steps=8, scales=3.5, prompt=
147
  print(f"Error in image generation: {str(e)}")
148
  return None
149
 
150
- def generate_image(h, w, s, sc, p, sd):
151
- """Gradio์—์„œ ๋„˜๊ฒจ๋ฐ›์€ ํŒŒ๋ผ๋ฏธํ„ฐ ์ˆœ์„œ์— ๋งž์ถฐ ์ด๋ฏธ์ง€ ์ƒ์„ฑ ํ•จ์ˆ˜ ํ˜ธ์ถœ"""
152
- return process_and_save_image(
153
- height=h,
154
- width=w,
155
- steps=s,
156
- scales=sc,
157
- prompt=p,
158
- seed=sd
159
- )
160
-
161
  def update_random_seed():
162
- return gr.Number.update(value=get_random_seed())
 
163
 
164
  # Gradio ์ธํ„ฐํŽ˜์ด์Šค
165
  with gr.Blocks(
@@ -270,12 +259,12 @@ with gr.Blocks(
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:
@@ -283,6 +272,7 @@ with gr.Blocks(
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;
@@ -301,7 +291,7 @@ with gr.Blocks(
301
  font-weight: bold;
302
  color: #333;
303
  padding: 10px;
304
- '>Prompt: {prompt}</p>
305
  </div>
306
  """
307
  except Exception as e:
@@ -310,31 +300,10 @@ with gr.Blocks(
310
  gallery_html += "</div>"
311
  gr.HTML(gallery_html)
312
 
313
- # ์ด๋ฒคํŠธ ํ•ธ๋“ค๋Ÿฌ ๋ถ€๋ถ„๋งŒ ์ˆ˜์ •
314
- def generate_image(h, w, s, sc, p, sd):
315
- return process_and_save_image(
316
- height=h,
317
- width=w,
318
- steps=s,
319
- scales=sc,
320
- prompt=p,
321
- seed=sd
322
- )
323
-
324
- def update_random_seed():
325
- return gr.update(value=get_random_seed())
326
-
327
- # ์ด๋ฒคํŠธ ๋ฐ”์ธ๋”ฉ
328
  generate_btn.click(
329
- fn=process_and_save_image, # ์ง์ ‘ process_and_save_image ํ•จ์ˆ˜ ์‚ฌ์šฉ
330
- inputs={
331
- "height": height,
332
- "width": width,
333
- "steps": steps,
334
- "scales": scales,
335
- "prompt": prompt,
336
- "seed": seed
337
- },
338
  outputs=output
339
  )
340
 
@@ -345,4 +314,4 @@ with gr.Blocks(
345
  )
346
 
347
  if __name__ == "__main__":
348
- demo.launch(allowed_paths=[PERSISTENT_DIR])
 
14
  from transformers import pipeline
15
  import base64
16
 
 
17
  translator = pipeline("translation", model="Helsinki-NLP/opus-mt-ko-en")
18
 
19
  # Hugging Face ํ† ํฐ ์„ค์ •
 
123
  translated = translator(prompt)[0]['translation_text']
124
  prompt = translated
125
 
126
+ formatted_prompt = f"wbgmsst, 3D, {prompt}, white background"
127
 
128
  with torch.inference_mode(), torch.autocast("cuda", dtype=torch.bfloat16), timer("inference"):
129
  try:
 
146
  print(f"Error in image generation: {str(e)}")
147
  return None
148
 
 
 
 
 
 
 
 
 
 
 
 
149
  def update_random_seed():
150
+ """๋ฒ„ํŠผ์œผ๋กœ ๋ˆŒ๋ €์„ ๋•Œ ์ƒˆ๋กœ์šด ์‹œ๋“œ๋ฅผ ์—…๋ฐ์ดํŠธ"""
151
+ return gr.update(value=get_random_seed())
152
 
153
  # Gradio ์ธํ„ฐํŽ˜์ด์Šค
154
  with gr.Blocks(
 
259
  value="3d.webp"
260
  )
261
 
262
+ # Gallery ์„น์…˜
263
  with gr.Row(elem_classes="gallery-container"):
264
  gr.HTML("<h2 class='gallery-title'>Gallery</h2>")
265
  gallery_html = "<div style='display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 20px;'>"
266
 
267
+ for img_file, prompt_text in SAMPLE_IMAGES.items():
268
  img_path = os.path.abspath(img_file) # ์ ˆ๋Œ€ ๊ฒฝ๋กœ๋กœ ๋ณ€ํ™˜
269
  if os.path.exists(img_path):
270
  try:
 
272
  with open(img_path, "rb") as img:
273
  img_data = base64.b64encode(img.read()).decode()
274
 
275
+ # 3d1.webp ํŒŒ์ผ์ด๋ฏ€๋กœ MIMEํƒ€์ž…์€ webp
276
  gallery_html += f"""
277
  <div style='
278
  border: 1px solid #ddd;
 
291
  font-weight: bold;
292
  color: #333;
293
  padding: 10px;
294
+ '>Prompt: {prompt_text}</p>
295
  </div>
296
  """
297
  except Exception as e:
 
300
  gallery_html += "</div>"
301
  gr.HTML(gallery_html)
302
 
303
+ # ์ด๋ฒคํŠธ ํ•ธ๋“ค๋Ÿฌ
 
 
 
 
 
 
 
 
 
 
 
 
 
 
304
  generate_btn.click(
305
+ fn=process_and_save_image,
306
+ inputs=[height, width, steps, scales, prompt, seed], # ๋”•์…”๋„ˆ๋ฆฌ ๋Œ€์‹  ๋ฆฌ์ŠคํŠธ ํ˜•ํƒœ
 
 
 
 
 
 
 
307
  outputs=output
308
  )
309
 
 
314
  )
315
 
316
  if __name__ == "__main__":
317
+ demo.launch(allowed_paths=[PERSISTENT_DIR])