Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,30 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import torch, os, gc, random
|
2 |
+
import gradio as gr
|
3 |
+
from PIL import Image
|
4 |
+
from diffusers.utils import load_image
|
5 |
+
from accelerate import Accelerator
|
6 |
+
from diffusers import StableDiffusionXLPipeline, EulerDiscreteScheduler
|
7 |
+
accelerator = Accelerator(cpu=True)
|
8 |
+
|
9 |
+
pipe = accelerator.prepare(StableDiffusionXLPipeline.from_single_file("https://huggingface.co/lllyasviel/fav_models/fav/realisticStockPhoto_v10.safetensors", torch_dtype=torch.bfloat16, use_safetensors=True, variant=None, safety_checker=False))
|
10 |
+
##pipe.scheduler = accelerator.prepare(EulerDiscreteScheduler.from_config(pipe.scheduler.config))
|
11 |
+
##pipe.unet.to(memory_format=torch.channels_last)
|
12 |
+
pipe.to("cpu")
|
13 |
+
apol=[]
|
14 |
+
def plex(prompt,neg_prompt,stips,nut):
|
15 |
+
apol=[]
|
16 |
+
if nut == 0:
|
17 |
+
nm = random.randint(1, 2147483616)
|
18 |
+
while nm % 32 != 0:
|
19 |
+
nm = random.randint(1, 2147483616)
|
20 |
+
else:
|
21 |
+
nm=nut
|
22 |
+
generator = torch.Generator(device="cpu").manual_seed(nm)
|
23 |
+
image = pipe(prompt=prompt, negative_prompt=neg_prompt, denoising_end=1.0,num_inference_steps=stips, output_type="pil",generator=generator)
|
24 |
+
for i, imge in enumerate(image["images"]):
|
25 |
+
apol.append(imge)
|
26 |
+
return apol
|
27 |
+
|
28 |
+
iface = gr.Interface(fn=plex, inputs=[gr.Textbox(label="prompt"),gr.Textbox(label="negative prompt",value="ugly, blurry, poor quality"), gr.Slider(label="num inference steps", minimum=1, step=1, maximum=10, value=6),gr.Slider(label="manual seed (leave 0 for random)", minimum=0,step=32,maximum=2147483616,value=0)], outputs=gr.Gallery(label="out", columns=1),description="Running on cpu, very slow! by JoPmt.")
|
29 |
+
iface.queue(max_size=1,api_open=False)
|
30 |
+
iface.launch(max_threads=1)
|