ehristoforu commited on
Commit
5d5215f
1 Parent(s): d4d2a1f

Upload 2 files

Browse files
Files changed (2) hide show
  1. app.py +236 -0
  2. requirements.txt +3 -0
app.py ADDED
@@ -0,0 +1,236 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ import requests
3
+ import io
4
+ import random
5
+ import os
6
+ from PIL import Image
7
+
8
+ list_models = [
9
+ "SD-1.4",
10
+ "SD-1.5",
11
+ "SD-2.1",
12
+ "SDXL-1.0",
13
+ "OpenJourney-V4",
14
+ "Midjourney-mini",
15
+ "Dreamshaper-XL-1.0",
16
+ "Protogen-x5.8",
17
+ "WavyFusion",
18
+ "OpenGen",
19
+ "Deliberate",
20
+ "Pixel-Art-XL"
21
+ ]
22
+
23
+ def generate_txt2img(current_model, prompt, is_negative=False, image_style="None style", steps=50, cfg_scale=7,
24
+ seed=None):
25
+
26
+ if current_model == "SD-1.4":
27
+ API_URL = "https://api-inference.huggingface.co/models/CompVis/stable-diffusion-v1-4"
28
+ elif current_model == "SD-1.5":
29
+ API_URL = "https://api-inference.huggingface.co/models/runwayml/stable-diffusion-v1-5"
30
+ elif current_model == "SD-2.1":
31
+ API_URL = "https://api-inference.huggingface.co/models/stabilityai/stable-diffusion-2-1"
32
+ elif current_model == "SDXL-1.0":
33
+ API_URL = "https://api-inference.huggingface.co/models/stabilityai/stable-diffusion-xl-base-1.0"
34
+ elif current_model == "OpenJourney-V4":
35
+ API_URL = "https://api-inference.huggingface.co/models/prompthero/openjourney"
36
+ elif current_model == "Midjourney-mini":
37
+ API_URL = "https://api-inference.huggingface.co/models/openskyml/midjourney-mini"
38
+ elif current_model == "Dreamshaper-XL-1.0":
39
+ API_URL = "https://api-inference.huggingface.co/models/Lykon/dreamshaper-xl-1-0"
40
+ elif current_model == "Protogen-x5.8":
41
+ API_URL = "https://api-inference.huggingface.co/models/darkstorm2150/Protogen_x5.8_Official_Release"
42
+ elif current_model == "WavyFusion":
43
+ API_URL = "https://api-inference.huggingface.co/models/wavymulder/wavyfusion"
44
+ elif current_model == "OpenGen":
45
+ API_URL = "https://api-inference.huggingface.co/models/darkstorm2150/OpenGen"
46
+ elif current_model == "Deliberate":
47
+ API_URL = "https://api-inference.huggingface.co/models/Yntec/Deliberate"
48
+ elif current_model == "Pixel-Art-XL":
49
+ API_URL = "https://api-inference.huggingface.co/models/nerijs/pixel-art-xl"
50
+
51
+
52
+ API_TOKEN = "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"
53
+ headers = {"Authorization": f"Bearer {API_TOKEN}"}
54
+
55
+
56
+ if image_style == "None style":
57
+ payload = {
58
+ "inputs": prompt + ", 8k",
59
+ "is_negative": is_negative,
60
+ "steps": steps,
61
+ "cfg_scale": cfg_scale,
62
+ "seed": seed if seed is not None else random.randint(-1, 2147483647)
63
+ }
64
+ elif image_style == "Cinematic":
65
+ payload = {
66
+ "inputs": prompt + ", realistic, detailed, textured, skin, hair, eyes, by Alex Huguet, Mike Hill, Ian Spriggs, JaeCheol Park, Marek Denko",
67
+ "is_negative": is_negative + ", abstract, cartoon, stylized",
68
+ "steps": steps,
69
+ "cfg_scale": cfg_scale,
70
+ "seed": seed if seed is not None else random.randint(-1, 2147483647)
71
+ }
72
+ elif image_style == "Digital Art":
73
+ payload = {
74
+ "inputs": prompt + ", faded , vintage , nostalgic , by Jose Villa , Elizabeth Messina , Ryan Brenizer , Jonas Peterson , Jasmine Star",
75
+ "is_negative": is_negative + ", sharp , modern , bright",
76
+ "steps": steps,
77
+ "cfg_scale": cfg_scale,
78
+ "seed": seed if seed is not None else random.randint(-1, 2147483647)
79
+ }
80
+ elif image_style == "Portrait":
81
+ payload = {
82
+ "inputs": prompt + ", soft light, sharp, exposure blend, medium shot, bokeh, (hdr:1.4), high contrast, (cinematic, teal and orange:0.85), (muted colors, dim colors, soothing tones:1.3), low saturation, (hyperdetailed:1.2), (noir:0.4), (natural skin texture, hyperrealism, soft light, sharp:1.2)",
83
+ "is_negative": is_negative,
84
+ "steps": steps,
85
+ "cfg_scale": cfg_scale,
86
+ "seed": seed if seed is not None else random.randint(-1, 2147483647)
87
+ }
88
+
89
+ # Вставьте ваш код для запроса к модели и получения изображения
90
+ image_bytes = requests.post(API_URL, headers=headers, json=payload).content
91
+ image = Image.open(io.BytesIO(image_bytes))
92
+ return image
93
+
94
+
95
+ css = """
96
+ .gradio-container {
97
+ font-family: 'IBM Plex Sans', sans-serif;
98
+ }
99
+ .gr-button {
100
+ color: white;
101
+ border-color: black;
102
+ background: black;
103
+ }
104
+ input[type='range'] {
105
+ accent-color: black;
106
+ }
107
+ .dark input[type='range'] {
108
+ accent-color: #dfdfdf;
109
+ }
110
+ .gradio-container {
111
+ max-width: 730px !important;
112
+ margin: auto;
113
+ padding-top: 1.5rem;
114
+ }
115
+ #gallery {
116
+ min-height: 22rem;
117
+ margin-bottom: 15px;
118
+ margin-left: auto;
119
+ margin-right: auto;
120
+ border-bottom-right-radius: .5rem !important;
121
+ border-bottom-left-radius: .5rem !important;
122
+ }
123
+ #gallery>div>.h-full {
124
+ min-height: 20rem;
125
+ }
126
+ .details:hover {
127
+ text-decoration: underline;
128
+ }
129
+ .gr-button {
130
+ white-space: nowrap;
131
+ }
132
+ .gr-button:focus {
133
+ border-color: rgb(147 197 253 / var(--tw-border-opacity));
134
+ outline: none;
135
+ box-shadow: var(--tw-ring-offset-shadow), var(--tw-ring-shadow), var(--tw-shadow, 0 0 #0000);
136
+ --tw-border-opacity: 1;
137
+ --tw-ring-offset-shadow: var(--tw-ring-inset) 0 0 0 var(--tw-ring-offset-width) var(--tw-ring-offset-color);
138
+ --tw-ring-shadow: var(--tw-ring-inset) 0 0 0 calc(3px var(--tw-ring-offset-width)) var(--tw-ring-color);
139
+ --tw-ring-color: rgb(191 219 254 / var(--tw-ring-opacity));
140
+ --tw-ring-opacity: .5;
141
+ }
142
+ #advanced-btn {
143
+ font-size: .7rem !important;
144
+ line-height: 19px;
145
+ margin-top: 12px;
146
+ margin-bottom: 12px;
147
+ padding: 2px 8px;
148
+ border-radius: 14px !important;
149
+ }
150
+ #advanced-options {
151
+ display: none;
152
+ margin-bottom: 20px;
153
+ }
154
+ .footer {
155
+ margin-bottom: 45px;
156
+ margin-top: 35px;
157
+ text-align: center;
158
+ border-bottom: 1px solid #e5e5e5;
159
+ }
160
+ .footer>p {
161
+ font-size: .8rem;
162
+ display: inline-block;
163
+ padding: 0 10px;
164
+ transform: translateY(10px);
165
+ background: white;
166
+ }
167
+ .dark .footer {
168
+ border-color: #303030;
169
+ }
170
+ .dark .footer>p {
171
+ background: #0b0f19;
172
+ }
173
+ .acknowledgments h4{
174
+ margin: 1.25em 0 .25em 0;
175
+ font-weight: bold;
176
+ font-size: 115%;
177
+ }
178
+ .animate-spin {
179
+ animation: spin 1s linear infinite;
180
+ }
181
+ @keyframes spin {
182
+ from {
183
+ transform: rotate(0deg);
184
+ }
185
+ to {
186
+ transform: rotate(360deg);
187
+ }
188
+ }
189
+ #share-btn-container {padding-left: 0.5rem !important; padding-right: 0.5rem !important; background-color: #000000; justify-content: center; align-items: center; border-radius: 9999px !important; max-width: 13rem; margin-left: auto;}
190
+ div#share-btn-container > div {flex-direction: row;background: black;align-items: center}
191
+ #share-btn-container:hover {background-color: #060606}
192
+ #share-btn {all: initial; color: #ffffff;font-weight: 600; cursor:pointer; font-family: 'IBM Plex Sans', sans-serif; margin-left: 0.5rem !important; padding-top: 0.5rem !important; padding-bottom: 0.5rem !important;right:0;}
193
+ #share-btn * {all: unset}
194
+ #share-btn-container div:nth-child(-n+2){width: auto !important;min-height: 0px !important;}
195
+ #share-btn-container .wrap {display: none !important}
196
+ #share-btn-container.hidden {display: none!important}
197
+ .gr-form{
198
+ flex: 1 1 50%; border-top-right-radius: 0; border-bottom-right-radius: 0;
199
+ }
200
+ #prompt-container{
201
+ gap: 0;
202
+ }
203
+ #prompt-container .form{
204
+ border-top-right-radius: 0;
205
+ border-bottom-right-radius: 0;
206
+ }
207
+ #gen-button{
208
+ border-top-left-radius:0;
209
+ border-bottom-left-radius:0;
210
+ }
211
+ #prompt-text-input, #negative-prompt-text-input{padding: .45rem 0.625rem}
212
+ #component-16{border-top-width: 1px!important;margin-top: 1em}
213
+ .image_duplication{position: absolute; width: 100px; left: 50px}
214
+ .tabitem{border: 0 !important}
215
+ """
216
+
217
+ with gr.Blocks(css=css) as sdxl:
218
+ favicon = '<img src="https://www.gstatic.com/android/keyboard/emojikitchen/20201001/u1f917/u1f917_u1f31e.png" width="48px" style="display: inline">'
219
+ gr.Markdown(
220
+ f"""<h1><center>{favicon} HuggingDiffusion</center></h1>
221
+ """
222
+ )
223
+ with gr.Row(elem_id="prompt-container"):
224
+ current_model = gr.Dropdown(label="Current Model", choices=list_models, value=list_models[1])
225
+ with gr.Row(elem_id="prompt-container"):
226
+ text_prompt = gr.Textbox(label="Prompt", placeholder="a cute cat", lines=1, elem_id="prompt-text-input")
227
+ text_button = gr.Button("Generate", variant='primary', elem_id="gen-button")
228
+ with gr.Row():
229
+ image_output = gr.Image(type="pil", label="Output Image", elem_id="gallery")
230
+ with gr.Accordion("Advanced settings", open=False):
231
+ negative_prompt = gr.Textbox(label="Negative Prompt", value="text, blurry, fuzziness", lines=1, elem_id="negative-prompt-text-input")
232
+ image_style = gr.Dropdown(label="Style", choices=["None style", "Cinematic", "Digital Art", "Portrait"], value="None style", allow_custom_value=False)
233
+
234
+ text_button.click(generate_txt2img, inputs=[current_model, text_prompt, negative_prompt, image_style], outputs=image_output)
235
+
236
+ sdxl.launch(show_api=False)
requirements.txt ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ gradio=4.1.1
2
+ requests
3
+ pillow