Spaces:
Sleeping
Sleeping
Add app to spaces
Browse files- app.py +53 -0
- requirements.txt +5 -0
app.py
ADDED
@@ -0,0 +1,53 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
import torch
|
3 |
+
from diffusers import StableDiffusionPipeline, AutoencoderKL
|
4 |
+
|
5 |
+
|
6 |
+
title = "Text-to-image Generator"
|
7 |
+
description = """
|
8 |
+
This Space uses the sdxs-512-0.9 model which has the ability to generate high quality images in the faction of the time of previous methods.
|
9 |
+
|
10 |
+
This Space demos the model on an inexpensive CPU, where it can generate images in just a couple of seconds. When on a GPU this model can generate up to 100 images per second.
|
11 |
+
|
12 |
+
Model: https://huggingface.co/IDKiro/sdxs-512-0.9\n
|
13 |
+
Paper: https://arxiv.org/pdf/2403.16627.pdf
|
14 |
+
|
15 |
+
|
16 |
+
"""
|
17 |
+
|
18 |
+
|
19 |
+
def generate_image(prompt):
|
20 |
+
|
21 |
+
repo = "IDKiro/sdxs-512-0.9"
|
22 |
+
weight_type = torch.float32
|
23 |
+
|
24 |
+
# Load model.
|
25 |
+
pipe = StableDiffusionPipeline.from_pretrained(repo, torch_dtype=weight_type)
|
26 |
+
# pipe.vae = AutoencoderKL.from_pretrained("IDKiro/sdxs-512-0.9/vae_large") # use original VAE
|
27 |
+
# pipe.to("cuda") # add this in only for gpu inference
|
28 |
+
|
29 |
+
# Ensure using the same inference steps as the loaded model and CFG set to 0.
|
30 |
+
image = pipe(
|
31 |
+
prompt,
|
32 |
+
num_inference_steps=1,
|
33 |
+
guidance_scale=0,
|
34 |
+
generator=torch.Generator(device="cpu") # change to 'cuda' for gpu inference
|
35 |
+
).images[0]
|
36 |
+
|
37 |
+
return image
|
38 |
+
|
39 |
+
|
40 |
+
# Build the Gradio interface
|
41 |
+
iface_generate_image = gr.Interface(
|
42 |
+
fn=generate_image,
|
43 |
+
title=title,
|
44 |
+
description=description,
|
45 |
+
inputs=[
|
46 |
+
gr.Textbox(label="Text Prompt", placeholder="Type your prompt here..."),
|
47 |
+
],
|
48 |
+
outputs=gr.Image(label="Generated Image"),
|
49 |
+
allow_flagging="never",
|
50 |
+
)
|
51 |
+
|
52 |
+
# start interface
|
53 |
+
iface_generate_image.launch()
|
requirements.txt
ADDED
@@ -0,0 +1,5 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
gradio==4.23.0
|
2 |
+
torch==2.2.1
|
3 |
+
diffusers==0.27.2
|
4 |
+
transformers==4.39.1
|
5 |
+
accelerate==0.27.2
|