forked from nicknochnack/StableDiffusionApp
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.py
40 lines (30 loc) · 1.16 KB
/
app.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
import tkinter as tk
import customtkinter as ctk
from PIL import ImageTk
from authtoken import auth_token
import torch
from torch import autocast
from diffusers import StableDiffusionPipeline
# Create the app
app = tk.Tk()
app.geometry("532x632")
app.title("Stable Bud")
ctk.set_appearance_mode("dark")
prompt = ctk.CTkEntry(height=40, width=512, text_font=("Arial", 20), text_color="black", fg_color="white")
prompt.place(x=10, y=10)
lmain = ctk.CTkLabel(height=512, width=512)
lmain.place(x=10, y=110)
modelid = "CompVis/stable-diffusion-v1-4"
device = "cuda"
pipe = StableDiffusionPipeline.from_pretrained(modelid, revision="fp16", torch_dtype=torch.float16, use_auth_token=auth_token)
pipe.to(device)
def generate():
with autocast(device):
image = pipe(prompt.get(), guidance_scale=8.5)["sample"][0]
image.save('generatedimage.png')
img = ImageTk.PhotoImage(image)
lmain.configure(image=img)
trigger = ctk.CTkButton(height=40, width=120, text_font=("Arial", 20), text_color="white", fg_color="blue", command=generate)
trigger.configure(text="Generate")
trigger.place(x=206, y=60)
app.mainloop()