Waseem7711 commited on
Commit
d749028
·
verified ·
1 Parent(s): 7508b2b

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +4 -4
app.py CHANGED
@@ -1,5 +1,5 @@
1
  import streamlit as st
2
- from diffusers import DiffusionPipeline
3
  import torch
4
  from PIL import Image
5
 
@@ -15,7 +15,7 @@ generate_button = st.sidebar.button("Generate Image")
15
  # Cache the Stable Diffusion model to load it only once
16
  @st.cache_resource
17
  def load_model():
18
- model = DiffusionPipeline.from_pretrained("runwayml/stable-diffusion-v1-5", torch_dtype=torch.float16)
19
  model = model.to("cuda" if torch.cuda.is_available() else "cpu")
20
  return model
21
 
@@ -28,10 +28,10 @@ if generate_button:
28
  st.error("Prompt cannot be empty. Please enter a valid text prompt.")
29
  else:
30
  st.write(f"### Prompt: {prompt}")
31
- with st.spinner("Generating image... Please wait."):
32
  try:
33
  # Generate the image
34
- image = pipe(prompt).images[0]
35
 
36
  # Display the image
37
  st.image(image, caption="Generated Image", use_column_width=True)
 
1
  import streamlit as st
2
+ from diffusers import StableDiffusionPipeline
3
  import torch
4
  from PIL import Image
5
 
 
15
  # Cache the Stable Diffusion model to load it only once
16
  @st.cache_resource
17
  def load_model():
18
+ model = StableDiffusionPipeline.from_pretrained("stabilityai/stable-diffusion-2-1-base", torch_dtype=torch.float16)
19
  model = model.to("cuda" if torch.cuda.is_available() else "cpu")
20
  return model
21
 
 
28
  st.error("Prompt cannot be empty. Please enter a valid text prompt.")
29
  else:
30
  st.write(f"### Prompt: {prompt}")
31
+ with st.spinner("Generating image... Please wait. This may take a few moments depending on system performance."):
32
  try:
33
  # Generate the image
34
+ image = pipe(prompt, num_inference_steps=50, guidance_scale=7.5).images[0]
35
 
36
  # Display the image
37
  st.image(image, caption="Generated Image", use_column_width=True)