Spaces:
Runtime error
Runtime error
Update app.py
#4
by
Aditibaheti
- opened
app.py
CHANGED
|
@@ -17,13 +17,18 @@ base_model_repo = "stabilityai/stable-diffusion-3-medium-diffusers"
|
|
| 17 |
lora_weights_path = "./pytorch_lora_weights.safetensors"
|
| 18 |
|
| 19 |
# Load the base model
|
| 20 |
-
pipeline = DiffusionPipeline.from_pretrained(
|
|
|
|
|
|
|
|
|
|
|
|
|
| 21 |
pipeline.load_lora_weights(lora_weights_path)
|
| 22 |
-
pipeline.enable_sequential_cpu_offload()
|
|
|
|
| 23 |
pipeline = pipeline.to(device)
|
| 24 |
|
| 25 |
MAX_SEED = np.iinfo(np.int32).max
|
| 26 |
-
MAX_IMAGE_SIZE =
|
| 27 |
|
| 28 |
def infer(prompt, negative_prompt, seed, randomize_seed, width, height, guidance_scale, num_inference_steps):
|
| 29 |
if randomize_seed:
|
|
@@ -128,9 +133,9 @@ with gr.Blocks(css=css) as demo:
|
|
| 128 |
num_inference_steps = gr.Slider(
|
| 129 |
label="Number of inference steps",
|
| 130 |
minimum=1,
|
| 131 |
-
maximum=
|
| 132 |
step=1,
|
| 133 |
-
value=
|
| 134 |
)
|
| 135 |
|
| 136 |
gr.Examples(
|
|
|
|
| 17 |
lora_weights_path = "./pytorch_lora_weights.safetensors"
|
| 18 |
|
| 19 |
# Load the base model
|
| 20 |
+
pipeline = DiffusionPipeline.from_pretrained(
|
| 21 |
+
base_model_repo,
|
| 22 |
+
torch_dtype=torch.float16 if torch.cuda.is_available() else torch.float32,
|
| 23 |
+
use_auth_token=HUGGINGFACE_TOKEN
|
| 24 |
+
)
|
| 25 |
pipeline.load_lora_weights(lora_weights_path)
|
| 26 |
+
pipeline.enable_sequential_cpu_offload() # Efficient memory usage
|
| 27 |
+
pipeline.enable_xformers_memory_efficient_attention() # Enable xformers memory efficient attention
|
| 28 |
pipeline = pipeline.to(device)
|
| 29 |
|
| 30 |
MAX_SEED = np.iinfo(np.int32).max
|
| 31 |
+
MAX_IMAGE_SIZE = 768 # Reduce max image size to fit within memory constraints
|
| 32 |
|
| 33 |
def infer(prompt, negative_prompt, seed, randomize_seed, width, height, guidance_scale, num_inference_steps):
|
| 34 |
if randomize_seed:
|
|
|
|
| 133 |
num_inference_steps = gr.Slider(
|
| 134 |
label="Number of inference steps",
|
| 135 |
minimum=1,
|
| 136 |
+
maximum=50,
|
| 137 |
step=1,
|
| 138 |
+
value=30,
|
| 139 |
)
|
| 140 |
|
| 141 |
gr.Examples(
|