Update app.py
Browse files
app.py
CHANGED
@@ -1,11 +1,20 @@
|
|
1 |
import gradio as gr
|
2 |
-
|
|
|
|
|
3 |
import torch
|
4 |
|
5 |
-
|
6 |
-
pipe = AutoPipelineForText2Image.from_pretrained("stabilityai/sdxl-turbo", torch_dtype=torch.float16, variant="fp16")
|
7 |
-
pipe.to("cuda")
|
8 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
9 |
# Define the image generation function
|
10 |
def generate_image(prompt, steps, guidance):
|
11 |
image = pipe(prompt=prompt, num_inference_steps=steps, guidance_scale=guidance).images[0]
|
|
|
1 |
import gradio as gr
|
2 |
+
import numpy as np
|
3 |
+
import random
|
4 |
+
from diffusers import DiffusionPipeline
|
5 |
import torch
|
6 |
|
7 |
+
device = "cuda" if torch.cuda.is_available() else "cpu"
|
|
|
|
|
8 |
|
9 |
+
if torch.cuda.is_available():
|
10 |
+
torch.cuda.max_memory_allocated(device=device)
|
11 |
+
pipe = DiffusionPipeline.from_pretrained("stabilityai/sdxl-turbo", torch_dtype=torch.float16, variant="fp16", use_safetensors=True)
|
12 |
+
pipe.enable_xformers_memory_efficient_attention()
|
13 |
+
pipe = pipe.to(device)
|
14 |
+
else:
|
15 |
+
pipe = DiffusionPipeline.from_pretrained("stabilityai/sdxl-turbo", use_safetensors=True)
|
16 |
+
pipe = pipe.to(device)
|
17 |
+
|
18 |
# Define the image generation function
|
19 |
def generate_image(prompt, steps, guidance):
|
20 |
image = pipe(prompt=prompt, num_inference_steps=steps, guidance_scale=guidance).images[0]
|