anasmkh commited on
Commit
712157a
·
verified ·
1 Parent(s): 6d64247

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +31 -0
app.py ADDED
@@ -0,0 +1,31 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from diffusers import StableDiffusionImg2ImgPipeline
2
+ import torch
3
+ from PIL import Image
4
+ from diffusers import DiffusionPipeline
5
+ import gradio as gr
6
+
7
+
8
+ pipe = DiffusionPipeline.from_pretrained("stable-diffusion-v1-5/stable-diffusion-v1-5")
9
+
10
+ prompt = "Astronaut in a jungle, cold color palette, muted colors, detailed, 8k"
11
+ image = pipe(prompt).images[0]
12
+
13
+
14
+
15
+ def img2img(image, prompt, strength):
16
+ images = pipe(prompt=prompt, image=image, strength=strength, guidance_scale=7.5).images
17
+ return images[0]
18
+
19
+ iface = gr.Interface(
20
+ fn=img2img,
21
+ inputs=[
22
+ gr.Image(type="pil"),
23
+ gr.Textbox(label="Prompt"),
24
+ gr.Slider(label="Strength", minimum=0.0, maximum=1.0, value=0.75, step=0.05),
25
+ ],
26
+ outputs=gr.Image(type="pil"),
27
+ title="Stable Diffusion img2img",
28
+ description="Modify an image using Stable Diffusion",
29
+ )
30
+
31
+ iface.launch(debug=True)