File size: 993 Bytes
75d2ac3
f76646b
 
 
 
0b81ac3
f76646b
0b81ac3
f76646b
 
 
 
75d2ac3
f76646b
 
 
 
 
 
4127a8c
75d2ac3
f76646b
 
 
0b81ac3
f76646b
0b81ac3
75d2ac3
 
 
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
26
27
28
29
30
import gradio as gr


import PIL
import requests
import torch
from diffusers import StableDiffusionInstructPix2PixPipeline, EulerAncestralDiscreteScheduler

model_id = "timbrooks/instruct-pix2pix"
pipe = StableDiffusionInstructPix2PixPipeline.from_pretrained(model_id, torch_dtype=torch.float16, safety_checker=None)
pipe.to("cpu")
pipe.scheduler = EulerAncestralDiscreteScheduler.from_config(pipe.scheduler.config)

def download_image(img):
    image = PIL.Image.open(requests.get(img, stream=True).raw)
    image = PIL.ImageOps.exif_transpose(image)
    image = image.convert("RGB")
    return image
image = download_image("https://raw.githubusercontent.com/timothybrooks/instruct-pix2pix/main/imgs/example.jpg")

def greet(name):
    prompt = "add tshirt"
    images = pipe(prompt, image=image, num_inference_steps=10, image_guidance_scale=1).images
      
    
    image.save(images[0]+".png")
    return "done"

iface = gr.Interface(fn=greet, inputs="text", outputs="text")
iface.launch()