khliif commited on
Commit
9e80620
1 Parent(s): 45d0716
Files changed (1) hide show
  1. app.py +212 -0
app.py ADDED
@@ -0,0 +1,212 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ import torch
3
+ from torch import autocast
4
+ from diffusers import StableDiffusionPipeline
5
+
6
+ #model_id = "hakurei/waifu-diffusion"
7
+ pipe = StableDiffusionPipeline.from_pretrained("hakurei/waifu-diffusion", torch_type=torch.float16, revision="fp16")
8
+ pipe = pipe.to("cuda")
9
+ #torch.backends.cudnn.benchmark = True
10
+ num_samples = 2
11
+
12
+ def infer(prompt):
13
+ images = pipe([prompt] * num_samples, guidance_scale=7.5)["sample"]
14
+ return images
15
+
16
+ css = """
17
+ .gradio-container {
18
+ font-family: 'IBM Plex Sans', sans-serif;
19
+ }
20
+ .gr-button {
21
+ color: white;
22
+ border-color: black;
23
+ background: black;
24
+ }
25
+ input[type='range'] {
26
+ accent-color: black;
27
+ }
28
+ .dark input[type='range'] {
29
+ accent-color: #dfdfdf;
30
+ }
31
+ .container {
32
+ max-width: 730px;
33
+ margin: auto;
34
+ padding-top: 1.5rem;
35
+ }
36
+ #gallery {
37
+ min-height: 22rem;
38
+ margin-bottom: 15px;
39
+ margin-left: auto;
40
+ margin-right: auto;
41
+ border-bottom-right-radius: .5rem !important;
42
+ border-bottom-left-radius: .5rem !important;
43
+ }
44
+ #gallery>div>.h-full {
45
+ min-height: 20rem;
46
+ }
47
+ .details:hover {
48
+ text-decoration: underline;
49
+ }
50
+ .gr-button {
51
+ white-space: nowrap;
52
+ }
53
+ .gr-button:focus {
54
+ border-color: rgb(147 197 253 / var(--tw-border-opacity));
55
+ outline: none;
56
+ box-shadow: var(--tw-ring-offset-shadow), var(--tw-ring-shadow), var(--tw-shadow, 0 0 #0000);
57
+ --tw-border-opacity: 1;
58
+ --tw-ring-offset-shadow: var(--tw-ring-inset) 0 0 0 var(--tw-ring-offset-width) var(--tw-ring-offset-color);
59
+ --tw-ring-shadow: var(--tw-ring-inset) 0 0 0 calc(3px var(--tw-ring-offset-width)) var(--tw-ring-color);
60
+ --tw-ring-color: rgb(191 219 254 / var(--tw-ring-opacity));
61
+ --tw-ring-opacity: .5;
62
+ }
63
+ #advanced-btn {
64
+ font-size: .7rem !important;
65
+ line-height: 19px;
66
+ margin-top: 12px;
67
+ margin-bottom: 12px;
68
+ padding: 2px 8px;
69
+ border-radius: 14px !important;
70
+ }
71
+ #advanced-options {
72
+ display: none;
73
+ margin-bottom: 20px;
74
+ }
75
+ .footer {
76
+ margin-bottom: 45px;
77
+ margin-top: 35px;
78
+ text-align: center;
79
+ border-bottom: 1px solid #e5e5e5;
80
+ }
81
+ .footer>p {
82
+ font-size: .8rem;
83
+ display: inline-block;
84
+ padding: 0 10px;
85
+ transform: translateY(10px);
86
+ background: white;
87
+ }
88
+ .dark .footer {
89
+ border-color: #303030;
90
+ }
91
+ .dark .footer>p {
92
+ background: #0b0f19;
93
+ }
94
+ .acknowledgments h4{
95
+ margin: 1.25em 0 .25em 0;
96
+ font-weight: bold;
97
+ font-size: 115%;
98
+ }
99
+ #container-advanced-btns{
100
+ display: flex;
101
+ flex-wrap: wrap;
102
+ justify-content: space-between;
103
+ align-items: center;
104
+ }
105
+ .animate-spin {
106
+ animation: spin 1s linear infinite;
107
+ }
108
+ @keyframes spin {
109
+ from {
110
+ transform: rotate(0deg);
111
+ }
112
+ to {
113
+ transform: rotate(360deg);
114
+ }
115
+ }
116
+ #share-btn-container {
117
+ display: flex; padding-left: 0.5rem !important; padding-right: 0.5rem !important; background-color: #000000; justify-content: center; align-items: center; border-radius: 9999px !important; width: 13rem;
118
+ }
119
+ #share-btn {
120
+ all: initial; color: #ffffff;font-weight: 600; cursor:pointer; font-family: 'IBM Plex Sans', sans-serif; margin-left: 0.5rem !important; padding-top: 0.25rem !important; padding-bottom: 0.25rem !important;
121
+ }
122
+ #share-btn * {
123
+ all: unset;
124
+ }
125
+ .gr-form{
126
+ flex: 1 1 50%; border-top-right-radius: 0; border-bottom-right-radius: 0;
127
+ }
128
+ #prompt-container{
129
+ gap: 0;
130
+ }
131
+ #generated_id{
132
+ min-height: 700px
133
+ }
134
+ """
135
+ block = gr.Blocks(css=css)
136
+
137
+ examples = [
138
+ [
139
+ 'Goku'
140
+ ],
141
+ [
142
+ 'Mikasa Ackerman'
143
+ ],
144
+ [
145
+ 'Saber'
146
+ ],
147
+ ]
148
+
149
+ with block as demo:
150
+ gr.HTML(
151
+ """
152
+ <div style="text-align: center; max-width: 650px; margin: 0 auto;">
153
+ <div
154
+ style="
155
+ display: inline-flex;
156
+ align-items: center;
157
+ gap: 0.8rem;
158
+ font-size: 1.75rem;
159
+ "
160
+ >
161
+ <img src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAACQAAAAkCAYAAADhAJiYAAANeElEQVRYhY1Ye4xc1X3+zjn33Oc8dmdmZ5+zttfrZ/wIDmAgJgkWoTZKW1WQRG1T0aZNG7VSK7XiL1SlNIqaKEpQUlWqkj5CCCmUpECBGMLDDWAwsbF5LTb78u7s7ni9u/O+M/d9T3XuGjsRsslIVzNXd+653+/3+87v932XAEBloSK/QAiBqmlwux2YKQsijGBRDg6KtchBEAYQsUA2lYJCGDzHkTchpg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Vd2x6W7wUu+Q8A/w+34pKwK2kanwAAAABJRU5ErkJggg==" />
162
+ <h1 style="font-weight: 900; margin-bottom: 7px;">
163
+ Waifu Diffusion Demo
164
+ </h1>
165
+ </div>
166
+ <p style="margin-bottom: 10px; font-size: 94%">
167
+ waifu-diffusion is a latent text-to-image diffusion model that has been conditioned on high-quality anime images through fine-tuning
168
+ </p>
169
+ </div>
170
+ """
171
+ )
172
+ with gr.Group():
173
+ with gr.Box():
174
+ with gr.Row().style(mobile_collapse=False, equal_height=True):
175
+
176
+ text = gr.Textbox(
177
+ label="Enter your prompt", show_label=False, max_lines=1
178
+ ).style(
179
+ border=(True, False, True, True),
180
+ rounded=(True, False, False, True),
181
+ container=False,
182
+ )
183
+ btn = gr.Button("Run").style(
184
+ margin=False,
185
+ rounded=(False, True, True, False),
186
+ )
187
+
188
+ gallery = gr.Gallery(label="Generated images", show_label=False, elem_id="generated_id").style(
189
+ grid=[2], height="auto"
190
+ )
191
+
192
+ ex = gr.Examples(examples=examples, fn=infer, inputs=[text], outputs=gallery, cache_examples=True)
193
+ ex.dataset.headers = [""]
194
+
195
+ text.submit(infer, inputs=[text], outputs=gallery)
196
+ btn.click(infer, inputs=[text], outputs=gallery)
197
+
198
+ gr.HTML(
199
+ """
200
+ <div class="footer">
201
+ <p>Stable Diffusion model fine-tuned on 56K anime image board images by <a href="https://huggingface.co/hakurei" style="text-decoration: underline;" target="_blank">hakurei</a>
202
+ </p>
203
+ </div>
204
+ <div class="acknowledgments">
205
+ <p><h4>LICENSE</h4>
206
+ The model is licensed with a <a href="https://huggingface.co/spaces/CompVis/stable-diffusion-license" style="text-decoration: underline;" target="_blank">CreativeML Open RAIL-M</a> license. The authors claim no rights on the outputs you generate, you are free to use them and are accountable for their use which must not go against the provisions set in this license. The license forbids you from sharing any content that violates any laws, produce any harm to a person, disseminate any personal information that would be meant for harm, spread misinformation and target vulnerable groups. For the full list of restrictions please <a href="https://huggingface.co/spaces/CompVis/stable-diffusion-license" target="_blank" style="text-decoration: underline;" target="_blank">read the license</a></p>
207
+ <p><h4>Biases and content acknowledgment</h4>
208
+ Despite how impressive being able to turn text into image is, beware to the fact that this model may output content that reinforces or exacerbates societal biases, as well as realistic faces, pornography and violence. The model was trained on the <a href="https://laion.ai/blog/laion-5b/" style="text-decoration: underline;" target="_blank">LAION-5B dataset</a>, which scraped non-curated image-text-pairs from the internet (the exception being the removal of illegal content) and is meant for research purposes. You can read more in the <a href="https://huggingface.co/CompVis/stable-diffusion-v1-4" style="text-decoration: underline;" target="_blank">model card</a></p>
209
+ </div>
210
+ """
211
+ )
212
+ demo.queue(max_size=25).launch()