Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,23 +1,30 @@
|
|
| 1 |
-
import
|
| 2 |
import torch
|
| 3 |
from diffusers import DiffusionPipeline
|
| 4 |
|
| 5 |
-
|
| 6 |
-
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
).to("cuda")
|
| 13 |
-
pipe.load_lora_weights("ZB-Tech/Text-to-Image")
|
| 14 |
-
return pipe
|
| 15 |
|
| 16 |
-
|
| 17 |
-
|
| 18 |
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
import torch
|
| 3 |
from diffusers import DiffusionPipeline
|
| 4 |
|
| 5 |
+
# Load model once
|
| 6 |
+
pipe = DiffusionPipeline.from_pretrained(
|
| 7 |
+
"stabilityai/stable-diffusion-xl-base-1.0",
|
| 8 |
+
torch_dtype=torch.float16,
|
| 9 |
+
variant="fp16",
|
| 10 |
+
use_safetensors=True
|
| 11 |
+
).to("cuda")
|
|
|
|
|
|
|
|
|
|
| 12 |
|
| 13 |
+
# Load the LoRA weights
|
| 14 |
+
pipe.load_lora_weights("ZB-Tech/Text-to-Image")
|
| 15 |
|
| 16 |
+
# Define generation function
|
| 17 |
+
def generate_image(prompt):
|
| 18 |
+
image = pipe(prompt).images[0]
|
| 19 |
+
return image
|
| 20 |
+
|
| 21 |
+
# Gradio UI
|
| 22 |
+
demo = gr.Interface(
|
| 23 |
+
fn=generate_image,
|
| 24 |
+
inputs=gr.Textbox(label="Enter a prompt", placeholder="e.g. Draw a picture of some coding on a screen with a horror background"),
|
| 25 |
+
outputs=gr.Image(type="pil", label="Generated Image"),
|
| 26 |
+
title="🎨 AI Image Generator",
|
| 27 |
+
description="This demo uses Stable Diffusion XL with custom LoRA weights to generate images from your prompts."
|
| 28 |
+
)
|
| 29 |
+
|
| 30 |
+
demo.launch()
|