Docty commited on
Commit
015a42c
·
verified ·
1 Parent(s): 63ed18c

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +16 -1
app.py CHANGED
@@ -4,10 +4,25 @@ import torch
4
 
5
  st.title("Image Generation 2")
6
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
7
 
8
  prompt = st.text_input("Enter a prompt to generate an image:", value="pipeline under the sea")
9
 
10
  if st.button("Generate Image"):
11
  with st.spinner("Generating image..."):
12
- image = pipe(prompt).images[0]
13
  st.image(image, caption="Generated Image", use_column_width=True)
 
4
 
5
  st.title("Image Generation 2")
6
 
7
+ @st.cache_resource
8
+ def load_pipeline():
9
+ pipe = DiffusionPipeline.from_pretrained(
10
+ "stable-diffusion-v1-5/stable-diffusion-v1-5",
11
+ torch_dtype=torch.float16,
12
+ )
13
+ pipe.to("cuda" if torch.cuda.is_available() else "cpu")
14
+
15
+ pipe.scheduler = DPMSolverMultistepScheduler.from_config(pipeline.scheduler.config)
16
+
17
+ pipe.enable_attention_slicing()
18
+
19
+ return pipe
20
+
21
+ pipeline = load_pipeline()
22
 
23
  prompt = st.text_input("Enter a prompt to generate an image:", value="pipeline under the sea")
24
 
25
  if st.button("Generate Image"):
26
  with st.spinner("Generating image..."):
27
+ image = pipeline(prompt).images[0]
28
  st.image(image, caption="Generated Image", use_column_width=True)