-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.py
44 lines (34 loc) · 1.2 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
41
42
43
44
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("Text to Image")
ctk.set_appearance_mode("dark")
# input
prompt = ctk.CTkEntry(master=app, height=40, width=512, font=("Arial", 20), text_color="black", fg_color="white")
prompt.place(x=10, y=10)
# result area
lmain = ctk.CTkLabel(master=app, height=512, width=512, text="")
lmain.place(x=10, y=110)
# Model initialization
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(str(prompt.get())).images[0]
image.save('generatedimage.png')
img = ctk.CTkImage(image, size=(512, 512))
lmain.configure(image=img)
# Button to generate
trigger = ctk.CTkButton(master=app, height=40, width=120, font=("Arial", 20), text_color="white", fg_color="blue", command=generate)
trigger.configure(text='Generate')
trigger.place(x=206, y=60)
app.mainloop()