openfree commited on
Commit
9066da8
ยท
verified ยท
1 Parent(s): a01dc26

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +29 -3
app.py CHANGED
@@ -4,6 +4,7 @@ import torch
4
  from einops import rearrange, repeat
5
  from PIL import Image
6
  import numpy as np
 
7
 
8
  from flux.sampling import denoise, get_noise, get_schedule, prepare, rf_denoise, rf_inversion, unpack
9
  from flux.util import (
@@ -71,6 +72,8 @@ except Exception as e:
71
  model_initialized = False
72
 
73
 
 
 
74
  @torch.inference_mode()
75
  def generate_image(
76
  prompt: str,
@@ -247,7 +250,7 @@ def generate_image(
247
 
248
 
249
  def create_demo():
250
- with gr.Blocks(theme="apriel") as demo:
251
  gr.Markdown("# PuLID: ์ธ๋ฌผ ์ด๋ฏธ์ง€ ๋ณ€ํ™˜ ๋„๊ตฌ")
252
 
253
  if not model_initialized:
@@ -278,7 +281,28 @@ def create_demo():
278
  seed_output = gr.Textbox(label="๊ฒฐ๊ณผ/์˜ค๋ฅ˜ ๋ฉ”์‹œ์ง€")
279
  gr.Markdown(_CITE_)
280
 
281
- # Gradio ์ด๋ฒคํŠธ ์—ฐ๊ฒฐ ์ˆ˜์ • - ์ง์ ‘ ์ •์ˆ˜ ๊ฐ’์„ ์ „๋‹ฌํ•˜์ง€ ์•Š๊ณ  UI ์ปดํฌ๋„ŒํŠธ๋งŒ ์ „๋‹ฌ
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
282
  generate_btn.click(
283
  fn=generate_image,
284
  inputs=[
@@ -300,5 +324,7 @@ if __name__ == "__main__":
300
  parser.add_argument("--port", type=int, default=8080)
301
  args = parser.parse_args()
302
 
 
 
303
  demo = create_demo()
304
- demo.launch(ssr_mode=False)
 
4
  from einops import rearrange, repeat
5
  from PIL import Image
6
  import numpy as np
7
+ import spaces # Hugging Face Spaces ์ž„ํฌํŠธ ์ถ”๊ฐ€
8
 
9
  from flux.sampling import denoise, get_noise, get_schedule, prepare, rf_denoise, rf_inversion, unpack
10
  from flux.util import (
 
72
  model_initialized = False
73
 
74
 
75
+ # Spaces GPU ๋ฐ์ฝ”๋ ˆ์ดํ„ฐ ์ถ”๊ฐ€ (120์ดˆ GPU ์‚ฌ์šฉ)
76
+ @spaces.GPU(duration=120)
77
  @torch.inference_mode()
78
  def generate_image(
79
  prompt: str,
 
250
 
251
 
252
  def create_demo():
253
+ with gr.Blocks() as demo:
254
  gr.Markdown("# PuLID: ์ธ๋ฌผ ์ด๋ฏธ์ง€ ๋ณ€ํ™˜ ๋„๊ตฌ")
255
 
256
  if not model_initialized:
 
281
  seed_output = gr.Textbox(label="๊ฒฐ๊ณผ/์˜ค๋ฅ˜ ๋ฉ”์‹œ์ง€")
282
  gr.Markdown(_CITE_)
283
 
284
+ # ์˜ˆ์ œ ์ถ”๊ฐ€
285
+ with gr.Row():
286
+ gr.Markdown("## ์˜ˆ์ œ")
287
+ example_inps = [
288
+ [
289
+ 'a portrait of a clown',
290
+ 'example_inputs/unsplash/lhon-karwan-11tbHtK5STE-unsplash.jpg',
291
+ 0.5, 3.5, "-1", 16, 0.4, "", 3.5, 0.5, 0.8
292
+ ],
293
+ [
294
+ 'a portrait of a zombie',
295
+ 'example_inputs/unsplash/baruk-granda-cfLL_jHQ-Iw-unsplash.jpg',
296
+ 0.4, 3.5, "42", 16, 0.4, "", 3.5, 0.5, 0.8
297
+ ]
298
+ ]
299
+ gr.Examples(
300
+ examples=example_inps,
301
+ inputs=[prompt, id_image, id_weight, guidance, seed, num_steps,
302
+ id_weight, neg_prompt, true_cfg, gamma, eta]
303
+ )
304
+
305
+ # Gradio ์ด๋ฒคํŠธ ์—ฐ๊ฒฐ
306
  generate_btn.click(
307
  fn=generate_image,
308
  inputs=[
 
324
  parser.add_argument("--port", type=int, default=8080)
325
  args = parser.parse_args()
326
 
327
+ print("Hugging Face Spaces ํ™˜๊ฒฝ์—์„œ ์‹คํ–‰ ์ค‘์ž…๋‹ˆ๋‹ค. GPU ํ• ๋‹น์„ ์š”์ฒญํ•ฉ๋‹ˆ๋‹ค.")
328
+
329
  demo = create_demo()
330
+ demo.queue(concurrency_count=1).launch(server_name="0.0.0.0", server_port=args.port)