Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -8,10 +8,8 @@ from PIL import Image
|
|
| 8 |
from diffusers import StableDiffusionXLImg2ImgPipeline, EDMEulerScheduler, AutoencoderKL
|
| 9 |
from huggingface_hub import hf_hub_download
|
| 10 |
|
| 11 |
-
# Load the VAE
|
| 12 |
vae = AutoencoderKL.from_pretrained("madebyollin/sdxl-vae-fp16-fix", torch_dtype=torch.float16)
|
| 13 |
|
| 14 |
-
# Download and load the model
|
| 15 |
pipe_edit = StableDiffusionXLImg2ImgPipeline.from_single_file(
|
| 16 |
hf_hub_download(repo_id="stabilityai/cosxl", filename="cosxl_edit.safetensors"),
|
| 17 |
num_in_channels=8,
|
|
@@ -20,11 +18,9 @@ pipe_edit = StableDiffusionXLImg2ImgPipeline.from_single_file(
|
|
| 20 |
torch_dtype=torch.float16,
|
| 21 |
)
|
| 22 |
|
| 23 |
-
# Set the scheduler
|
| 24 |
pipe_edit.scheduler = EDMEulerScheduler(sigma_min=0.002, sigma_max=120.0, sigma_data=1.0, prediction_type="v_prediction")
|
| 25 |
pipe_edit.to("cuda")
|
| 26 |
|
| 27 |
-
# Load the refiner
|
| 28 |
refiner = StableDiffusionXLImg2ImgPipeline.from_pretrained(
|
| 29 |
"stabilityai/stable-diffusion-xl-refiner-1.0",
|
| 30 |
vae=vae,
|
|
@@ -34,7 +30,6 @@ refiner = StableDiffusionXLImg2ImgPipeline.from_pretrained(
|
|
| 34 |
)
|
| 35 |
refiner.to("cuda")
|
| 36 |
|
| 37 |
-
# Patch for the scheduler
|
| 38 |
def set_timesteps_patched(self, num_inference_steps: int, device=None):
|
| 39 |
self.num_inference_steps = num_inference_steps
|
| 40 |
ramp = np.linspace(0, 1, self.num_inference_steps)
|
|
@@ -48,7 +43,6 @@ def set_timesteps_patched(self, num_inference_steps: int, device=None):
|
|
| 48 |
|
| 49 |
EDMEulerScheduler.set_timesteps = set_timesteps_patched
|
| 50 |
|
| 51 |
-
# Function to perform image editing
|
| 52 |
def king(input_image, instruction: str, negative_prompt: str = "", steps: int = 25, randomize_seed: bool = True, seed: int = 2404, guidance_scale: float = 6, progress=gr.Progress(track_tqdm=True)):
|
| 53 |
input_image = Image.open(input_image).convert('RGB')
|
| 54 |
if randomize_seed:
|
|
@@ -76,7 +70,6 @@ def king(input_image, instruction: str, negative_prompt: str = "", steps: int =
|
|
| 76 |
).images[0]
|
| 77 |
return seed, refine
|
| 78 |
|
| 79 |
-
# CSS for the Gradio interface
|
| 80 |
css = '''
|
| 81 |
.gradio-container{max-width: 700px !important}
|
| 82 |
h1{text-align:center}
|
|
@@ -85,13 +78,11 @@ footer {
|
|
| 85 |
}
|
| 86 |
'''
|
| 87 |
|
| 88 |
-
# Examples for the Gradio interface
|
| 89 |
examples = [
|
| 90 |
["./supercar.png", "make it red"],
|
| 91 |
["./red_car.png", "add some snow"],
|
| 92 |
]
|
| 93 |
|
| 94 |
-
# Creating the Gradio interface
|
| 95 |
with gr.Blocks(css=css) as demo:
|
| 96 |
gr.Markdown("# Image Editing\n### Note: First image generation takes time")
|
| 97 |
with gr.Row():
|
|
@@ -130,4 +121,4 @@ with gr.Blocks(css=css) as demo:
|
|
| 130 |
outputs=[seed, input_image],
|
| 131 |
)
|
| 132 |
|
| 133 |
-
demo.queue(max_size=500).launch()
|
|
|
|
| 8 |
from diffusers import StableDiffusionXLImg2ImgPipeline, EDMEulerScheduler, AutoencoderKL
|
| 9 |
from huggingface_hub import hf_hub_download
|
| 10 |
|
|
|
|
| 11 |
vae = AutoencoderKL.from_pretrained("madebyollin/sdxl-vae-fp16-fix", torch_dtype=torch.float16)
|
| 12 |
|
|
|
|
| 13 |
pipe_edit = StableDiffusionXLImg2ImgPipeline.from_single_file(
|
| 14 |
hf_hub_download(repo_id="stabilityai/cosxl", filename="cosxl_edit.safetensors"),
|
| 15 |
num_in_channels=8,
|
|
|
|
| 18 |
torch_dtype=torch.float16,
|
| 19 |
)
|
| 20 |
|
|
|
|
| 21 |
pipe_edit.scheduler = EDMEulerScheduler(sigma_min=0.002, sigma_max=120.0, sigma_data=1.0, prediction_type="v_prediction")
|
| 22 |
pipe_edit.to("cuda")
|
| 23 |
|
|
|
|
| 24 |
refiner = StableDiffusionXLImg2ImgPipeline.from_pretrained(
|
| 25 |
"stabilityai/stable-diffusion-xl-refiner-1.0",
|
| 26 |
vae=vae,
|
|
|
|
| 30 |
)
|
| 31 |
refiner.to("cuda")
|
| 32 |
|
|
|
|
| 33 |
def set_timesteps_patched(self, num_inference_steps: int, device=None):
|
| 34 |
self.num_inference_steps = num_inference_steps
|
| 35 |
ramp = np.linspace(0, 1, self.num_inference_steps)
|
|
|
|
| 43 |
|
| 44 |
EDMEulerScheduler.set_timesteps = set_timesteps_patched
|
| 45 |
|
|
|
|
| 46 |
def king(input_image, instruction: str, negative_prompt: str = "", steps: int = 25, randomize_seed: bool = True, seed: int = 2404, guidance_scale: float = 6, progress=gr.Progress(track_tqdm=True)):
|
| 47 |
input_image = Image.open(input_image).convert('RGB')
|
| 48 |
if randomize_seed:
|
|
|
|
| 70 |
).images[0]
|
| 71 |
return seed, refine
|
| 72 |
|
|
|
|
| 73 |
css = '''
|
| 74 |
.gradio-container{max-width: 700px !important}
|
| 75 |
h1{text-align:center}
|
|
|
|
| 78 |
}
|
| 79 |
'''
|
| 80 |
|
|
|
|
| 81 |
examples = [
|
| 82 |
["./supercar.png", "make it red"],
|
| 83 |
["./red_car.png", "add some snow"],
|
| 84 |
]
|
| 85 |
|
|
|
|
| 86 |
with gr.Blocks(css=css) as demo:
|
| 87 |
gr.Markdown("# Image Editing\n### Note: First image generation takes time")
|
| 88 |
with gr.Row():
|
|
|
|
| 121 |
outputs=[seed, input_image],
|
| 122 |
)
|
| 123 |
|
| 124 |
+
demo.queue(max_size=500).launch()
|