import torch from diffusers import AmusedPipeline from transformers import pipeline import PIL.Image from diffusers.utils import load_image import gradio as gr from PIL import Image import cv2 import os, random, gc import numpy as np from accelerate import Accelerator accelerator = Accelerator(cpu=True) pipe = accelerator.prepare(AmusedPipeline.from_pretrained("amused/amused-512", variant=None, torch_dtype=torch.float32, use_safetensors=True)) pipe.vqvae.to(torch.float32) pipe.to("cpu") apol=[] def plex(prompt, neg_prompt, fifth, twice): gc.collect() apol=[] prompt = prompt negative_prompt = neg_prompt nm = random.randint(1, 4836928) while nm % 32 != 0: nm = random.randint(1, 4836928) generator = torch.Generator(device="cpu").manual_seed(nm) image = pipe([prompt]*fifth,guidance_scale=4,num_inference_steps=twice,generator=generator) for a, imze in enumerate(image["images"]): apol.append(imze) return apol iface = gr.Interface(fn=plex, inputs=[gr.Textbox(label="prompt",),gr.Textbox(label="negative prompt", value="low quality,blurry, low resolution, image artifacts"),gr.Slider(label="num images", minimum=1, step=1, maximum=4, value=1), gr.Slider(label="num inference steps", minimum=1, step=1, maximum=20, value=12)], outputs=gr.Gallery(label="out", columns=2),description="Running on cpu, very slow! by JoPmt.") iface.queue(max_size=1,api_open=False) iface.launch(max_threads=1)