JoPmt commited on
Commit
2aba8c5
·
1 Parent(s): 9cf429a

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +28 -0
app.py ADDED
@@ -0,0 +1,28 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from PIL import Image
2
+ import gradio as gr
3
+ import random, os, gc
4
+ import torch
5
+ from accelerate import Accelerator
6
+ from transformers import pipeline
7
+ from diffusers.utils import load_image
8
+ from diffusers import EulerDiscreteScheduler, DiffusionPipeline
9
+
10
+ accelerator = Accelerator(cpu=True)
11
+ pipe = accelerator.prepare(DiffusionPipeline.from_pretrained("stabilityai/sdxl-turbo", torch_dtype=torch.bfloat16, use_safetensors=True, variant="fp16", safety_checker=None))
12
+ pipe.scheduler = EulerDiscreteScheduler.from_config(pipe.scheduler.config)
13
+ pipe.unet.to(memory_format=torch.channels_last)
14
+ pipe = accelerator.prepare(pipe.to("cpu"))
15
+ generator = torch.Generator("cpu").manual_seed(random.randint(1, 867346))
16
+ apol=[]
17
+
18
+ def plex(prompt):
19
+ gc.collect()
20
+ apol=[]
21
+ imags = pipe(prompt=[prompt]*2,num_inference_steps=2,width=512,height=512,guidance_scale=0.0,generator=generator)
22
+ for i, igs in enumerate(imags["images"]):
23
+ apol.append(igs)
24
+ return apol
25
+
26
+ iface = gr.Interface(fn=plex,inputs=gr.Textbox(), outputs=gr.Gallery(columns=2), title="Stabilityai SDXL-Turbo CPU", description="Running on CPU, very slow! by JoPmt")
27
+ iface.queue(max_size=1)
28
+ iface.launch(max_threads=1)