lelafav502 commited on
Commit
09bc5a3
·
1 Parent(s): bdbd893

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +18 -14
app.py CHANGED
@@ -1,21 +1,25 @@
 
1
  import torch
2
- from diffusers import StableDiffusionPipeline
3
- from PIL import Image
4
- import io
5
 
6
- # Load the model
7
- pipe = StableDiffusionPipeline.from_pretrained("CompVis/stable-diffusion-v1-4", torch_dtype=torch.float16)
 
 
 
8
  pipe = pipe.to("cuda")
9
 
10
- def generate_image(prompt):
11
- image = pipe(prompt).images[0]
12
- return image
 
 
 
 
 
 
13
 
14
- # Take prompt as input
15
- prompt = input("Enter a prompt: ")
16
 
17
- # Generate the image
18
- generated_image = generate_image(prompt)
19
 
20
- # Display the generated image
21
- generated_image.show()
 
1
+ from diffusers import StableDiffusionPipeline, EulerDiscreteScheduler
2
  import torch
 
 
 
3
 
4
+ model_id = "stabilityai/stable-diffusion-2"
5
+
6
+ # Use the Euler scheduler here instead
7
+ scheduler = EulerDiscreteScheduler.from_pretrained(model_id, subfolder="scheduler")
8
+ pipe = StableDiffusionPipeline.from_pretrained(model_id, scheduler=scheduler, revision="fp16", torch_dtype=torch.float16)
9
  pipe = pipe.to("cuda")
10
 
11
+ prompt = "realistic photo of 3d cartoon style of a cat in a space suit with milky way background"
12
+
13
+ def txt2img(prompt):
14
+
15
+ image = pipe(prompt, height=768, width=768, guidance_scale = 10).images[0]
16
+
17
+ image.save("sd_image.png")
18
+
19
+ return image
20
 
21
+ txt2img(prompt)
 
22
 
23
+ import gradio as gr
 
24
 
25
+ gr.Interface(txt2img, gr.Text(), gr.Image(), title = 'Stable Diffusion 2.0 Colab with Gradio UI').launch(share = True, debug = True)