Arafath10 commited on
Commit
f76646b
·
1 Parent(s): d06a82b

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +19 -8
app.py CHANGED
@@ -1,18 +1,29 @@
1
  import gradio as gr
 
 
 
 
2
  import torch
3
- from diffusers import StableDiffusionPipeline
4
 
5
- model_id = "CompVis/stable-diffusion-v1-4"
6
- device = "cpu"
 
 
7
 
8
- pipe = StableDiffusionPipeline.from_pretrained(model_id, torch_dtype=torch.bfloat16)
9
- pipe = pipe.to(device)
 
 
 
 
10
 
11
  def greet(name):
12
- prompt = name
13
- image = pipe(prompt).images[0]
 
14
 
15
- image.save(prompt+".png")
16
  return "done"
17
 
18
  iface = gr.Interface(fn=greet, inputs="text", outputs="text")
 
1
  import gradio as gr
2
+
3
+
4
+ import PIL
5
+ import requests
6
  import torch
7
+ from diffusers import StableDiffusionInstructPix2PixPipeline, EulerAncestralDiscreteScheduler
8
 
9
+ model_id = "timbrooks/instruct-pix2pix"
10
+ pipe = StableDiffusionInstructPix2PixPipeline.from_pretrained(model_id, torch_dtype=torch.float16, safety_checker=None)
11
+ pipe.to("cpu")
12
+ pipe.scheduler = EulerAncestralDiscreteScheduler.from_config(pipe.scheduler.config)
13
 
14
+ def download_image(img):
15
+ image = PIL.Image.open(requests.get(img, stream=True).raw)
16
+ image = PIL.ImageOps.exif_transpose(image)
17
+ image = image.convert("RGB")
18
+ return image
19
+ image = download_image("https://raw.githubusercontent.com/timothybrooks/instruct-pix2pix/main/imgs/example.jpg")
20
 
21
  def greet(name):
22
+ prompt = "add tshirt"
23
+ images = pipe(prompt, image=image, num_inference_steps=10, image_guidance_scale=1).images
24
+
25
 
26
+ image.save(images[0]+".png")
27
  return "done"
28
 
29
  iface = gr.Interface(fn=greet, inputs="text", outputs="text")