Spaces:
Sleeping
Sleeping
yash
commited on
Commit
·
8f88a50
1
Parent(s):
f8ef591
remove unnacessary comments
Browse files
app.py
CHANGED
|
@@ -6,22 +6,7 @@ from diffusers import KDPM2DiscreteScheduler,KDPM2AncestralDiscreteScheduler,PN
|
|
| 6 |
from diffusers import DPMSolverMultistepScheduler
|
| 7 |
import random
|
| 8 |
|
| 9 |
-
# pipe = StableDiffusionPipeline.from_pretrained(
|
| 10 |
-
# "SG161222/Realistic_Vision_V5.1_noVAE",
|
| 11 |
-
# torch_dtype=torch.float16,
|
| 12 |
-
# use_safetensors=True,
|
| 13 |
-
# ).to("cpu")
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
def set_pipeline(model_id_repo,scheduler):
|
| 19 |
-
# pipe = StableDiffusionPipeline.from_single_file(
|
| 20 |
-
# "/home/ubuntu/stable-diffusion-webui/models/Stable-diffusion/realisticVisionV51_v51VAE.safetensors",
|
| 21 |
-
# # torch_dtype=torch.float16,
|
| 22 |
-
# use_safetensors=True,
|
| 23 |
-
# ).to("cpu")
|
| 24 |
-
|
| 25 |
|
| 26 |
model_ids_dict = {
|
| 27 |
"dreamshaper": "Lykon/DreamShaper",
|
|
@@ -34,12 +19,6 @@ def set_pipeline(model_id_repo,scheduler):
|
|
| 34 |
print("model_repo :",model_repo)
|
| 35 |
|
| 36 |
|
| 37 |
-
# pipe = StableDiffusionPipeline.from_pretrained(
|
| 38 |
-
# model_repo,
|
| 39 |
-
# # torch_dtype=torch.float16, # to run on cpu
|
| 40 |
-
# use_safetensors=True,
|
| 41 |
-
# ).to("cpu")
|
| 42 |
-
|
| 43 |
pipe = StableDiffusionPipeline.from_pretrained(
|
| 44 |
model_repo,
|
| 45 |
# torch_dtype=torch.float16, # to run on cpu
|
|
@@ -68,10 +47,6 @@ def set_pipeline(model_id_repo,scheduler):
|
|
| 68 |
else:
|
| 69 |
pass
|
| 70 |
|
| 71 |
-
# # prompt = "a photo of an astronaut riding a horse on mars"
|
| 72 |
-
# # pipe.enable_attention_slicing()
|
| 73 |
-
# image = pipe(prompt).images[0]
|
| 74 |
-
# image.save("1.png")
|
| 75 |
return pipe
|
| 76 |
|
| 77 |
|
|
@@ -88,10 +63,6 @@ def img_args(
|
|
| 88 |
seed = 0
|
| 89 |
):
|
| 90 |
|
| 91 |
-
print(model_id_repo)
|
| 92 |
-
print(scheduler)
|
| 93 |
-
print(prompt,"&&&&&&&&&&&&&&&&")
|
| 94 |
-
|
| 95 |
pipe = set_pipeline(model_id_repo,scheduler)
|
| 96 |
|
| 97 |
if seed == 0:
|
|
@@ -111,8 +82,6 @@ def img_args(
|
|
| 111 |
num_images_per_prompt = num_images_per_prompt, # default 1
|
| 112 |
generator = generator,
|
| 113 |
).images
|
| 114 |
-
print(image,"#############")
|
| 115 |
-
# image.save("1.png")
|
| 116 |
return image
|
| 117 |
|
| 118 |
|
|
@@ -145,62 +114,3 @@ with block as image_gen:
|
|
| 145 |
run_btn.click(fn=img_args,inputs=[prompt,negative_prompt,model_selection,schduler_selection,height_slider,width_slider,num_inference_steps_slider,guidance_scale_slider,num_images_per_prompt_slider,seed_slider],outputs=[out_img])
|
| 146 |
image_gen.launch()
|
| 147 |
|
| 148 |
-
# block = gr.Blocks().queue()
|
| 149 |
-
# block.title = "Inpaint Anything"
|
| 150 |
-
# with block as inpaint_anything_interface:
|
| 151 |
-
# with gr.Column():
|
| 152 |
-
# with gr.Row():
|
| 153 |
-
# gr.Markdown("## Inpainting with Segment Anything (Multi Controlnet)")
|
| 154 |
-
# with gr.Row():
|
| 155 |
-
# with gr.Column():
|
| 156 |
-
# # with gr.Row():
|
| 157 |
-
# model_selection = gr.Dropdown(choices=["dreamshaper","deliberate","realisticVisionV51_v51VAE","revAnimated_v121Inp","runwayml","Realistic_Vision_V5_1_noVAE"],value = "Realistic_Vision_V5_1_noVAE",label="Models")
|
| 158 |
-
# # scheduler = gr.Dropdown(choices=["DDIM","Euler","Euler a","UniPC","DPM2 Karras","DPM2 a Karras","PNDM","DPM++ 2M Karras","DPM++ 2M SDE Karras"],value = "Euler a",label="Sampler")
|
| 159 |
-
# input_image = gr.Image(type="numpy",label="input",height=400)
|
| 160 |
-
# run_btn = gr.Button("Run Segment", elem_id="select_btn", variant="primary")
|
| 161 |
-
|
| 162 |
-
# prompt = gr.Textbox(placeholder="what you want to generate")
|
| 163 |
-
# guidance_scale_slider = gr.Slider(label="Guidance Scale", minimum=0, maximum=20.0, value=7.5, step=0.5)
|
| 164 |
-
# inference_slider = gr.Slider(label="Guidance Scale", minimum=0, maximum=150, value=50, step=1)
|
| 165 |
-
# with gr.Row():
|
| 166 |
-
# canny_slider = gr.Slider(label="Canny Slider", minimum=0, maximum=1.0, value=0.5, step=0.1)
|
| 167 |
-
# depth_slider = gr.Slider(label="Depth Slider", minimum=0, maximum=1.0, value=0.5, step=0.1)
|
| 168 |
-
# seg_slider = gr.Slider(label="Segment Slider", minimum=0, maximum=1.0, value=0.5, step=0.1)
|
| 169 |
-
# out_img = gr.Image(type="pil",label="output")
|
| 170 |
-
# seed_slider = gr.Slider(label="Seed Slider",elem_id="expand_mask_iteration_count", minimum=0, maximum=25647981548564, value=0, step=1)
|
| 171 |
-
# grn_btn = gr.Button("image generation", elem_id="select_btn", variant="primary")
|
| 172 |
-
# # bru_btn = gr.Button("Brush generation", elem_id="select_btn", variant="primary")
|
| 173 |
-
# with gr.Column():
|
| 174 |
-
# scheduler = gr.Dropdown(choices=["DDIM","Euler","Euler a","UniPC","DPM2 Karras","DPM2 a Karras","PNDM","DPM++ 2M Karras","DPM++ 2M SDE Karras"],value = "Euler a",label="Sampler")
|
| 175 |
-
# # lora_chk = gr.Checkbox(label="Use Lora", elem_id="invert_chk", show_label=True, value=False, interactive=True)
|
| 176 |
-
# # image_out = gr.Image(type="pil",label="Output")
|
| 177 |
-
# sam_image = gr.Image(label="Segment Anything image", elem_id="ia_sam_image", type="numpy", tool="sketch", brush_radius=8,
|
| 178 |
-
# show_label=False, interactive=True,height=400)
|
| 179 |
-
# mask_btn = gr.Button("Create Mask", elem_id="select_btn", variant="primary")
|
| 180 |
-
# with gr.Column():
|
| 181 |
-
# with gr.Row():
|
| 182 |
-
# invert_chk = gr.Checkbox(label="Invert mask", elem_id="invert_chk", show_label=True, value=True, interactive=True)
|
| 183 |
-
# ignore_black_chk = gr.Checkbox(label="Ignore black area", elem_id="ignore_black_chk", value=True, show_label=True, interactive=True)
|
| 184 |
-
# lora_chk = gr.Checkbox(label="Use Lora", elem_id="invert_chk", show_label=True, value=False, interactive=True)
|
| 185 |
-
# with gr.Column():
|
| 186 |
-
# sel_mask = gr.Image(label="Selected mask image", elem_id="ia_sel_mask", type="numpy", tool="sketch", brush_radius=12,
|
| 187 |
-
# show_label=False, interactive=True, height=480)
|
| 188 |
-
# with gr.Column():
|
| 189 |
-
# with gr.Row():
|
| 190 |
-
# expand_mask_btn = gr.Button("Expand mask region", elem_id="expand_mask_btn")
|
| 191 |
-
# # with gr.Column():
|
| 192 |
-
# expand_mask_iteration_count = gr.Slider(label="Expand Mask Iterations",
|
| 193 |
-
# elem_id="expand_mask_iteration_count", minimum=1, maximum=100, value=1, step=1)
|
| 194 |
-
# with gr.Row():
|
| 195 |
-
# add_mask_btn = gr.Button("Add mask by sketch", elem_id="add_mask_btn")
|
| 196 |
-
# apply_mask_btn = gr.Button("Trim mask by sketch", elem_id="apply_mask_btn")
|
| 197 |
-
|
| 198 |
-
|
| 199 |
-
# run_btn.click(fn=run_seg,inputs=[input_image],outputs=[sam_image])
|
| 200 |
-
# mask_btn.click(fn=select_mask,inputs=[input_image, sam_image, invert_chk, ignore_black_chk,sel_mask], outputs=[sel_mask])
|
| 201 |
-
# expand_mask_btn.click(expand_mask, inputs=[input_image, sel_mask, expand_mask_iteration_count], outputs=[sel_mask])
|
| 202 |
-
# apply_mask_btn.click(apply_mask, inputs=[input_image, sel_mask], outputs=[sel_mask])
|
| 203 |
-
# add_mask_btn.click(add_mask, inputs=[input_image, sel_mask], outputs=[sel_mask])
|
| 204 |
-
# grn_btn.click(fn=generate_image,inputs=[input_image,sam_image,prompt,seed_slider,canny_slider,depth_slider,seg_slider,model_selection,scheduler,guidance_scale_slider,inference_slider,lora_chk],outputs=[out_img])
|
| 205 |
-
# bru_btn.click(fn=brush_geeration,inputs=[input_image,prompt],outputs=[out_img])
|
| 206 |
-
# inpaint_anything_interface.launch()
|
|
|
|
| 6 |
from diffusers import DPMSolverMultistepScheduler
|
| 7 |
import random
|
| 8 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 9 |
def set_pipeline(model_id_repo,scheduler):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 10 |
|
| 11 |
model_ids_dict = {
|
| 12 |
"dreamshaper": "Lykon/DreamShaper",
|
|
|
|
| 19 |
print("model_repo :",model_repo)
|
| 20 |
|
| 21 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 22 |
pipe = StableDiffusionPipeline.from_pretrained(
|
| 23 |
model_repo,
|
| 24 |
# torch_dtype=torch.float16, # to run on cpu
|
|
|
|
| 47 |
else:
|
| 48 |
pass
|
| 49 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 50 |
return pipe
|
| 51 |
|
| 52 |
|
|
|
|
| 63 |
seed = 0
|
| 64 |
):
|
| 65 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 66 |
pipe = set_pipeline(model_id_repo,scheduler)
|
| 67 |
|
| 68 |
if seed == 0:
|
|
|
|
| 82 |
num_images_per_prompt = num_images_per_prompt, # default 1
|
| 83 |
generator = generator,
|
| 84 |
).images
|
|
|
|
|
|
|
| 85 |
return image
|
| 86 |
|
| 87 |
|
|
|
|
| 114 |
run_btn.click(fn=img_args,inputs=[prompt,negative_prompt,model_selection,schduler_selection,height_slider,width_slider,num_inference_steps_slider,guidance_scale_slider,num_images_per_prompt_slider,seed_slider],outputs=[out_img])
|
| 115 |
image_gen.launch()
|
| 116 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|