Spaces:
Running
on
Zero
Running
on
Zero
update
Browse files
app.py
CHANGED
@@ -1,6 +1,13 @@
|
|
1 |
import spaces
|
2 |
import torch
|
3 |
from diffusers import FluxInpaintPipeline
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
4 |
|
5 |
dtype = torch.bfloat16
|
6 |
device = "cuda" if torch.cuda.is_available() else "cpu"
|
@@ -9,12 +16,7 @@ pipe = FluxInpaintPipeline.from_pretrained("black-forest-labs/FLUX.1-schnell", t
|
|
9 |
|
10 |
|
11 |
|
12 |
-
import gradio as gr
|
13 |
-
import re
|
14 |
-
from PIL import Image
|
15 |
|
16 |
-
import os
|
17 |
-
import numpy as np
|
18 |
|
19 |
|
20 |
def sanitize_prompt(prompt):
|
@@ -46,7 +48,7 @@ def process_images(image, image2=None,prompt="a girl",inpaint_model="black-fores
|
|
46 |
mask = image['layers'][0]
|
47 |
|
48 |
|
49 |
-
def
|
50 |
if image == None:
|
51 |
return None
|
52 |
|
@@ -55,12 +57,13 @@ def process_images(image, image2=None,prompt="a girl",inpaint_model="black-fores
|
|
55 |
generator = torch.Generator("cuda").manual_seed(seed)
|
56 |
generators.append(generator)
|
57 |
# more parameter see https://huggingface.co/docs/diffusers/api/pipelines/flux#diffusers.FluxInpaintPipeline
|
58 |
-
output = pipe(prompt=prompt, image=image, mask_image=mask_image,generator=generator,strength=strength
|
|
|
59 |
|
60 |
return output.images[0]
|
61 |
|
62 |
|
63 |
-
output =
|
64 |
|
65 |
return output,mask
|
66 |
|
@@ -71,16 +74,6 @@ def read_file(path: str) -> str:
|
|
71 |
|
72 |
return content
|
73 |
|
74 |
-
def example_out(image,image_mask,prompt,strength,example_id):
|
75 |
-
# input
|
76 |
-
#parent,file=os.path.split(image_mask) # image is complex dict
|
77 |
-
#base,ext = os.path.splitext(file)
|
78 |
-
#key = base.split("_")[0]
|
79 |
-
return f"images/{example_id}.jpg"
|
80 |
-
#loaded_image = Image.open(f"images/{example_id}.jpg")
|
81 |
-
#return loaded_image
|
82 |
-
#return np.array(loaded_image)
|
83 |
-
|
84 |
css="""
|
85 |
#col-left {
|
86 |
margin: 0 auto;
|
@@ -100,7 +93,7 @@ with demo_blocks as demo:
|
|
100 |
image = gr.ImageEditor(height=800,sources=['upload','clipboard'],transforms=[],image_mode='RGB', layers=False, elem_id="image_upload", type="pil", label="Upload",brush=gr.Brush(colors=["#fff"], color_mode="fixed"))
|
101 |
with gr.Row(elem_id="prompt-container", equal_height=False):
|
102 |
with gr.Row():
|
103 |
-
prompt = gr.Textbox(label="Prompt",value="a
|
104 |
|
105 |
btn = gr.Button("Inpaint", elem_id="run_button",variant="primary")
|
106 |
|
@@ -139,4 +132,4 @@ with demo_blocks as demo:
|
|
139 |
"""
|
140 |
)
|
141 |
|
142 |
-
demo_blocks.
|
|
|
1 |
import spaces
|
2 |
import torch
|
3 |
from diffusers import FluxInpaintPipeline
|
4 |
+
import gradio as gr
|
5 |
+
import re
|
6 |
+
from PIL import Image
|
7 |
+
|
8 |
+
import os
|
9 |
+
import numpy as np
|
10 |
+
|
11 |
|
12 |
dtype = torch.bfloat16
|
13 |
device = "cuda" if torch.cuda.is_available() else "cpu"
|
|
|
16 |
|
17 |
|
18 |
|
|
|
|
|
|
|
19 |
|
|
|
|
|
20 |
|
21 |
|
22 |
def sanitize_prompt(prompt):
|
|
|
48 |
mask = image['layers'][0]
|
49 |
|
50 |
|
51 |
+
def process_inpaint(image,mask_image,prompt="a person",model_id="black-forest-labs/FLUX.1-schnell",strength=0.75,seed=0,num_inference_steps=4):
|
52 |
if image == None:
|
53 |
return None
|
54 |
|
|
|
57 |
generator = torch.Generator("cuda").manual_seed(seed)
|
58 |
generators.append(generator)
|
59 |
# more parameter see https://huggingface.co/docs/diffusers/api/pipelines/flux#diffusers.FluxInpaintPipeline
|
60 |
+
output = pipe(prompt=prompt, image=image, mask_image=mask_image,generator=generator,strength=strength,
|
61 |
+
guidance_scale=0,num_inference_steps=num_inference_steps,max_sequence_length=256)
|
62 |
|
63 |
return output.images[0]
|
64 |
|
65 |
|
66 |
+
output = process_inpaint(image["background"],mask,prompt,inpaint_model,strength,seed)
|
67 |
|
68 |
return output,mask
|
69 |
|
|
|
74 |
|
75 |
return content
|
76 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
77 |
css="""
|
78 |
#col-left {
|
79 |
margin: 0 auto;
|
|
|
93 |
image = gr.ImageEditor(height=800,sources=['upload','clipboard'],transforms=[],image_mode='RGB', layers=False, elem_id="image_upload", type="pil", label="Upload",brush=gr.Brush(colors=["#fff"], color_mode="fixed"))
|
94 |
with gr.Row(elem_id="prompt-container", equal_height=False):
|
95 |
with gr.Row():
|
96 |
+
prompt = gr.Textbox(label="Prompt",value="a person",placeholder="Your prompt (what you want in place of what is erased)", elem_id="prompt")
|
97 |
|
98 |
btn = gr.Button("Inpaint", elem_id="run_button",variant="primary")
|
99 |
|
|
|
132 |
"""
|
133 |
)
|
134 |
|
135 |
+
demo_blocks.launch()
|