Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,7 +1,7 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
import numpy as np
|
| 3 |
import random
|
| 4 |
-
from diffusers import
|
| 5 |
import torch
|
| 6 |
|
| 7 |
MAX_SEED = np.iinfo(np.int32).max
|
|
@@ -9,11 +9,16 @@ MAX_IMAGE_SIZE = 1024
|
|
| 9 |
|
| 10 |
def infer(prompt, negative_prompt, seed, randomize_seed, width, height, guidance_scale, num_inference_steps, model):
|
| 11 |
|
| 12 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 13 |
|
| 14 |
-
pipe = AutoPipelineForText2Image.from_pretrained(model)
|
| 15 |
pipe.scheduler = EulerDiscreteScheduler.from_config(pipe.scheduler.config)
|
| 16 |
-
pipe = pipe.to(device)
|
| 17 |
pipe.safety_checker=None
|
| 18 |
|
| 19 |
if randomize_seed:
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
import numpy as np
|
| 3 |
import random
|
| 4 |
+
from diffusers import DiffusionPipeline, EulerDiscreteScheduler
|
| 5 |
import torch
|
| 6 |
|
| 7 |
MAX_SEED = np.iinfo(np.int32).max
|
|
|
|
| 9 |
|
| 10 |
def infer(prompt, negative_prompt, seed, randomize_seed, width, height, guidance_scale, num_inference_steps, model):
|
| 11 |
|
| 12 |
+
if torch.cuda.is_available():
|
| 13 |
+
torch.cuda.max_memory_allocated(device="cuda")
|
| 14 |
+
pipe = DiffusionPipeline.from_pretrained(model, torch_dtype=torch.float16, variant="fp16", use_safetensors=True)
|
| 15 |
+
pipe.enable_xformers_memory_efficient_attention()
|
| 16 |
+
pipe = pipe.to("cuda")
|
| 17 |
+
else:
|
| 18 |
+
pipe = DiffusionPipeline.from_pretrained(model, use_safetensors=True)
|
| 19 |
+
pipe = pipe.to("cpu")
|
| 20 |
|
|
|
|
| 21 |
pipe.scheduler = EulerDiscreteScheduler.from_config(pipe.scheduler.config)
|
|
|
|
| 22 |
pipe.safety_checker=None
|
| 23 |
|
| 24 |
if randomize_seed:
|