Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -5,7 +5,8 @@ from diffusers import DiffusionPipeline
|
|
| 5 |
import torch
|
| 6 |
import spaces
|
| 7 |
|
| 8 |
-
|
|
|
|
| 9 |
|
| 10 |
MAX_SEED = np.iinfo(np.int32).max
|
| 11 |
MAX_IMAGE_SIZE = 1024
|
|
@@ -18,13 +19,13 @@ def generate_image(prompt, negative_prompt, seed, randomize_seed, width, height,
|
|
| 18 |
seed = random.randint(0, MAX_SEED)
|
| 19 |
|
| 20 |
# Initialize the generator with the seed
|
| 21 |
-
generator = torch.Generator(device=device).manual_seed(seed)
|
| 22 |
|
| 23 |
-
# Load a simpler model (
|
| 24 |
print("Loading model...")
|
| 25 |
pipe = DiffusionPipeline.from_pretrained("CompVis/stable-diffusion-v1-4", torch_dtype=torch.float32)
|
| 26 |
-
pipe.
|
| 27 |
-
pipe
|
| 28 |
|
| 29 |
print(f"Model loaded successfully on {device}.")
|
| 30 |
|
|
@@ -41,7 +42,7 @@ def generate_image(prompt, negative_prompt, seed, randomize_seed, width, height,
|
|
| 41 |
).images[0]
|
| 42 |
|
| 43 |
# Return the generated image
|
| 44 |
-
return image, None #
|
| 45 |
|
| 46 |
except Exception as e:
|
| 47 |
# If there's an error, catch it and return an error message
|
|
@@ -124,9 +125,9 @@ with gr.Blocks(css=css) as demo:
|
|
| 124 |
guidance_scale = gr.Slider(
|
| 125 |
label="Guidance scale",
|
| 126 |
minimum=0.0,
|
| 127 |
-
maximum=20.0, #
|
| 128 |
step=0.1,
|
| 129 |
-
value=7.5, #
|
| 130 |
)
|
| 131 |
|
| 132 |
num_inference_steps = gr.Slider(
|
|
@@ -134,7 +135,7 @@ with gr.Blocks(css=css) as demo:
|
|
| 134 |
minimum=1,
|
| 135 |
maximum=50,
|
| 136 |
step=1,
|
| 137 |
-
value=25, #
|
| 138 |
)
|
| 139 |
|
| 140 |
gr.Examples(
|
|
|
|
| 5 |
import torch
|
| 6 |
import spaces
|
| 7 |
|
| 8 |
+
# Ensure the correct device (GPU or CPU)
|
| 9 |
+
device = "cuda" if torch.cuda.is_available() else "cpu"
|
| 10 |
|
| 11 |
MAX_SEED = np.iinfo(np.int32).max
|
| 12 |
MAX_IMAGE_SIZE = 1024
|
|
|
|
| 19 |
seed = random.randint(0, MAX_SEED)
|
| 20 |
|
| 21 |
# Initialize the generator with the seed
|
| 22 |
+
generator = torch.Generator(device=device).manual_seed(seed)
|
| 23 |
|
| 24 |
+
# Load a simpler model (CompVis/stable-diffusion-v1-4)
|
| 25 |
print("Loading model...")
|
| 26 |
pipe = DiffusionPipeline.from_pretrained("CompVis/stable-diffusion-v1-4", torch_dtype=torch.float32)
|
| 27 |
+
pipe = pipe.to(device) # Ensure the model is moved to the correct device
|
| 28 |
+
pipe.enable_xformers_memory_efficient_attention() # Enable memory-efficient attention if you want
|
| 29 |
|
| 30 |
print(f"Model loaded successfully on {device}.")
|
| 31 |
|
|
|
|
| 42 |
).images[0]
|
| 43 |
|
| 44 |
# Return the generated image
|
| 45 |
+
return image, None # Return both the image and None for error message
|
| 46 |
|
| 47 |
except Exception as e:
|
| 48 |
# If there's an error, catch it and return an error message
|
|
|
|
| 125 |
guidance_scale = gr.Slider(
|
| 126 |
label="Guidance scale",
|
| 127 |
minimum=0.0,
|
| 128 |
+
maximum=20.0, # Increased max value for better results
|
| 129 |
step=0.1,
|
| 130 |
+
value=7.5, # Increased value for better image quality
|
| 131 |
)
|
| 132 |
|
| 133 |
num_inference_steps = gr.Slider(
|
|
|
|
| 135 |
minimum=1,
|
| 136 |
maximum=50,
|
| 137 |
step=1,
|
| 138 |
+
value=25, # Increased inference steps for better detail
|
| 139 |
)
|
| 140 |
|
| 141 |
gr.Examples(
|