Tulsigida commited on
Commit
632f9b4
·
1 Parent(s): 5a8d785

Upload 3 files

Browse files
Files changed (3) hide show
  1. app.py +56 -0
  2. authtoken.py +2 -0
  3. requirements.txt +26 -0
app.py ADDED
@@ -0,0 +1,56 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Libraries for building GUI
2
+ import tkinter as tk
3
+ import customtkinter as ctk
4
+
5
+ # Machine Learning libraries
6
+ import torch
7
+ from torch import autocast
8
+ from diffusers import StableDiffusionPipeline
9
+
10
+ # Libraries for processing image
11
+ from PIL import ImageTk
12
+
13
+ # private modules
14
+ from authtoken import auth_token
15
+
16
+
17
+ # Create app user interface
18
+ app = tk.Tk()
19
+ app.geometry("532x632")
20
+ app.title("Text to Image app")
21
+ app.configure(bg='black')
22
+ ctk.set_appearance_mode("dark")
23
+
24
+ # Create input box on the user interface
25
+ prompt = ctk.CTkEntry(height=40, width=512, text_font=("Arial", 15), text_color="white", fg_color="black")
26
+ prompt.place(x=10, y=10)
27
+
28
+ # Create a placeholder to show the generated image
29
+ img_placeholder = ctk.CTkLabel(height=512, width=512, text="")
30
+ img_placeholder.place(x=10, y=110)
31
+
32
+ # Download stable diffusion model from hugging face
33
+ modelid = "CompVis/stable-diffusion-v1-4"
34
+ device = "cuda"
35
+ stable_diffusion_model = StableDiffusionPipeline.from_pretrained(modelid, revision="fp16", torch_dtype=torch.float16, use_auth_token=auth_token)
36
+ stable_diffusion_model.to(device)
37
+
38
+ # Generate image from test
39
+ def generate():
40
+ """ This function generate image from a text with stable diffusion"""
41
+ with autocast(device):
42
+ image = stable_diffusion_model(prompt.get(), guidance_scale=8.5)["sample"][0]
43
+
44
+ # Save the generated image
45
+ image.save('generatedimage.png')
46
+
47
+ # Display the generated image on the user interface
48
+ img = ImageTk.PhotoImage(image)
49
+ img_placeholder.configure(image=img)
50
+
51
+
52
+ trigger = ctk.CTkButton(height=40, width=120, text_font=("Arial", 15), text_color="black", fg_color="white", command=generate)
53
+ trigger.configure(text="Generate")
54
+ trigger.place(x=206, y=60)
55
+
56
+ app.mainloop()
authtoken.py ADDED
@@ -0,0 +1,2 @@
 
 
 
1
+ auth_token = "YOUR HUGGING FACE TOKEN HERE"
2
+ # How to get one: https://huggingface.co/docs/hub/security-tokens
requirements.txt ADDED
@@ -0,0 +1,26 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ certifi==2022.9.14
2
+ charset-normalizer==2.1.1
3
+ colorama==0.4.5
4
+ customtkinter==4.6.1
5
+ darkdetect==0.7.1
6
+ diffusers==0.3.0
7
+ filelock==3.8.0
8
+ huggingface-hub==0.9.1
9
+ idna==3.4
10
+ importlib-metadata==4.12.0
11
+ numpy==1.23.3
12
+ packaging==21.3
13
+ Pillow==9.2.0
14
+ pyparsing==3.0.9
15
+ PyYAML==6.0
16
+ regex==2022.9.13
17
+ requests==2.28.1
18
+ tk==0.1.0
19
+ torch
20
+ torchaudio
21
+ torchvision
22
+ tqdm==4.64.1
23
+ transformers==4.22.1
24
+ typing_extensions==4.3.0
25
+ urllib3==1.26.12
26
+ zipp==3.8.1