Spaces:
Runtime error
Runtime error
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,22 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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
|
7 |
+
accelerator = Accelerator(cpu=True)
|
8 |
+
|
9 |
+
pipe = accelerator.prepare(StableDiffusionXLPipeline.from_pretrained("segmind/SSD-1B", torch_dtype=torch.float32, use_safetensors=True, variant="fp32"))
|
10 |
+
pipe = accelerator.prepare(pipe.to("cpu"))
|
11 |
+
|
12 |
+
def plex(prompt,neg_prompt,stips):
|
13 |
+
apol=[]
|
14 |
+
|
15 |
+
image = pipe(prompt=prompt, negative_prompt=neg_prompt, num_inference_steps=stips, output_type="pil")
|
16 |
+
for i, imge in enumerate(image["images"]):
|
17 |
+
apol.append(imge)
|
18 |
+
return apol
|
19 |
+
|
20 |
+
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=5, value=2)], outputs=gr.Gallery(label="out", columns=2))
|
21 |
+
iface.queue(max_size=1)
|
22 |
+
iface.launch(max_threads=1)
|