Spaces:
Sleeping
Sleeping
Add app.py with Gradio interface for image generation
Browse files
app.py
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import torch
|
| 2 |
+
from diffusers import StableDiffusionPipeline, AutoencoderKL
|
| 3 |
+
import gradio as gr
|
| 4 |
+
|
| 5 |
+
repo = "IDKiro/sdxs-512-0.9"
|
| 6 |
+
seed = 42
|
| 7 |
+
weight_type = torch.float16
|
| 8 |
+
|
| 9 |
+
# Load model.
|
| 10 |
+
pipe = StableDiffusionPipeline.from_pretrained(repo, torch_dtype=weight_type)
|
| 11 |
+
|
| 12 |
+
generator = pipe
|
| 13 |
+
# move to GPU if available
|
| 14 |
+
if torch.cuda.is_available():
|
| 15 |
+
generator = generator.to("cuda")
|
| 16 |
+
|
| 17 |
+
|
| 18 |
+
def generate(prompts):
|
| 19 |
+
images = generator(list(prompts)).images
|
| 20 |
+
return [images]
|
| 21 |
+
|
| 22 |
+
|
| 23 |
+
demo = gr.Interface(
|
| 24 |
+
generate,
|
| 25 |
+
"textbox",
|
| 26 |
+
"image",
|
| 27 |
+
batch=True,
|
| 28 |
+
max_batch_size=4, # Set the batch size based on your CPU/GPU memory
|
| 29 |
+
).queue()
|
| 30 |
+
|
| 31 |
+
if __name__ == "__main__":
|
| 32 |
+
demo.launch()
|