andr290606 commited on
Commit
5a3bea7
1 Parent(s): 4fb849b

Init commit

Browse files
Files changed (2) hide show
  1. app.py +203 -0
  2. requirements.txt +8 -0
app.py ADDED
@@ -0,0 +1,203 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ import torch
3
+ from torch import autocast
4
+ from diffusers import StableDiffusionPipeline
5
+
6
+ #model_id = "Deltaadams/Hentai-Diffusion"
7
+ pipe = StableDiffusionPipeline.from_pretrained("Deltaadams/Hentai-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
+ # 'TO'
140
+ # ],
141
+ # [
142
+ # 'DO'
143
+ # ]
144
+ ]
145
+
146
+ with block as demo:
147
+ gr.HTML(
148
+ """
149
+ <div style="text-align: center; max-width: 650px; margin: 0 auto;">
150
+ <div
151
+ style="
152
+ display: inline-flex;
153
+ align-items: center;
154
+ gap: 0.8rem;
155
+ font-size: 1.75rem;
156
+ "
157
+ >
158
+ <!--<img src="data:image/png;base64," />-->
159
+ <h1 style="font-weight: 900; margin-bottom: 7px;">
160
+ Hentai Diffusion Demo
161
+ </h1>
162
+ </div>
163
+ <p style="margin-bottom: 10px; font-size: 94%">
164
+ text-to-image diffusion model based on HD model
165
+ </p>
166
+ </div>
167
+ """
168
+ )
169
+ with gr.Group():
170
+ with gr.Box():
171
+ with gr.Row().style(mobile_collapse=False, equal_height=True):
172
+
173
+ text = gr.Textbox(
174
+ label="Enter your prompt", show_label=False, max_lines=1
175
+ ).style(
176
+ border=(True, False, True, True),
177
+ rounded=(True, False, False, True),
178
+ container=False,
179
+ )
180
+ btn = gr.Button("Run").style(
181
+ margin=False,
182
+ rounded=(False, True, True, False),
183
+ )
184
+
185
+ gallery = gr.Gallery(label="Generated images", show_label=False, elem_id="generated_id").style(
186
+ grid=[2], height="auto"
187
+ )
188
+
189
+ ex = gr.Examples(examples=examples, fn=infer, inputs=[text], outputs=gallery, cache_examples=True)
190
+ ex.dataset.headers = [""]
191
+
192
+ text.submit(infer, inputs=[text], outputs=gallery)
193
+ btn.click(infer, inputs=[text], outputs=gallery)
194
+
195
+ gr.HTML(
196
+ """
197
+ <div class="footer">
198
+ <p>Stable Diffusion model by <a href="https://huggingface.co/Deltaadams" style="text-decoration: underline;" target="_blank">Deltaadams</a>
199
+ </p>
200
+ </div>
201
+ """
202
+ )
203
+ demo.queue(max_size=25).launch()
requirements.txt ADDED
@@ -0,0 +1,8 @@
 
 
 
 
 
 
 
 
 
1
+ --extra-index-url https://download.pytorch.org/whl/cu113
2
+ torch
3
+ diffusers==0.4.1
4
+ huggingface-hub==0.10.0
5
+ nvidia-ml-py3
6
+ transformers==4.22.2
7
+ ftfy
8
+ scipy