Commit
·
3fec1fb
1
Parent(s):
74ce001
added gradio
Browse filesI think image.save doesn't work in a hugging face space so I'm trying this instead
app.py
CHANGED
|
@@ -1,5 +1,6 @@
|
|
| 1 |
import torch
|
| 2 |
from diffusers import StableDiffusionPipeline
|
|
|
|
| 3 |
|
| 4 |
model_base = "runwayml/stable-diffusion-v1-5"
|
| 5 |
lora_model_path = "Krebzonide/3a0s-w68r-4qw1-0"
|
|
@@ -8,9 +9,47 @@ pipe = StableDiffusionPipeline.from_pretrained(model_base, torch_dtype=torch.flo
|
|
| 8 |
pipe.unet.load_attn_procs(lora_model_path)
|
| 9 |
pipe.to("cuda")
|
| 10 |
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
import torch
|
| 2 |
from diffusers import StableDiffusionPipeline
|
| 3 |
+
import gradio as gr
|
| 4 |
|
| 5 |
model_base = "runwayml/stable-diffusion-v1-5"
|
| 6 |
lora_model_path = "Krebzonide/3a0s-w68r-4qw1-0"
|
|
|
|
| 9 |
pipe.unet.load_attn_procs(lora_model_path)
|
| 10 |
pipe.to("cuda")
|
| 11 |
|
| 12 |
+
css = """
|
| 13 |
+
.btn-green {
|
| 14 |
+
background-image: linear-gradient(to bottom right, #86efac, #22c55e) !important;
|
| 15 |
+
border-color: #22c55e !important;
|
| 16 |
+
color: #166534 !important;
|
| 17 |
+
}
|
| 18 |
+
.btn-green:hover {
|
| 19 |
+
background-image: linear-gradient(to bottom right, #86efac, #86efac) !important;
|
| 20 |
+
}
|
| 21 |
+
.btn-red {
|
| 22 |
+
background: linear-gradient(to bottom right, #fda4af, #fb7185) !important;
|
| 23 |
+
border-color: #fb7185 !important;
|
| 24 |
+
color: #9f1239 !important;
|
| 25 |
+
}
|
| 26 |
+
.btn-red:hover {background: linear-gradient(to bottom right, #fda4af, #fda4af) !important;}
|
| 27 |
+
/*****/
|
| 28 |
+
.dark .btn-green {
|
| 29 |
+
background-image: linear-gradient(to bottom right, #047857, #065f46) !important;
|
| 30 |
+
border-color: #047857 !important;
|
| 31 |
+
color: #ffffff !important;
|
| 32 |
+
}
|
| 33 |
+
.dark .btn-green:hover {
|
| 34 |
+
background-image: linear-gradient(to bottom right, #047857, #047857) !important;
|
| 35 |
+
}
|
| 36 |
+
.dark .btn-red {
|
| 37 |
+
background: linear-gradient(to bottom right, #be123c, #9f1239) !important;
|
| 38 |
+
border-color: #be123c !important;
|
| 39 |
+
color: #ffffff !important;
|
| 40 |
+
}
|
| 41 |
+
.dark .btn-red:hover {background: linear-gradient(to bottom right, #be123c, #be123c) !important;}
|
| 42 |
+
"""
|
| 43 |
+
|
| 44 |
+
def generate(prompt):
|
| 45 |
+
images = pipe(prompt,num_inference_steps=25,guidance_scale=7.5).images
|
| 46 |
+
return [(img, f"Image {i+1}") for i, img in enumerate(images)]
|
| 47 |
+
|
| 48 |
+
|
| 49 |
+
with gr.Blocks(css=css) as demo:
|
| 50 |
+
with gr.Collumn():
|
| 51 |
+
prompt = gr.Textbox(label="Prompt")
|
| 52 |
+
submit_btn = gr.Button("Generate", variant="primary", min_width="96px")
|
| 53 |
+
gallery = gr.Gallery(label="Generated images")
|
| 54 |
+
|
| 55 |
+
submit_btn.click(generate, [prompt], [gallery], queue=True)
|