Qianli commited on
Commit
d38fc1d
1 Parent(s): 8881e9b

Add application file

Browse files
Files changed (1) hide show
  1. app.py +27 -0
app.py ADDED
@@ -0,0 +1,27 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from diffusers import StableDiffusionPipeline, EulerDiscreteScheduler
2
+ import torch
3
+ import gradio as gr
4
+
5
+ model_id = "stabilityai/stable-diffusion-2"
6
+
7
+ # Use the Euler scheduler here instead
8
+ scheduler = EulerDiscreteScheduler.from_pretrained(model_id, subfolder="scheduler")
9
+ pipe = StableDiffusionPipeline.from_pretrained(model_id, scheduler=scheduler, revision="fp16", torch_dtype=torch.float16)
10
+ pipe = pipe.to("cuda")
11
+ pipe.enable_attention_slicing()
12
+ prompt = "a young doctor talk with a patient in the cartoon style"
13
+
14
+
15
+ num_imgs=3
16
+ scale=7.5
17
+ steps=100
18
+ i=0
19
+ def gen(num_imgs, scale, steps):
20
+ image = pipe(num_imgs*[prompt], height=768, width=768,guidance_scale=scale, num_inference_steps=steps).images
21
+ return image
22
+ gr.Interface(fn=gen, inputs=['text', gr.Slider(1, 100, 20), gr.Slider(1, maximum=20, value=10, step=1), gr.Slider(minimum=1, step=1, maximum=999999999999999999, randomize=True)], outputs='image', title="Stable Diffusion 2.0 ZQL", description="SD 2.0. <b>WARNING:</b> Extremely Slow. 130s/Iteration. Expect 25-50mins an image for 10-20 iterations respectively.", article = "Code Monkey: <a href=\"https://huggingface.co/qianli\">千里马</a>").launch()
23
+
24
+ for i in range(num_imgs):
25
+ file_name="doctor"+str(i)+".png"
26
+ image[i].save(file_name)
27
+