add img2img diff
Browse files- app.py +16 -1
- requirements.txt +4 -0
app.py
CHANGED
@@ -1,3 +1,18 @@
|
|
1 |
import gradio as gr
|
|
|
2 |
|
3 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
import gradio as gr
|
2 |
+
import torch
|
3 |
|
4 |
+
from diffusers import StableDiffusionImg2ImgPipeline
|
5 |
+
|
6 |
+
# load the pipeline
|
7 |
+
device = "cpu"
|
8 |
+
model_id_or_path = "runwayml/stable-diffusion-v1-5"
|
9 |
+
# model_id_or_path = "shanetx/stable-diffusion-wtx-app"
|
10 |
+
img2img_pipe = StableDiffusionImg2ImgPipeline.from_pretrained(model_id_or_path, torch_dtype=torch.float16)
|
11 |
+
img2img_pipe = img2img_pipe.to(device)
|
12 |
+
|
13 |
+
|
14 |
+
def img2img_diff(prompt, img):
|
15 |
+
return img2img_pipe(prompt=prompt, image=img, strength=0.75, guidance_scale=7.5).images[0]
|
16 |
+
|
17 |
+
|
18 |
+
gr.Interface(fn=img2img_diff, inputs=['text', 'image'], outputs='image')
|
requirements.txt
ADDED
@@ -0,0 +1,4 @@
|
|
|
|
|
|
|
|
|
|
|
1 |
+
torch
|
2 |
+
diffusers
|
3 |
+
transformers
|
4 |
+
accelerate
|