Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -132,7 +132,7 @@ def imgur(prompt, img, seed):
|
|
132 |
return link, loglink
|
133 |
|
134 |
sdtries = 0
|
135 |
-
def sd(prompt, negprompt):
|
136 |
if prompt == "":
|
137 |
return Image.open('error.png'), "Error! Please enter a prompt"
|
138 |
|
@@ -151,16 +151,22 @@ def sd(prompt, negprompt):
|
|
151 |
# convert the sdkey from bytes to a string
|
152 |
sdkey = sdkey.decode()
|
153 |
|
|
|
|
|
|
|
|
|
|
|
154 |
# connect to dream API
|
155 |
stability_api = client.StabilityInference(
|
156 |
key = sdkey,
|
157 |
verbose=True,
|
158 |
-
engine=
|
159 |
)
|
160 |
# convert string prompt to lowercase
|
161 |
prompt = prompt.lower()
|
162 |
negprompt = negprompt.lower()
|
163 |
|
|
|
164 |
# set random seed
|
165 |
seed = random.randint(0, 9999999)
|
166 |
|
@@ -192,10 +198,13 @@ def sd(prompt, negprompt):
|
|
192 |
answers = stability_api.generate(
|
193 |
#prompt=prompt,
|
194 |
steps=15,
|
|
|
|
|
195 |
seed=seed,
|
196 |
prompt = [generation.Prompt(text=prompt,parameters=generation.PromptParameters(weight=5)),
|
197 |
generation.Prompt(text=negprompt,parameters=generation.PromptParameters(weight=-5))],
|
198 |
)
|
|
|
199 |
|
200 |
# convert seed to string
|
201 |
seed = str(seed)
|
@@ -233,26 +242,32 @@ def sd(prompt, negprompt):
|
|
233 |
|
234 |
|
235 |
|
236 |
-
examples = [["A hyperrealistic photograph of German architectural modern home in the suburbs of Hamburg, Germany, lens flares, cinematic, hdri, matte painting, concept art, celestial, soft render, highly detailed, cgsociety, octane render, trending on artstation, architectural HD, HQ, 4k, 8k", "tree, bush, woods, branches, leaves, green, forest"],
|
237 |
-
["A
|
238 |
-
["A
|
239 |
-
["A
|
240 |
-
["
|
241 |
-
["A
|
|
|
|
|
242 |
|
243 |
-
with gr.Blocks(
|
244 |
-
*, body, #name, #negprompt, #ex, #article, .border-gray-200, .gr-input, .border-gray-100 { background: #0b0f19; color: white; border-color: #4c4c4c; }
|
245 |
-
.gr-samples-gallery .gr-sample-textbox, #greet_btn, #save_btn, .py-1, .gr-samples-gallery:hover .gr-sample-textbox:hover, .gr-text-input, #output, .wrap.svelte-1c38quw, .h-wrap { background: #1f2937; color: white; border-color: #4c4c4c;}
|
246 |
-
.py-6 {padding-top: 0;}
|
247 |
-
"""
|
248 |
) as demo:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
249 |
download = gr.HTML(elem_id="download")
|
250 |
output = gr.Image(label="Image Generation", elem_id="output")
|
251 |
name = gr.Textbox(label="Prompt", placeholder="Describe the image you want to generate. Longer and more detailed prompts work better.", elem_id="name")
|
252 |
negprompt = gr.Textbox(label="Negative Prompt", placeholder="Describe the image you want to avoid. Longer and more detailed prompts work better.", elem_id="negprompt")
|
253 |
greet_btn = gr.Button("Generate Image", elem_id="greet_btn")
|
254 |
bin = gr.HTML("", visible=False)
|
255 |
-
ex = gr.Examples(examples=examples, fn=sd, inputs=[name, negprompt], outputs=[output, download], cache_examples=
|
256 |
greet_btn.click(
|
257 |
None,
|
258 |
[],
|
@@ -268,7 +283,7 @@ with gr.Blocks(css = """
|
|
268 |
Cookies.set('creations', parseInt(Cookies.get('creations')) + 1, { expires: 250 / 24 / 60 / 60 }); }
|
269 |
console.log(Cookies.get('creations'));
|
270 |
}""")
|
271 |
-
greet_btn.click(fn=sd, inputs=[name, negprompt], outputs=[output, download])
|
272 |
|
273 |
|
274 |
demo.queue(concurrency_count=3, max_size=20).launch(max_threads=150)
|
|
|
132 |
return link, loglink
|
133 |
|
134 |
sdtries = 0
|
135 |
+
def sd(prompt, negprompt, version):
|
136 |
if prompt == "":
|
137 |
return Image.open('error.png'), "Error! Please enter a prompt"
|
138 |
|
|
|
151 |
# convert the sdkey from bytes to a string
|
152 |
sdkey = sdkey.decode()
|
153 |
|
154 |
+
if version == "2.1":
|
155 |
+
engine = "stable-diffusion-512-v2-1"
|
156 |
+
if version == "1.5":
|
157 |
+
engine = "stable-diffusion-v1-5"
|
158 |
+
|
159 |
# connect to dream API
|
160 |
stability_api = client.StabilityInference(
|
161 |
key = sdkey,
|
162 |
verbose=True,
|
163 |
+
engine=engine,
|
164 |
)
|
165 |
# convert string prompt to lowercase
|
166 |
prompt = prompt.lower()
|
167 |
negprompt = negprompt.lower()
|
168 |
|
169 |
+
print(version)
|
170 |
# set random seed
|
171 |
seed = random.randint(0, 9999999)
|
172 |
|
|
|
198 |
answers = stability_api.generate(
|
199 |
#prompt=prompt,
|
200 |
steps=15,
|
201 |
+
sampler=generation.SAMPLER_K_DPMPP_2S_ANCESTRAL,
|
202 |
+
guidance_preset=generation.GUIDANCE_PRESET_FAST_GREEN,
|
203 |
seed=seed,
|
204 |
prompt = [generation.Prompt(text=prompt,parameters=generation.PromptParameters(weight=5)),
|
205 |
generation.Prompt(text=negprompt,parameters=generation.PromptParameters(weight=-5))],
|
206 |
)
|
207 |
+
|
208 |
|
209 |
# convert seed to string
|
210 |
seed = str(seed)
|
|
|
242 |
|
243 |
|
244 |
|
245 |
+
examples = [["A hyperrealistic photograph of German architectural modern home in the suburbs of Hamburg, Germany, lens flares, cinematic, hdri, matte painting, concept art, celestial, soft render, highly detailed, cgsociety, octane render, trending on artstation, architectural HD, HQ, 4k, 8k", "tree, bush, woods, branches, leaves, green, forest", "2.1"],
|
246 |
+
["A dream of a distant galaxy, by Caspar David Friedrich, matte painting trending on artstation HQ", "", "1.5"],
|
247 |
+
["A Hyperrealistic photograph of ancient Malaysian architectural ruins in Borneo's East Malaysia, lens flares, cinematic, hdri, matte painting, concept art, celestial, soft render, highly detailed, cgsociety, octane render, trending on artstation, architectural HD, HQ, 4k, 8k", "", "2.1"],
|
248 |
+
["A dream of a distant galaxy, by Caspar David Friedrich, matte painting trending on artstation HQ", "", "1.5"],
|
249 |
+
["A small cabin on top of a snowy mountain in the style of Disney, artstation", "", "2.1"],
|
250 |
+
["A Hyperrealistic photograph of ancient Tokyo/London/Paris architectural ruins in a flooded apocalypse landscape of dead skyscrapers, lens flares, cinematic, hdri, matte painting, concept art, celestial, soft render, highly detailed, cgsociety, octane render, trending on artstation, architectural HD, HQ, 4k, 8k", "", "2.1"],
|
251 |
+
["a portrait of a beautiful blonde woman, fine - art photography, soft portrait shot 8 k, mid length, ultrarealistic uhd faces, unsplash, kodak ultra max 800, 85 mm, intricate, casual pose, centered symmetrical composition, stunning photos, masterpiece, grainy, centered composition", "blender, cropped, lowres, poorly drawn face, out of frame, poorly drawn hands, blurry, bad art, blurred, text, watermark, disfigured, deformed, closed eyes", "2.1"],
|
252 |
+
["A hyperrealistic painting of an astronaut inside of a massive futuristic metal mechawarehouse, cinematic, sci-fi, lens flares, rays of light, epic, matte painting, concept art, celestial, soft render, octane render, trending on artstation, 4k, 8k", "blender, cropped, lowres, out of frame, blurry, bad art, blurred, text, disfigured, deformed", "2.1"]]
|
253 |
|
254 |
+
with gr.Blocks(
|
|
|
|
|
|
|
|
|
255 |
) as demo:
|
256 |
+
# create radio for to use either v1.5 or v2.0
|
257 |
+
version = gr.Radio(
|
258 |
+
label="Stable Diffusion Version",
|
259 |
+
choices=["1.5", "2.1"],
|
260 |
+
value="1.5",
|
261 |
+
elem_id="version",
|
262 |
+
)
|
263 |
+
|
264 |
download = gr.HTML(elem_id="download")
|
265 |
output = gr.Image(label="Image Generation", elem_id="output")
|
266 |
name = gr.Textbox(label="Prompt", placeholder="Describe the image you want to generate. Longer and more detailed prompts work better.", elem_id="name")
|
267 |
negprompt = gr.Textbox(label="Negative Prompt", placeholder="Describe the image you want to avoid. Longer and more detailed prompts work better.", elem_id="negprompt")
|
268 |
greet_btn = gr.Button("Generate Image", elem_id="greet_btn")
|
269 |
bin = gr.HTML("", visible=False)
|
270 |
+
ex = gr.Examples(examples=examples, fn=sd, inputs=[name, negprompt, version], outputs=[output, download], cache_examples=False)
|
271 |
greet_btn.click(
|
272 |
None,
|
273 |
[],
|
|
|
283 |
Cookies.set('creations', parseInt(Cookies.get('creations')) + 1, { expires: 250 / 24 / 60 / 60 }); }
|
284 |
console.log(Cookies.get('creations'));
|
285 |
}""")
|
286 |
+
greet_btn.click(fn=sd, inputs=[name, negprompt, version], outputs=[output, download])
|
287 |
|
288 |
|
289 |
demo.queue(concurrency_count=3, max_size=20).launch(max_threads=150)
|