File size: 830 Bytes
bce09e6
6cab1a9
270bf94
6cab1a9
270bf94
 
bce09e6
270bf94
 
bce09e6
 
 
5dec614
270bf94
 
 
5dec614
 
270bf94
 
 
5dec614
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
import os
import gradio as gr
import torch

from diffusers import StableDiffusionImg2ImgPipeline

os.environ['GRADIO_THEME'] = 'default'
# load the pipeline
device = "cpu"
# model_id_or_path = "runwayml/stable-diffusion-v1-5"
# takes too much time downloading, change to local path
model_path = "."
img2img_pipe = StableDiffusionImg2ImgPipeline.from_pretrained(model_path, torch_dtype=torch.float32)
img2img_pipe = img2img_pipe.to(device)


def img2img_diff(prompt, pil_img):
    img = pil_img.resize((768, 512))
    return img2img_pipe(prompt=prompt, image=img, strength=0.75, guidance_scale=7.5).images[0]


app = gr.Interface(fn=img2img_diff, inputs=[gr.Text(label="prompt text"), gr.Image(type='pil', label='draft image')],
                   outputs=gr.Image(type='pil'))
if __name__ == "__main__":
    app.launch(debug=True)