Spaces:
Runtime error
Runtime error
Commit
Β·
eebc5e9
1
Parent(s):
21b7e4a
Attempt to remove inputs from artbot image function
Browse files
app.py
CHANGED
@@ -181,6 +181,12 @@ for model in model_tags:
|
|
181 |
if model != "ahx-model-1" and model != "ahx-model-2":
|
182 |
DROPDOWNS[model] = f" in the style of <{model}>"
|
183 |
|
|
|
|
|
|
|
|
|
|
|
|
|
184 |
# def image_prompt(prompt, dropdown, guidance, steps, seed, height, width, negative_prompt=""):
|
185 |
def image_prompt(prompt, guidance, steps, seed, height, width, negative_prompt=""):
|
186 |
# prompt = prompt + DROPDOWNS[dropdown]
|
@@ -215,6 +221,62 @@ def image_prompt(prompt, guidance, steps, seed, height, width, negative_prompt="
|
|
215 |
f"Prompt violates Hugging Face's Terms of Service"
|
216 |
)
|
217 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
218 |
def default_guidance():
|
219 |
return 7.5
|
220 |
|
@@ -436,19 +498,12 @@ with gr.Blocks(css=".gradio-container {max-width: 650px}") as artbot_1:
|
|
436 |
# size_dropdown = gr.Dropdown(['square', 'portrait', 'landscape'], label="choose size...")
|
437 |
# prompt = gr.Textbox(label="image prompt...", elem_id="input-text")
|
438 |
|
439 |
-
all_models = [dropdown for dropdown in list(DROPDOWNS) if 'ahx-' in dropdown]
|
440 |
-
model_1 = random.choice(all_models)
|
441 |
-
model_2 = random.choice(all_models)
|
442 |
-
|
443 |
-
prompt = f"{model_1} {model_2}"
|
444 |
-
|
445 |
-
seed = random_seed()
|
446 |
|
447 |
go_button = gr.Button("generate image", elem_id="go-button")
|
448 |
output = gr.Image(elem_id="output-image")
|
449 |
output_text = gr.Text(elem_id="output-text")
|
450 |
# go_button.click(fn=simple_image_prompt, inputs=[prompt, dropdown, size_dropdown], outputs=[output, output_text])
|
451 |
-
go_button.click(fn=
|
452 |
|
453 |
|
454 |
|
|
|
181 |
if model != "ahx-model-1" and model != "ahx-model-2":
|
182 |
DROPDOWNS[model] = f" in the style of <{model}>"
|
183 |
|
184 |
+
TOKENS = []
|
185 |
+
|
186 |
+
for model in model_tags:
|
187 |
+
if model != "ahx-model-1" and model != "ahx-model-2":
|
188 |
+
TOKENS.append(f"<{model}>")
|
189 |
+
|
190 |
# def image_prompt(prompt, dropdown, guidance, steps, seed, height, width, negative_prompt=""):
|
191 |
def image_prompt(prompt, guidance, steps, seed, height, width, negative_prompt=""):
|
192 |
# prompt = prompt + DROPDOWNS[dropdown]
|
|
|
221 |
f"Prompt violates Hugging Face's Terms of Service"
|
222 |
)
|
223 |
|
224 |
+
|
225 |
+
# New ArtBot image function -------------------------------------------------
|
226 |
+
# def image_prompt(prompt, dropdown, guidance, steps, seed, height, width, negative_prompt=""):
|
227 |
+
# def artbot_image(prompt, guidance, steps, seed, height, width, negative_prompt=""):
|
228 |
+
def artbot_image():
|
229 |
+
guidance = 7.5
|
230 |
+
steps = 30
|
231 |
+
height = 768
|
232 |
+
width = 768
|
233 |
+
negative_prompt = ""
|
234 |
+
|
235 |
+
all_models = [token for token in TOKENS if 'ahx-' in token]
|
236 |
+
model_1 = random.choice(all_models)
|
237 |
+
model_2 = random.choice(all_models)
|
238 |
+
|
239 |
+
prompt = f"{model_1} {model_2}"
|
240 |
+
|
241 |
+
seed = random_seed()
|
242 |
+
|
243 |
+
|
244 |
+
square_pixels = height * width
|
245 |
+
if square_pixels > 640000:
|
246 |
+
height = 640000 // width
|
247 |
+
generator = torch.Generator(device="cuda").manual_seed(int(seed))
|
248 |
+
|
249 |
+
height=int((height // 8) * 8)
|
250 |
+
width=int((width // 8) * 8)
|
251 |
+
|
252 |
+
# image_count += 1
|
253 |
+
curr_time = datetime.datetime.now()
|
254 |
+
|
255 |
+
is_clean = check_prompt(prompt)
|
256 |
+
|
257 |
+
print("----- advanced tab prompt ------------------------------")
|
258 |
+
print(f"prompt: {prompt}, size: {width}px x {height}px, guidance: {guidance}, steps: {steps}, seed: {int(seed)}")
|
259 |
+
# print(f"image_count: {image_count}, datetime: `{e}`")
|
260 |
+
print(f"datetime: `{curr_time}`")
|
261 |
+
print(f"is_prompt_clean: {is_clean}")
|
262 |
+
print("-------------------------------------------------------")
|
263 |
+
|
264 |
+
if is_clean:
|
265 |
+
return (
|
266 |
+
pipe(prompt=prompt, guidance_scale=guidance, num_inference_steps=steps, generator=generator, height=height, width=width, negative_prompt=negative_prompt).images[0],
|
267 |
+
f"prompt: '{prompt}', seed = {int(seed)},\nheight: {height}px, width: {width}px,\nguidance: {guidance}, steps: {steps}, negative prompt: {negative_prompt}"
|
268 |
+
)
|
269 |
+
else:
|
270 |
+
return (
|
271 |
+
pipe(prompt="", guidance_scale=0, num_inference_steps=1, generator=generator, height=32, width=32).images[0],
|
272 |
+
f"Prompt violates Hugging Face's Terms of Service"
|
273 |
+
)
|
274 |
+
|
275 |
+
|
276 |
+
|
277 |
+
|
278 |
+
|
279 |
+
|
280 |
def default_guidance():
|
281 |
return 7.5
|
282 |
|
|
|
498 |
# size_dropdown = gr.Dropdown(['square', 'portrait', 'landscape'], label="choose size...")
|
499 |
# prompt = gr.Textbox(label="image prompt...", elem_id="input-text")
|
500 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
501 |
|
502 |
go_button = gr.Button("generate image", elem_id="go-button")
|
503 |
output = gr.Image(elem_id="output-image")
|
504 |
output_text = gr.Text(elem_id="output-text")
|
505 |
# go_button.click(fn=simple_image_prompt, inputs=[prompt, dropdown, size_dropdown], outputs=[output, output_text])
|
506 |
+
go_button.click(fn=artbot_image, inputs=[], outputs=[output, output_text])
|
507 |
|
508 |
|
509 |
|