Spaces:
Runtime error
Runtime error
File size: 1,191 Bytes
1e66a62 2f94b61 1e66a62 2f94b61 1e66a62 2f94b61 1e66a62 9a59bfc 2f94b61 1e66a62 2f94b61 5a73097 2f94b61 1e66a62 5a73097 7592d36 1e66a62 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
from PIL import Image
import gradio as gr
import random, os, gc
import torch
from accelerate import Accelerator
from transformers import pipeline
from diffusers.utils import load_image
from diffusers import EulerDiscreteScheduler, DiffusionPipeline
accelerator = Accelerator(cpu=True)
pipe = accelerator.prepare(DiffusionPipeline.from_pretrained("stabilityai/sd-turbo", torch_dtype=torch.float32, use_safetensors=True, safety_checker=None))
pipe.scheduler = EulerDiscreteScheduler.from_config(pipe.scheduler.config)
pipe.unet.to(memory_format=torch.channels_last)
pipe = accelerator.prepare(pipe.to("cpu"))
generator = torch.Generator("cpu").manual_seed(random.randint(1, 867346))
apol=[]
def plex(prompt):
gc.collect()
apol=[]
imags = pipe(prompt=[prompt]*2,negative_prompt=["bad quality"]*2,num_inference_steps=5,width=512,height=512,generator=generator)
for i, igs in enumerate(imags["images"]):
apol.append(igs)
return apol
iface = gr.Interface(fn=plex,inputs=gr.Textbox(), outputs=gr.Gallery(columns=2), title="Stabilityai SD-Turbo CPU", description="Running on CPU, very slow! by JoPmt")
iface.queue(max_size=1,api_open=False)
iface.launch(max_threads=1) |