harpomaxx commited on
Commit
846fabc
·
1 Parent(s): dd88c3a

add gradio app

Browse files
Files changed (1) hide show
  1. app.py +114 -0
app.py ADDED
@@ -0,0 +1,114 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ PATH = 'harpomaxx/deeplili' #stable diffusion 1.5
2
+ from PIL import Image
3
+ import torch
4
+ from transformers import CLIPTextModel, CLIPTokenizer
5
+ from diffusers import AutoencoderKL, UNet2DConditionModel, PNDMScheduler
6
+ from diffusers import UniPCMultistepScheduler
7
+ from diffusers import StableDiffusionPipeline
8
+ from PIL import Image
9
+ from tqdm.auto import tqdm
10
+ import random
11
+ import gradio as gr
12
+
13
+ guidance_scale = 8.5 # Scale for classifier-free guidance
14
+
15
+
16
+ pipe = StableDiffusionPipeline.from_pretrained(PATH,local_files_only=False ).to("cpu")
17
+ guidance_scale = 8.5
18
+
19
+ def generate_images(prompt, guidance_scale, n_samples, num_inference_steps):
20
+ seeds = [random.randint(1, 10000) for _ in range(n_samples)]
21
+ images = []
22
+ for seed in tqdm(seeds):
23
+ torch.manual_seed(seed)
24
+ image = pipe(prompt, num_inference_steps=num_inference_steps,guidance_scale=guidance_scale).images[0]
25
+ images.append(image)
26
+ return images
27
+
28
+ def gr_generate_images(prompt: str, num_images: int, num_inference: int):
29
+ prompt = prompt + "sks style"
30
+ images = generate_images(prompt, tokenizer, text_encoder, unet, vae, scheduler, guidance_scale, num_images, num_inference)
31
+ return images
32
+
33
+ with gr.Blocks() as demo:
34
+ examples = [
35
+ [
36
+ 'A black and white cute character on top of a hill',
37
+ 1,
38
+ 30
39
+ ],
40
+ [
41
+ 'Bubbles and mountains in the sky',
42
+ 1,
43
+ 20
44
+ ],
45
+ [
46
+ 'A tree with multiple eyes and a small flower muted colors',
47
+ 1,
48
+ 20
49
+ ],
50
+ [
51
+ "3d character on top of a hill",
52
+ 1,
53
+ 20
54
+ ],
55
+ [
56
+ "a poster of a large forest with black and white characters",
57
+ 1,
58
+ 20
59
+ ],
60
+ ]
61
+ gr.Markdown(
62
+ """
63
+ <img src="https://github.com/harpomaxx/DeepLili/raw/main/images/lilifiallo/660.png" width="150" height="150">
64
+
65
+ # #DeepLili v0.45b
66
+
67
+ ## Enter your prompt and generate a work of art in the style of Lili's Toy Art paintings.
68
+ """
69
+ )
70
+
71
+ with gr.Column(variant="panel"):
72
+ with gr.Row(variant="compact"):
73
+ text = gr.Textbox(
74
+ label="Enter your prompt",
75
+ show_label=False,
76
+ max_lines=2,
77
+ placeholder="a white and black drawing of a cute character on top of a house with a little animal"
78
+ ).style(
79
+ container=False,
80
+ )
81
+
82
+ with gr.Row(variant="compact"):
83
+ num_images_slider = gr.Slider(
84
+ minimum=1,
85
+ maximum=10,
86
+ step=1,
87
+ value=1,
88
+ label="Number of Images",
89
+ )
90
+
91
+ num_inference_steps_slider = gr.Slider(
92
+ minimum=1,
93
+ maximum=25,
94
+ step=1,
95
+ value=20,
96
+ label="Number of Inference Steps",
97
+ )
98
+
99
+ btn = gr.Button("Generate image").style(full_width=False)
100
+
101
+ gallery = gr.Gallery(
102
+ label="Generated images", show_label=False, elem_id="gallery"
103
+ ).style(columns=[5], rows=[1], object_fit="contain", height="250px", width="250px")
104
+
105
+ btn.click(gr_generate_images, [text, num_images_slider,num_inference_steps_slider], gallery)
106
+ gr.Examples(examples, inputs=[text])
107
+ gr.HTML(
108
+ """
109
+ <h6><a href="https://harpomaxx.github.io/"> harpomaxx </a></h6>
110
+ """
111
+ )
112
+
113
+ if __name__ == "__main__":
114
+ demo.queue().launch(share=True)