Spaces:
Running
on
Zero
Running
on
Zero
change py
Browse files
app.py
CHANGED
|
@@ -27,7 +27,7 @@ def sanitize_prompt(prompt):
|
|
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
-
@spaces.GPU(duration=
|
| 31 |
def process_images(image, image2=None,prompt="a girl",strength=0.75,seed=0,inference_step=4,progress=gr.Progress(track_tqdm=True)):
|
| 32 |
print("start process_images")
|
| 33 |
progress(0, desc="Starting")
|
|
@@ -35,7 +35,7 @@ def process_images(image, image2=None,prompt="a girl",strength=0.75,seed=0,infer
|
|
| 35 |
if not isinstance(image, dict):
|
| 36 |
if image2 == None:
|
| 37 |
print("empty mask")
|
| 38 |
-
return image
|
| 39 |
else:
|
| 40 |
image = dict({'background': image, 'layers': [image2]})
|
| 41 |
|
|
@@ -62,7 +62,7 @@ def process_images(image, image2=None,prompt="a girl",strength=0.75,seed=0,infer
|
|
| 62 |
# more parameter see https://huggingface.co/docs/diffusers/api/pipelines/flux#diffusers.FluxInpaintPipeline
|
| 63 |
print(prompt)
|
| 64 |
output = pipe(prompt=prompt, image=image,generator=generator,strength=strength
|
| 65 |
-
,guidance_scale=0,num_inference_steps=num_inference_steps,max_sequence_length=
|
| 66 |
|
| 67 |
# TODO support mask
|
| 68 |
return output.images[0]
|
|
@@ -70,7 +70,7 @@ def process_images(image, image2=None,prompt="a girl",strength=0.75,seed=0,infer
|
|
| 70 |
output = process_img2img(image["background"],mask,prompt,strength,seed,inference_step)
|
| 71 |
|
| 72 |
print("end process_images")
|
| 73 |
-
return output
|
| 74 |
|
| 75 |
|
| 76 |
def read_file(path: str) -> str:
|
|
@@ -79,15 +79,6 @@ def read_file(path: str) -> str:
|
|
| 79 |
|
| 80 |
return content
|
| 81 |
|
| 82 |
-
def example_out(image,image_mask,prompt,strength,example_id):
|
| 83 |
-
# input
|
| 84 |
-
#parent,file=os.path.split(image_mask) # image is complex dict
|
| 85 |
-
#base,ext = os.path.splitext(file)
|
| 86 |
-
#key = base.split("_")[0]
|
| 87 |
-
return f"images/{example_id}.jpg"
|
| 88 |
-
#loaded_image = Image.open(f"images/{example_id}.jpg")
|
| 89 |
-
#return loaded_image
|
| 90 |
-
#return np.array(loaded_image)
|
| 91 |
|
| 92 |
css="""
|
| 93 |
#col-left {
|
|
@@ -116,7 +107,7 @@ with gr.Blocks(css=css, elem_id="demo-container") as demo:
|
|
| 116 |
with gr.Accordion(label="Advanced Settings", open=False):
|
| 117 |
with gr.Row( equal_height=True):
|
| 118 |
strength = gr.Number(value=0.75, minimum=0, maximum=0.75, step=0.01, label="strength")
|
| 119 |
-
seed = gr.Number(value=
|
| 120 |
inference_step = gr.Number(value=4, minimum=1, step=4, label="inference_step")
|
| 121 |
#models = ["black-forest-labs/FLUX.1-schnell"]
|
| 122 |
#inpaint_model = gr.Dropdown(label="modes", choices=models, value="black-forest-labs/FLUX.1-schnell")
|
|
@@ -124,11 +115,12 @@ with gr.Blocks(css=css, elem_id="demo-container") as demo:
|
|
| 124 |
|
| 125 |
with gr.Column():
|
| 126 |
image_out = gr.Image(height=800,sources=[],label="Output", elem_id="output-img",format="jpg")
|
|
|
|
| 127 |
|
| 128 |
|
| 129 |
|
| 130 |
|
| 131 |
-
btn.click(fn=process_images, inputs=[image, image_mask,prompt,strength,seed,inference_step], outputs =image_out, api_name='infer')
|
| 132 |
gr.Examples(
|
| 133 |
examples=[
|
| 134 |
#["images/00547245_99.jpg", "images/00547245_99_mask.jpg","a beautiful girl,eyes closed",0.8,"images/00547245.jpg"],
|
|
@@ -146,13 +138,14 @@ with gr.Blocks(css=css, elem_id="demo-container") as demo:
|
|
| 146 |
|
| 147 |
"""
|
| 148 |
)
|
| 149 |
-
|
| 150 |
triggers=[btn.click, prompt.submit],
|
| 151 |
fn = process_images,
|
| 152 |
-
inputs = [image, image_mask,
|
| 153 |
-
outputs = [image_out]
|
| 154 |
-
)
|
| 155 |
|
|
|
|
| 156 |
demo.launch()
|
| 157 |
|
| 158 |
|
|
|
|
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
+
@spaces.GPU(duration=120)
|
| 31 |
def process_images(image, image2=None,prompt="a girl",strength=0.75,seed=0,inference_step=4,progress=gr.Progress(track_tqdm=True)):
|
| 32 |
print("start process_images")
|
| 33 |
progress(0, desc="Starting")
|
|
|
|
| 35 |
if not isinstance(image, dict):
|
| 36 |
if image2 == None:
|
| 37 |
print("empty mask")
|
| 38 |
+
return image,None
|
| 39 |
else:
|
| 40 |
image = dict({'background': image, 'layers': [image2]})
|
| 41 |
|
|
|
|
| 62 |
# more parameter see https://huggingface.co/docs/diffusers/api/pipelines/flux#diffusers.FluxInpaintPipeline
|
| 63 |
print(prompt)
|
| 64 |
output = pipe(prompt=prompt, image=image,generator=generator,strength=strength
|
| 65 |
+
,guidance_scale=0,num_inference_steps=num_inference_steps,max_sequence_length=256)
|
| 66 |
|
| 67 |
# TODO support mask
|
| 68 |
return output.images[0]
|
|
|
|
| 70 |
output = process_img2img(image["background"],mask,prompt,strength,seed,inference_step)
|
| 71 |
|
| 72 |
print("end process_images")
|
| 73 |
+
return output,mask
|
| 74 |
|
| 75 |
|
| 76 |
def read_file(path: str) -> str:
|
|
|
|
| 79 |
|
| 80 |
return content
|
| 81 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 82 |
|
| 83 |
css="""
|
| 84 |
#col-left {
|
|
|
|
| 107 |
with gr.Accordion(label="Advanced Settings", open=False):
|
| 108 |
with gr.Row( equal_height=True):
|
| 109 |
strength = gr.Number(value=0.75, minimum=0, maximum=0.75, step=0.01, label="strength")
|
| 110 |
+
seed = gr.Number(value=100, minimum=0, step=1, label="seed")
|
| 111 |
inference_step = gr.Number(value=4, minimum=1, step=4, label="inference_step")
|
| 112 |
#models = ["black-forest-labs/FLUX.1-schnell"]
|
| 113 |
#inpaint_model = gr.Dropdown(label="modes", choices=models, value="black-forest-labs/FLUX.1-schnell")
|
|
|
|
| 115 |
|
| 116 |
with gr.Column():
|
| 117 |
image_out = gr.Image(height=800,sources=[],label="Output", elem_id="output-img",format="jpg")
|
| 118 |
+
mask_out = gr.Image(height=800,sources=[],label="Mask", elem_id="mask-img",format="jpeg")
|
| 119 |
|
| 120 |
|
| 121 |
|
| 122 |
|
| 123 |
+
#btn.click(fn=process_images, inputs=[image, image_mask,prompt,strength,seed,inference_step], outputs =[image_out,mask_out], api_name='infer')
|
| 124 |
gr.Examples(
|
| 125 |
examples=[
|
| 126 |
#["images/00547245_99.jpg", "images/00547245_99_mask.jpg","a beautiful girl,eyes closed",0.8,"images/00547245.jpg"],
|
|
|
|
| 138 |
|
| 139 |
"""
|
| 140 |
)
|
| 141 |
+
gr.on(
|
| 142 |
triggers=[btn.click, prompt.submit],
|
| 143 |
fn = process_images,
|
| 144 |
+
inputs = [image, image_mask,prompt,strength,seed,inference_step],
|
| 145 |
+
outputs = [image_out,mask_out]
|
| 146 |
+
)
|
| 147 |
|
| 148 |
+
if __name__ == "__main__":
|
| 149 |
demo.launch()
|
| 150 |
|
| 151 |
|