shanetx commited on
Commit
fbc78dc
1 Parent(s): 37327a5

add image to image transform api

Browse files
Files changed (1) hide show
  1. app.py +21 -1
app.py CHANGED
@@ -1,3 +1,23 @@
 
1
  import gradio as gr
 
2
 
3
- gr.Interface.load("models/runwayml/stable-diffusion-v1-5").launch()
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import os
2
  import gradio as gr
3
+ import torch
4
 
5
+ from diffusers import StableDiffusionImg2ImgPipeline
6
+
7
+ os.environ['GRADIO_THEME'] = 'default'
8
+ # load the pipeline
9
+ device = "cpu"
10
+ model_id_or_path = "runwayml/stable-diffusion-v1-5"
11
+ img2img_pipe = StableDiffusionImg2ImgPipeline.from_pretrained(model_id_or_path, torch_dtype=torch.float32)
12
+ img2img_pipe = img2img_pipe.to(device)
13
+
14
+
15
+ def img2img_diff(prompt, pil_img):
16
+ img = pil_img.resize((768, 512))
17
+ return img2img_pipe(prompt=prompt, image=img, strength=0.75, guidance_scale=7.5).images[0]
18
+
19
+
20
+ app = gr.Interface(fn=img2img_diff, inputs=[gr.Text(label="prompt text"), gr.Image(type='pil', label='draft image')],
21
+ outputs=gr.Image(type='pil'))
22
+
23
+ app.launch(debug=True)