JavierGon12 commited on
Commit
86165e8
1 Parent(s): 757b45e

Add custom prompt

Browse files
Files changed (1) hide show
  1. app.py +6 -24
app.py CHANGED
@@ -4,32 +4,14 @@ from PIL import Image
4
  import torch
5
  import numpy as np
6
 
7
- def generate_image():
8
- scheduler = DDPMScheduler.from_pretrained("google/ddpm-cat-256")
9
- model = UNet2DModel.from_pretrained("google/ddpm-cat-256").to("cuda")
10
- scheduler.set_timesteps(50)
11
-
12
- sample_size = model.config.sample_size
13
- noise = torch.randn((1, 3, sample_size, sample_size)).to("cuda")
14
- input = noise
15
-
16
- for t in scheduler.timesteps:
17
- with torch.no_grad():
18
- noisy_residual = model(input, t).sample()
19
- prev_noisy_sample = scheduler.step(noisy_residual, t, input).prev_sample
20
- input = prev_noisy_sample
21
 
22
- image = (input / 2 + 0.5).clamp(0, 1)
23
- image = image.cpu().permute(0, 2, 3, 1).numpy()[0]
24
- image = Image.fromarray((image * 255).round().astype("uint8"))
25
- return image
26
 
27
- # Streamlit app
28
- st.title("DDPM Image Generation")
29
- st.write("Generating and displaying an image using DDPM.")
30
 
31
- # Generate and display the image
32
- generated_image = generate_image()
33
- st.image(generated_image, caption="Generated Image", use_column_width=True)
34
 
35
 
 
4
  import torch
5
  import numpy as np
6
 
7
+ import torch
8
+ from diffusers import StableDiffusionPipeline
 
 
 
 
 
 
 
 
 
 
 
 
9
 
10
+ pipe = StableDiffusionPipeline.from_pretrained("runwayml/stable-diffusion-v1-5", torch_dtype=torch.float16)
11
+ pipe = pipe.to("cuda")
 
 
12
 
13
+ prompt = st.text_input('Insert here your prompt')
 
 
14
 
15
+ image = pipe(prompt).images[0]
 
 
16
 
17