xinglilu commited on
Commit
709e8b8
1 Parent(s): a992e53

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +25 -26
app.py CHANGED
@@ -3,36 +3,35 @@ import numpy as np
3
  import random
4
  import spaces
5
  import torch
6
- from diffusers import DiffusionPipeline, FlowMatchEulerDiscreteScheduler
7
- from transformers import CLIPTextModel, CLIPTokenizer,T5EncoderModel, T5TokenizerFast
8
 
9
  dtype = torch.bfloat16
10
  device = "cuda" if torch.cuda.is_available() else "cpu"
11
 
12
- pipe = DiffusionPipeline.from_pretrained("black-forest-labs/FLUX.1-dev", torch_dtype=torch.bfloat16).to(device)
13
 
14
  MAX_SEED = np.iinfo(np.int32).max
15
  MAX_IMAGE_SIZE = 2048
16
 
17
  @spaces.GPU(duration=190)
18
- def infer(prompt, seed=42, randomize_seed=False, width=1024, height=1024, guidance_scale=5.0, num_inference_steps=28, progress=gr.Progress(track_tqdm=True)):
19
  if randomize_seed:
20
  seed = random.randint(0, MAX_SEED)
21
  generator = torch.Generator().manual_seed(seed)
22
  image = pipe(
23
- prompt = prompt,
24
- width = width,
25
- height = height,
26
- num_inference_steps = num_inference_steps,
27
- generator = generator,
28
  guidance_scale=guidance_scale
29
  ).images[0]
30
  return image, seed
31
-
32
  examples = [
33
- "a tiny astronaut hatching from an egg on the moon",
34
- "a cat holding a sign that says hello world",
35
- "an anime illustration of a wiener schnitzel",
36
  ]
37
 
38
  css="""
@@ -45,9 +44,9 @@ css="""
45
  with gr.Blocks(css=css) as demo:
46
 
47
  with gr.Column(elem_id="col-container"):
48
- gr.Markdown(f"""# FLUX.1 [dev]
49
- 12B param rectified flow transformer guidance-distilled from [FLUX.1 [pro]](https://blackforestlabs.ai/)
50
- [[non-commercial license](https://huggingface.co/black-forest-labs/FLUX.1-dev/blob/main/LICENSE.md)] [[blog](https://blackforestlabs.ai/announcing-black-forest-labs/)] [[model](https://huggingface.co/black-forest-labs/FLUX.1-dev)]
51
  """)
52
 
53
  with gr.Row():
@@ -83,7 +82,7 @@ with gr.Blocks(css=css) as demo:
83
  minimum=256,
84
  maximum=MAX_IMAGE_SIZE,
85
  step=32,
86
- value=1024,
87
  )
88
 
89
  height = gr.Slider(
@@ -109,22 +108,22 @@ with gr.Blocks(css=css) as demo:
109
  minimum=1,
110
  maximum=50,
111
  step=1,
112
- value=28,
113
  )
114
 
115
  gr.Examples(
116
- examples = examples,
117
- fn = infer,
118
- inputs = [prompt],
119
- outputs = [result, seed],
120
  cache_examples="lazy"
121
  )
122
 
123
  gr.on(
124
  triggers=[run_button.click, prompt.submit],
125
- fn = infer,
126
- inputs = [prompt, seed, randomize_seed, width, height, guidance_scale, num_inference_steps],
127
- outputs = [result, seed]
128
  )
129
 
130
- demo.launch()
 
3
  import random
4
  import spaces
5
  import torch
6
+ from diffusers import FluxPipeline
 
7
 
8
  dtype = torch.bfloat16
9
  device = "cuda" if torch.cuda.is_available() else "cpu"
10
 
11
+ pipe = FluxPipeline.from_pretrained("Shakker-Labs/AWPortrait-FL", torch_dtype=torch.bfloat16).to(device)
12
 
13
  MAX_SEED = np.iinfo(np.int32).max
14
  MAX_IMAGE_SIZE = 2048
15
 
16
  @spaces.GPU(duration=190)
17
+ def infer(prompt, seed=42, randomize_seed=False, width=768, height=1024, guidance_scale=3.5, num_inference_steps=24, progress=gr.Progress(track_tqdm=True)):
18
  if randomize_seed:
19
  seed = random.randint(0, MAX_SEED)
20
  generator = torch.Generator().manual_seed(seed)
21
  image = pipe(
22
+ prompt=prompt,
23
+ width=width,
24
+ height=height,
25
+ num_inference_steps=num_inference_steps,
26
+ generator=generator,
27
  guidance_scale=guidance_scale
28
  ).images[0]
29
  return image, seed
30
+
31
  examples = [
32
+ "close up portrait, Amidst the interplay of light and shadows in a photography studio,a soft spotlight traces the contours of a face,highlighting a figure clad in a sleek black turtleneck...",
33
+ "a cinematic portrait of an elegant elderly man with a wise expression...",
34
+ "a dramatic close-up shot of a warrior princess with fierce eyes..."
35
  ]
36
 
37
  css="""
 
44
  with gr.Blocks(css=css) as demo:
45
 
46
  with gr.Column(elem_id="col-container"):
47
+ gr.Markdown(f"""# AWPortrait-FL
48
+ 12B param flow transformer guidance-distilled from [AWPortrait-FL](https://huggingface.co/Shakker-Labs/AWPortrait-FL)
49
+ [[non-commercial license](https://huggingface.co/Shakker-Labs/AWPortrait-FL/blob/main/LICENSE.md)]
50
  """)
51
 
52
  with gr.Row():
 
82
  minimum=256,
83
  maximum=MAX_IMAGE_SIZE,
84
  step=32,
85
+ value=768,
86
  )
87
 
88
  height = gr.Slider(
 
108
  minimum=1,
109
  maximum=50,
110
  step=1,
111
+ value=24,
112
  )
113
 
114
  gr.Examples(
115
+ examples=examples,
116
+ fn=infer,
117
+ inputs=[prompt],
118
+ outputs=[result, seed],
119
  cache_examples="lazy"
120
  )
121
 
122
  gr.on(
123
  triggers=[run_button.click, prompt.submit],
124
+ fn=infer,
125
+ inputs=[prompt, seed, randomize_seed, width, height, guidance_scale, num_inference_steps],
126
+ outputs=[result, seed]
127
  )
128
 
129
+ demo.launch()