vilarin commited on
Commit
6fdb3d2
·
verified ·
1 Parent(s): 380e58e

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +7 -22
app.py CHANGED
@@ -1,7 +1,7 @@
1
  import torch
2
  import spaces
3
  import gradio as gr
4
- from diffusers import FluxInpaintPipeline, FluxTransformer2DModel
5
  import random
6
  import os
7
  import numpy as np
@@ -9,30 +9,17 @@ from huggingface_hub import hf_hub_download
9
 
10
  os.environ["HF_HUB_ENABLE_HF_TRANSFER"] = "1"
11
  MAX_SEED = np.iinfo(np.int32).max
12
- model = "black-forest-labs/FLUX.1-dev"
13
- hf_hub_download(repo_id="black-forest-labs/FLUX.1-Fill-dev", filename="ae.safetensors", local_dir=".")
14
 
15
  if torch.cuda.is_available():
16
- transformer = FluxTransformer2DModel.from_single_file(
17
- "https://huggingface.co/black-forest-labs/FLUX.1-Fill-dev/blob/main/flux1-fill-dev.safetensors",
18
- low_cpu_mem_usage=False,
19
- ignore_mismatched_sizes=True,
20
- torch_dtype=torch.bfloat16
21
- )
22
- vae = AutoencoderKL.from_pretrained("./ae.safetensors")
23
- pipe = FluxInpaintPipeline.from_pretrained(
24
- model,
25
- vae=vae,
26
- transformer=transformer,
27
- torch_dtype=torch.bfloat16)
28
- pipe.to("cuda")
29
 
30
 
31
  @spaces.GPU()
32
  def inpaintGen(
33
  imgMask,
34
  inpaint_prompt: str,
35
- strength: float,
36
  guidance: float,
37
  num_steps: int,
38
  seed: int,
@@ -52,7 +39,7 @@ def inpaintGen(
52
 
53
  if randomize_seed:
54
  seed = random.randint(0, MAX_SEED)
55
- generator = torch.Generator(device=DEVICE).manual_seed(seed)
56
 
57
  result = pipe(
58
  prompt=inpaint_prompt,
@@ -61,10 +48,10 @@ def inpaintGen(
61
  mask_image=mask_img,
62
  width=width,
63
  height=height,
64
- strength=strength,
65
  num_inference_steps=num_steps,
66
  generator=generator,
67
- guidance_scale=guidance
 
68
  ).images[0]
69
 
70
  return result
@@ -88,7 +75,6 @@ with gr.Blocks(theme="ocean", title="Flux.1 dev inpaint", css=CSS) as demo:
88
  Inpaint_clearBtn = gr.ClearButton([imgMask, inpaint_prompt], value="Clear")
89
  image_out = gr.Image(type="pil", label="Output", height=960)
90
  with gr.Accordion("Advanced ⚙️", open=False):
91
- strength = gr.Slider(label="Strength", minimum=0, maximum=1, value=1, step=0.1)
92
  guidance = gr.Slider(label="Guidance scale", minimum=1, maximum=20, value=7.5, step=0.1)
93
  num_steps = gr.Slider(label="Steps", minimum=1, maximum=20, value=20, step=1)
94
  seed = gr.Number(label="Seed", value=42, precision=0)
@@ -103,7 +89,6 @@ with gr.Blocks(theme="ocean", title="Flux.1 dev inpaint", css=CSS) as demo:
103
  inputs = [
104
  imgMask,
105
  inpaint_prompt,
106
- strength,
107
  guidance,
108
  num_steps,
109
  seed,
 
1
  import torch
2
  import spaces
3
  import gradio as gr
4
+ from diffusers import FluxFillPipeline
5
  import random
6
  import os
7
  import numpy as np
 
9
 
10
  os.environ["HF_HUB_ENABLE_HF_TRANSFER"] = "1"
11
  MAX_SEED = np.iinfo(np.int32).max
12
+
 
13
 
14
  if torch.cuda.is_available():
15
+ repo_id = "black-forest-labs/FLUX.1-Fill-dev"
16
+ pipe = FluxFillPipeline.from_pretrained(repo_id, torch_dtype=torch.bfloat16).to("cuda")
 
 
 
 
 
 
 
 
 
 
 
17
 
18
 
19
  @spaces.GPU()
20
  def inpaintGen(
21
  imgMask,
22
  inpaint_prompt: str,
 
23
  guidance: float,
24
  num_steps: int,
25
  seed: int,
 
39
 
40
  if randomize_seed:
41
  seed = random.randint(0, MAX_SEED)
42
+ generator = torch.Generator("cpu").manual_seed(seed)
43
 
44
  result = pipe(
45
  prompt=inpaint_prompt,
 
48
  mask_image=mask_img,
49
  width=width,
50
  height=height,
 
51
  num_inference_steps=num_steps,
52
  generator=generator,
53
+ guidance_scale=guidance,
54
+ max_sequence_length=512,
55
  ).images[0]
56
 
57
  return result
 
75
  Inpaint_clearBtn = gr.ClearButton([imgMask, inpaint_prompt], value="Clear")
76
  image_out = gr.Image(type="pil", label="Output", height=960)
77
  with gr.Accordion("Advanced ⚙️", open=False):
 
78
  guidance = gr.Slider(label="Guidance scale", minimum=1, maximum=20, value=7.5, step=0.1)
79
  num_steps = gr.Slider(label="Steps", minimum=1, maximum=20, value=20, step=1)
80
  seed = gr.Number(label="Seed", value=42, precision=0)
 
89
  inputs = [
90
  imgMask,
91
  inpaint_prompt,
 
92
  guidance,
93
  num_steps,
94
  seed,