ginipick commited on
Commit
955c611
ยท
verified ยท
1 Parent(s): 9488128

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +18 -52
app.py CHANGED
@@ -103,20 +103,8 @@ def save_image(image):
103
  print(f"Error in save_image: {str(e)}")
104
  return None
105
 
106
- # ์˜ˆ์‹œ ํ”„๋กฌํ”„ํŠธ ์ •์˜ ๋ถ€๋ถ„์„ ์ˆ˜์ •
107
- example_prompts = [
108
- "A 3D Star Wars Darth Vader helmet, highly detailed metallic finish",
109
- "A 3D Iron Man mask with glowing eyes and metallic red-gold finish",
110
- "A 3D Pokemon Pikachu figure with glossy surface",
111
- "A 3D geometric abstract cube transforming into a sphere, metallic finish",
112
- "A 3D steampunk mechanical heart with brass and copper details",
113
- "A 3D crystal dragon with transparent iridescent scales",
114
- "A 3D futuristic hovering drone with neon light accents",
115
- "A 3D ancient Greek warrior helmet with ornate details",
116
- "A 3D robotic butterfly with mechanical wings and metallic finish",
117
- "A 3D floating magical crystal orb with internal energy swirls"
118
- ]
119
-
120
 
121
  @spaces.GPU
122
  def process_and_save_image(height=1024, width=1024, steps=8, scales=3.5, prompt="", seed=None):
@@ -157,20 +145,19 @@ def process_and_save_image(height=1024, width=1024, steps=8, scales=3.5, prompt=
157
  print(f"Error in image generation: {str(e)}")
158
  return None
159
 
160
- def get_random_seed():
161
- return torch.randint(0, 1000000, (1,)).item()
162
-
163
- def process_example(prompt):
164
  return process_and_save_image(
165
- height=1024,
166
- width=1024,
167
- steps=8,
168
- scales=3.5,
169
- prompt=prompt,
170
- seed=get_random_seed()
171
  )
172
 
173
- # example_prompts ๋ณ€์ˆ˜์™€ process_example ํ•จ์ˆ˜ ์ œ๊ฑฐ
 
174
 
175
  # Gradio ์ธํ„ฐํŽ˜์ด์Šค
176
  with gr.Blocks(
@@ -286,7 +273,7 @@ with gr.Blocks(
286
  gr.HTML("<h2 class='gallery-title'>Gallery</h2>")
287
  gallery_html = "<div style='display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 20px;'>"
288
 
289
- for img_file, prompt in SAMPLE_IMAGES.items():
290
  if os.path.exists(img_file):
291
  gallery_html += f"""
292
  <div style='
@@ -306,46 +293,25 @@ with gr.Blocks(
306
  font-weight: bold;
307
  color: #333;
308
  padding: 10px;
309
- '>Prompt: {prompt}</p>
310
  </div>
311
  """
312
 
313
  gallery_html += "</div>"
314
  gr.HTML(gallery_html)
315
 
316
- # ์ด๋ฒคํŠธ ํ•ธ๋“ค๋Ÿฌ ๋ถ€๋ถ„๋งŒ ์ˆ˜์ •
317
- def generate_image(h, w, s, sc, p, sd):
318
- return process_and_save_image(
319
- height=h,
320
- width=w,
321
- steps=s,
322
- scales=sc,
323
- prompt=p,
324
- seed=sd
325
- )
326
-
327
- def update_random_seed():
328
- return gr.Number.update(value=get_random_seed())
329
-
330
  # ์ด๋ฒคํŠธ ๋ฐ”์ธ๋”ฉ
331
  generate_btn.click(
332
- generate_image,
333
- inputs={
334
- "h": height,
335
- "w": width,
336
- "s": steps,
337
- "sc": scales,
338
- "p": prompt,
339
- "sd": seed
340
- },
341
  outputs=output
342
  )
343
 
344
  randomize_seed.click(
345
- update_random_seed,
346
  inputs=None,
347
  outputs=seed
348
  )
349
 
350
  if __name__ == "__main__":
351
- demo.launch(allowed_paths=[PERSISTENT_DIR])
 
103
  print(f"Error in save_image: {str(e)}")
104
  return None
105
 
106
+ def get_random_seed():
107
+ return torch.randint(0, 1000000, (1,)).item()
 
 
 
 
 
 
 
 
 
 
 
 
108
 
109
  @spaces.GPU
110
  def process_and_save_image(height=1024, width=1024, steps=8, scales=3.5, prompt="", seed=None):
 
145
  print(f"Error in image generation: {str(e)}")
146
  return None
147
 
148
+ def generate_image(h, w, s, sc, p, sd):
149
+ """Gradio์—์„œ ๋„˜๊ฒจ๋ฐ›์€ ํŒŒ๋ผ๋ฏธํ„ฐ ์ˆœ์„œ์— ๋งž์ถฐ ์ด๋ฏธ์ง€ ์ƒ์„ฑ ํ•จ์ˆ˜ ํ˜ธ์ถœ"""
 
 
150
  return process_and_save_image(
151
+ height=h,
152
+ width=w,
153
+ steps=s,
154
+ scales=sc,
155
+ prompt=p,
156
+ seed=sd
157
  )
158
 
159
+ def update_random_seed():
160
+ return gr.Number.update(value=get_random_seed())
161
 
162
  # Gradio ์ธํ„ฐํŽ˜์ด์Šค
163
  with gr.Blocks(
 
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='
 
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(
305
+ fn=generate_image,
306
+ inputs=[height, width, steps, scales, prompt, seed], # ๋”•์…”๋„ˆ๋ฆฌ ๋Œ€์‹  ์ˆœ์„œ๋Œ€๋กœ ๋ฆฌ์ŠคํŠธ
 
 
 
 
 
 
 
307
  outputs=output
308
  )
309
 
310
  randomize_seed.click(
311
+ fn=update_random_seed,
312
  inputs=None,
313
  outputs=seed
314
  )
315
 
316
  if __name__ == "__main__":
317
+ demo.launch(allowed_paths=[PERSISTENT_DIR])