auh11 commited on
Commit
0e7b829
1 Parent(s): 2313634

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +3 -1
app.py CHANGED
@@ -7,6 +7,9 @@ import torch
7
 
8
  # Function to generate and display image
9
  def generate_and_display_image(prompt_text):
 
 
 
10
  # Create the diffusion pipeline
11
  pipe = StableDiffusionPipeline.from_pretrained(model_id, torch_dtype=torch.float16)
12
  pipe = pipe.to(device)
@@ -37,7 +40,6 @@ def display_image(image_path):
37
 
38
  # Model parameters
39
  model_id = "CompVis/stable-diffusion-v1-4"
40
- device = "cuda"
41
 
42
  # Streamlit text input for prompt
43
  prompt_text = st.text_input("Enter the prompt:")
 
7
 
8
  # Function to generate and display image
9
  def generate_and_display_image(prompt_text):
10
+ # Set device to CPU if GPU is not available
11
+ device = "cuda" if torch.cuda.is_available() else "cpu"
12
+
13
  # Create the diffusion pipeline
14
  pipe = StableDiffusionPipeline.from_pretrained(model_id, torch_dtype=torch.float16)
15
  pipe = pipe.to(device)
 
40
 
41
  # Model parameters
42
  model_id = "CompVis/stable-diffusion-v1-4"
 
43
 
44
  # Streamlit text input for prompt
45
  prompt_text = st.text_input("Enter the prompt:")