Artvik commited on
Commit
3345f59
1 Parent(s): daf0899

Delete App

Browse files
Files changed (1) hide show
  1. App +0 -288
App DELETED
@@ -1,288 +0,0 @@
1
- import gradio as gr
2
-
3
- import torch
4
- from torch import autocast
5
- from diffusers import StableDiffusionPipeline
6
- from datasets import load_dataset
7
- from PIL import Image
8
- import re
9
-
10
- model_id = "CompVis/stable-diffusion-v1-4"
11
- device = "cuda"
12
-
13
- #If you are running this code locally, you need to either do a 'huggingface-cli login` or paste your User Access Token from here https://huggingface.co/settings/tokens into the use_auth_token field below.
14
- pipe = StableDiffusionPipeline.from_pretrained(model_id, use_auth_token="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", torch_dtype=torch.float16)
15
- pipe = pipe.to(device)
16
-
17
- def infer(prompt, samples, steps, scale, seed):
18
- #When running locally you can also remove this filter
19
- generator = torch.Generator(device=device).manual_seed(seed)
20
-
21
- #If you are running locally with CPU, you can remove the `with autocast("cuda")`
22
- images = []
23
- safe_image = Image.open(r"unsafe.png")
24
- for i, image in enumerate(images_list["sample"]):
25
- if(images_list["nsfw_content_detected"][i]):
26
- images.append(safe_image)
27
- else:
28
- images.append(image)
29
- return images
30
-
31
- css = """
32
- .gradio-container {
33
- font-family: 'IBM Plex Sans', sans-serif;
34
- }
35
- .gr-button {
36
- color: white;
37
- border-color: black;
38
- background: black;
39
- }
40
- input[type='range'] {
41
- accent-color: black;
42
- }
43
- .dark input[type='range'] {
44
- accent-color: #dfdfdf;
45
- }
46
- .container {
47
- max-width: 730px;
48
- margin: auto;
49
- padding-top: 1.5rem;
50
- }
51
- #gallery {
52
- min-height: 22rem;
53
- margin-bottom: 15px;
54
- margin-left: auto;
55
- margin-right: auto;
56
- border-bottom-right-radius: .5rem !important;
57
- border-bottom-left-radius: .5rem !important;
58
- }
59
- #gallery>div>.h-full {
60
- min-height: 20rem;
61
- }
62
- .details:hover {
63
- text-decoration: underline;
64
- }
65
- .gr-button {
66
- white-space: nowrap;
67
- }
68
- .gr-button:focus {
69
- border-color: rgb(147 197 253 / var(--tw-border-opacity));
70
- outline: none;
71
- box-shadow: var(--tw-ring-offset-shadow), var(--tw-ring-shadow), var(--tw-shadow, 0 0 #0000);
72
- --tw-border-opacity: 1;
73
- --tw-ring-offset-shadow: var(--tw-ring-inset) 0 0 0 var(--tw-ring-offset-width) var(--tw-ring-offset-color);
74
- --tw-ring-shadow: var(--tw-ring-inset) 0 0 0 calc(3px var(--tw-ring-offset-width)) var(--tw-ring-color);
75
- --tw-ring-color: rgb(191 219 254 / var(--tw-ring-opacity));
76
- --tw-ring-opacity: .5;
77
- }
78
- #advanced-btn {
79
- font-size: .7rem !important;
80
- line-height: 19px;
81
- margin-top: 12px;
82
- margin-bottom: 12px;
83
- padding: 2px 8px;
84
- border-radius: 14px !important;
85
- }
86
- #advanced-options {
87
- display: none;
88
- margin-bottom: 20px;
89
- }
90
- .footer {
91
- margin-bottom: 45px;
92
- margin-top: 35px;
93
- text-align: center;
94
- border-bottom: 1px solid #e5e5e5;
95
- }
96
- .footer>p {
97
- font-size: .8rem;
98
- display: inline-block;
99
- padding: 0 10px;
100
- transform: translateY(10px);
101
- background: white;
102
- }
103
- .dark .footer {
104
- border-color: #303030;
105
- }
106
- .dark .footer>p {
107
- background: #0b0f19;
108
- }
109
- .acknowledgments h4{
110
- margin: 1.25em 0 .25em 0;
111
- font-weight: bold;
112
- font-size: 115%;
113
- }
114
- """
115
-
116
- block = gr.Blocks(css=css)
117
-
118
- examples = [
119
- [
120
- 'A high tech solarpunk utopia in the Amazon rainforest',
121
- 4,
122
- 45,
123
- 7.5,
124
- 1024,
125
- ],
126
- [
127
- 'A pikachu fine dining with a view to the Eiffel Tower',
128
- 4,
129
- 45,
130
- 7,
131
- 1024,
132
- ],
133
- [
134
- 'A mecha robot in a favela in expressionist style',
135
- 4,
136
- 45,
137
- 7,
138
- 1024,
139
- ],
140
- [
141
- 'an insect robot preparing a delicious meal',
142
- 4,
143
- 45,
144
- 7,
145
- 1024,
146
- ],
147
- [
148
- "A small cabin on top of a snowy mountain in the style of Disney, artstation",
149
- 4,
150
- 45,
151
- 7,
152
- 1024,
153
- ],
154
- ]
155
-
156
- with block:
157
- gr.HTML(
158
- """
159
- <div style="text-align: center; max-width: 650px; margin: 0 auto;">
160
- <div
161
- style="
162
- display: inline-flex;
163
- align-items: center;
164
- gap: 0.8rem;
165
- font-size: 1.75rem;
166
- "
167
- >
168
- <svg
169
- width="0.65em"
170
- height="0.65em"
171
- viewBox="0 0 115 115"
172
- fill="none"
173
- xmlns="http://www.w3.org/2000/svg"
174
- >
175
- <rect width="23" height="23" fill="white"></rect>
176
- <rect y="69" width="23" height="23" fill="white"></rect>
177
- <rect x="23" width="23" height="23" fill="#AEAEAE"></rect>
178
- <rect x="23" y="69" width="23" height="23" fill="#AEAEAE"></rect>
179
- <rect x="46" width="23" height="23" fill="white"></rect>
180
- <rect x="46" y="69" width="23" height="23" fill="white"></rect>
181
- <rect x="69" width="23" height="23" fill="black"></rect>
182
- <rect x="69" y="69" width="23" height="23" fill="black"></rect>
183
- <rect x="92" width="23" height="23" fill="#D9D9D9"></rect>
184
- <rect x="92" y="69" width="23" height="23" fill="#AEAEAE"></rect>
185
- <rect x="115" y="46" width="23" height="23" fill="white"></rect>
186
- <rect x="115" y="115" width="23" height="23" fill="white"></rect>
187
- <rect x="115" y="69" width="23" height="23" fill="#D9D9D9"></rect>
188
- <rect x="92" y="46" width="23" height="23" fill="#AEAEAE"></rect>
189
- <rect x="92" y="115" width="23" height="23" fill="#AEAEAE"></rect>
190
- <rect x="92" y="69" width="23" height="23" fill="white"></rect>
191
- <rect x="69" y="46" width="23" height="23" fill="white"></rect>
192
- <rect x="69" y="115" width="23" height="23" fill="white"></rect>
193
- <rect x="69" y="69" width="23" height="23" fill="#D9D9D9"></rect>
194
- <rect x="46" y="46" width="23" height="23" fill="black"></rect>
195
- <rect x="46" y="115" width="23" height="23" fill="black"></rect>
196
- <rect x="46" y="69" width="23" height="23" fill="black"></rect>
197
- <rect x="23" y="46" width="23" height="23" fill="#D9D9D9"></rect>
198
- <rect x="23" y="115" width="23" height="23" fill="#AEAEAE"></rect>
199
- <rect x="23" y="69" width="23" height="23" fill="black"></rect>
200
- </svg>
201
- <h1 style="font-weight: 900; margin-bottom: 7px;">
202
- Stable Diffusion Demo
203
- </h1>
204
- </div>
205
- <p style="margin-bottom: 10px; font-size: 94%">
206
- Stable Diffusion is a state of the art text-to-image model that generates
207
- images from text.<br>For faster generation and forthcoming API
208
- access you can try
209
- <a
210
- href="http://beta.dreamstudio.ai/"
211
- style="text-decoration: underline;"
212
- target="_blank"
213
- >DreamStudio Beta</a
214
- >
215
- </p>
216
- </div>
217
- """
218
- )
219
- with gr.Group():
220
- with gr.Box():
221
- with gr.Row().style(mobile_collapse=False, equal_height=True):
222
- text = gr.Textbox(
223
- label="Enter your prompt",
224
- show_label=False,
225
- max_lines=1,
226
- placeholder="Enter your prompt",
227
- ).style(
228
- border=(True, False, True, True),
229
- rounded=(True, False, False, True),
230
- container=False,
231
- )
232
- btn = gr.Button("Generate image").style(
233
- margin=False,
234
- rounded=(False, True, True, False),
235
- )
236
-
237
- gallery = gr.Gallery(
238
- label="Generated images", show_label=False, elem_id="gallery"
239
- ).style(grid=[2], height="auto")
240
-
241
- advanced_button = gr.Button("Advanced options", elem_id="advanced-btn")
242
-
243
- with gr.Row(elem_id="advanced-options"):
244
- samples = gr.Slider(label="Images", minimum=1, maximum=4, value=4, step=1)
245
- steps = gr.Slider(label="Steps", minimum=1, maximum=50, value=45, step=1)
246
- scale = gr.Slider(
247
- label="Guidance Scale", minimum=0, maximum=50, value=7.5, step=0.1
248
- )
249
- seed = gr.Slider(
250
- label="Seed",
251
- minimum=0,
252
- maximum=2147483647,
253
- step=1,
254
- randomize=True,
255
- )
256
-
257
- ex = gr.Examples(examples=examples, fn=infer, inputs=[text, samples, steps, scale, seed], outputs=gallery, cache_examples=True)
258
- ex.dataset.headers = [""]
259
-
260
-
261
- text.submit(infer, inputs=[text, samples, steps, scale, seed], outputs=gallery)
262
- btn.click(infer, inputs=[text, samples, steps, scale, seed], outputs=gallery)
263
- advanced_button.click(
264
- None,
265
- [],
266
- text,
267
- _js="""
268
- () => {
269
- const options = document.querySelector("body > gradio-app").querySelector("#advanced-options");
270
- options.style.display = ["none", ""].includes(options.style.display) ? "flex" : "none";
271
- }""",
272
- )
273
- gr.HTML(
274
- """
275
- <div class="footer">
276
- <p>Model by <a href="https://huggingface.co/CompVis" style="text-decoration: underline;" target="_blank">CompVis</a> and <a href="https://huggingface.co/stabilityai" style="text-decoration: underline;" target="_blank">Stability AI</a> - Gradio Demo by 🤗 Hugging Face
277
- </p>
278
- </div>
279
- <div class="acknowledgments">
280
- <p><h4>LICENSE</h4>
281
- 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>
282
- <p><h4>Biases and content acknowledgment</h4>
283
- 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>
284
- </div>
285
- """
286
- )
287
-
288
- block.queue(max_size=25).launch()