|
|
|
"""Untitled11.ipynb |
|
|
|
Automatically generated by Colab. |
|
|
|
Original file is located at |
|
https://colab.research.google.com/drive/17mNpy3A7oaJ-q9Txp8f4eBvRfO_k7NCb |
|
""" |
|
|
|
!pip install diffusers |
|
!pip install transformers |
|
|
|
import torch |
|
from diffusers import StableDiffusionImg2ImgPipeline |
|
from diffusers.utils import load_image |
|
import gradio as gr |
|
|
|
|
|
device = "cuda" |
|
|
|
|
|
pipe = StableDiffusionImg2ImgPipeline.from_pretrained( |
|
"CompVis/stable-diffusion-v1-4", |
|
torch_dtype=torch.float16 |
|
) |
|
pipe = pipe.to(device) |
|
|
|
|
|
url = "https://raw.githubusercontent.com/CompVis/stable-diffusion/main/assets/stable-samples/img2img/sketch-mountains-input.jpg" |
|
init_image = load_image(url).resize((1024, 1024)) |
|
|
|
|
|
prompt = "cat wizard, gandalf, lord of the rings, detailed, fantasy, cute, adorable, Pixar, Disney, 8k" |
|
|
|
|
|
def generate_image(prompt, image): |
|
image = pipe( |
|
prompt=prompt, |
|
image=image, |
|
num_inference_steps=50, |
|
strength=0.75, |
|
guidance_scale=7.5 |
|
).images[0] |
|
return image |
|
|
|
|
|
gr.Interface( |
|
fn=generate_image, |
|
inputs=["text", "image"], |
|
outputs="image" |
|
).launch() |