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