Adding img2img step
Browse files
app.py
CHANGED
|
@@ -4,6 +4,13 @@ import random
|
|
| 4 |
from PIL import Image
|
| 5 |
import cv2
|
| 6 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 7 |
import gradio as gr
|
| 8 |
from glob import glob
|
| 9 |
from omegaconf import OmegaConf
|
|
@@ -216,11 +223,18 @@ class AnimateController:
|
|
| 216 |
image.resize((512, 512))
|
| 217 |
|
| 218 |
# Save the resized image to the specified output path
|
| 219 |
-
image.save("resized.jpg")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 220 |
|
| 221 |
sample = pipeline(
|
| 222 |
prompt_textbox,
|
| 223 |
-
init_image = "
|
| 224 |
negative_prompt = negative_prompt_textbox,
|
| 225 |
num_inference_steps = 25,
|
| 226 |
guidance_scale = 8.,
|
|
|
|
| 4 |
from PIL import Image
|
| 5 |
import cv2
|
| 6 |
|
| 7 |
+
from diffusers import StableDiffusionImg2ImgPipeline
|
| 8 |
+
|
| 9 |
+
|
| 10 |
+
model_id_or_path = "runwayml/stable-diffusion-v1-5"
|
| 11 |
+
pipe = StableDiffusionImg2ImgPipeline.from_pretrained(model_id_or_path, torch_dtype=torch.float16)
|
| 12 |
+
pipe = pipe.to("cuda")
|
| 13 |
+
|
| 14 |
import gradio as gr
|
| 15 |
from glob import glob
|
| 16 |
from omegaconf import OmegaConf
|
|
|
|
| 223 |
image.resize((512, 512))
|
| 224 |
|
| 225 |
# Save the resized image to the specified output path
|
| 226 |
+
#image.save("resized.jpg")
|
| 227 |
+
|
| 228 |
+
|
| 229 |
+
|
| 230 |
+
# Convert the image to SD by Img2Img pipeline
|
| 231 |
+
|
| 232 |
+
sd_images = pipe(prompt=prompt_textbox, image=init_image, strength=0.75, guidance_scale=7.5).images
|
| 233 |
+
sd_images[0].save("sd_converted.png")
|
| 234 |
|
| 235 |
sample = pipeline(
|
| 236 |
prompt_textbox,
|
| 237 |
+
init_image = "sd_converted.jpg",
|
| 238 |
negative_prompt = negative_prompt_textbox,
|
| 239 |
num_inference_steps = 25,
|
| 240 |
guidance_scale = 8.,
|