Spaces:
Running
on
Zero
Running
on
Zero
Upload prompt.py
Browse files
prompt.py
CHANGED
@@ -322,7 +322,7 @@ import os
|
|
322 |
class HuggingFaceInferenceNode:
|
323 |
|
324 |
def __init__(self):
|
325 |
-
self.client = InferenceClient("meta-llama/Meta-Llama-3.1-70B-Instruct")
|
326 |
self.prompts_dir = "./prompts"
|
327 |
os.makedirs(self.prompts_dir, exist_ok=True)
|
328 |
|
@@ -379,7 +379,7 @@ You are allowed to make up film and branding names, and do them like 80's, 90's
|
|
379 |
{"role": "user", "content": user_message}
|
380 |
]
|
381 |
|
382 |
-
response = self.client.chat_completion(
|
383 |
model="meta-llama/Meta-Llama-3.1-70B-Instruct",
|
384 |
max_tokens=1024,
|
385 |
temperature=0.7,
|
@@ -412,160 +412,6 @@ pg_title = """<h1 align="center">FLUX Prompt Generator</h1>
|
|
412 |
</center></p>
|
413 |
"""
|
414 |
|
415 |
-
def create_interface():
|
416 |
-
prompt_generator = PromptGenerator()
|
417 |
-
huggingface_node = HuggingFaceInferenceNode()
|
418 |
-
|
419 |
-
with gr.Blocks(theme='bethecloud/storj_theme') as demo:
|
420 |
-
|
421 |
-
gr.HTML(pg_title)
|
422 |
-
|
423 |
-
with gr.Row():
|
424 |
-
with gr.Column(scale=2):
|
425 |
-
with gr.Accordion("Basic Settings"):
|
426 |
-
pg_seed = gr.Slider(0, 30000, label='Seed', step=1, value=random.randint(0,30000))
|
427 |
-
pg_custom = gr.Textbox(label="Custom Input Prompt (optional)")
|
428 |
-
pg_subject = gr.Textbox(label="Subject (optional)")
|
429 |
-
|
430 |
-
# Add the radio button for global option selection
|
431 |
-
pg_global_option = gr.Radio(
|
432 |
-
["Disabled", "Random", "No Figure Rand"],
|
433 |
-
label="Set all options to:",
|
434 |
-
value="Disabled"
|
435 |
-
)
|
436 |
-
|
437 |
-
with gr.Accordion("Artform and Photo Type", open=False):
|
438 |
-
pg_artform = gr.Dropdown(["disabled", "random"] + ARTFORM, label="Artform", value="disabled")
|
439 |
-
pg_photo_type = gr.Dropdown(["disabled", "random"] + PHOTO_TYPE, label="Photo Type", value="disabled")
|
440 |
-
|
441 |
-
with gr.Accordion("Character Details", open=False):
|
442 |
-
pg_body_types = gr.Dropdown(["disabled", "random"] + BODY_TYPES, label="Body Types", value="disabled")
|
443 |
-
pg_default_tags = gr.Dropdown(["disabled", "random"] + DEFAULT_TAGS, label="Default Tags", value="disabled")
|
444 |
-
pg_roles = gr.Dropdown(["disabled", "random"] + ROLES, label="Roles", value="disabled")
|
445 |
-
pg_hairstyles = gr.Dropdown(["disabled", "random"] + HAIRSTYLES, label="Hairstyles", value="disabled")
|
446 |
-
pg_clothing = gr.Dropdown(["disabled", "random"] + CLOTHING, label="Clothing", value="disabled")
|
447 |
-
|
448 |
-
with gr.Accordion("Scene Details", open=False):
|
449 |
-
pg_place = gr.Dropdown(["disabled", "random"] + PLACE, label="Place", value="disabled")
|
450 |
-
pg_lighting = gr.Dropdown(["disabled", "random"] + LIGHTING, label="Lighting", value="disabled")
|
451 |
-
pg_composition = gr.Dropdown(["disabled", "random"] + COMPOSITION, label="Composition", value="disabled")
|
452 |
-
pg_pose = gr.Dropdown(["disabled", "random"] + POSE, label="Pose", value="disabled")
|
453 |
-
pg_background = gr.Dropdown(["disabled", "random"] + BACKGROUND, label="Background", value="disabled")
|
454 |
-
|
455 |
-
with gr.Accordion("Style and Artist", open=False):
|
456 |
-
pg_additional_details = gr.Dropdown(["disabled", "random"] + ADDITIONAL_DETAILS, label="Additional Details", value="disabled")
|
457 |
-
pg_photography_styles = gr.Dropdown(["disabled", "random"] + PHOTOGRAPHY_STYLES, label="Photography Styles", value="disabled")
|
458 |
-
pg_device = gr.Dropdown(["disabled", "random"] + DEVICE, label="Device", value="disabled")
|
459 |
-
pg_photographer = gr.Dropdown(["disabled", "random"] + PHOTOGRAPHER, label="Photographer", value="disabled")
|
460 |
-
pg_artist = gr.Dropdown(["disabled", "random"] + ARTIST, label="Artist", value="disabled")
|
461 |
-
pg_digital_artform = gr.Dropdown(["disabled", "random"] + DIGITAL_ARTFORM, label="Digital Artform", value="disabled")
|
462 |
-
|
463 |
-
pg_generate_button = gr.Button("Generate Prompt")
|
464 |
-
|
465 |
-
with gr.Column(scale=2):
|
466 |
-
with gr.Accordion("Image and Caption", open=False):
|
467 |
-
pg_input_image = gr.Image(label="Input Image (optional)")
|
468 |
-
pg_caption_output = gr.Textbox(label="Generated Caption", lines=3)
|
469 |
-
pg_create_caption_button = gr.Button("Create Caption")
|
470 |
-
pg_add_caption_button = gr.Button("Add Caption to Prompt")
|
471 |
-
|
472 |
-
with gr.Accordion("Prompt Generation", open=True):
|
473 |
-
pg_output = gr.Textbox(label="Generated Prompt / Input Text", lines=4)
|
474 |
-
pg_t5xxl_output = gr.Textbox(label="T5XXL Output", visible=True)
|
475 |
-
pg_clip_l_output = gr.Textbox(label="CLIP L Output", visible=True)
|
476 |
-
pg_clip_g_output = gr.Textbox(label="CLIP G Output", visible=True)
|
477 |
-
|
478 |
-
with gr.Column(scale=2):
|
479 |
-
with gr.Accordion("Prompt Generation with LLM", open=False):
|
480 |
-
pg_model = gr.Dropdown(["Mixtral", "Mistral", "Llama 3", "Mistral-Nemo"], label="Model", value="Llama 3")
|
481 |
-
pg_happy_talk = gr.Checkbox(label="Happy Talk", value=True)
|
482 |
-
pg_compress = gr.Checkbox(label="Compress", value=True)
|
483 |
-
pg_compression_level = gr.Radio(["soft", "medium", "hard"], label="Compression Level", value="hard")
|
484 |
-
pg_poster = gr.Checkbox(label="Poster", value=False)
|
485 |
-
pg_custom_base_prompt = gr.Textbox(label="Custom Base Prompt", lines=5)
|
486 |
-
pg_generate_text_button = gr.Button("Generate Prompt with LLM")
|
487 |
-
pg_text_output = gr.Textbox(label="Generated Text", lines=10)
|
488 |
-
|
489 |
-
def create_caption(image):
|
490 |
-
if image is not None:
|
491 |
-
return florence_caption(image)
|
492 |
-
return ""
|
493 |
-
|
494 |
-
pg_create_caption_button.click(
|
495 |
-
create_caption,
|
496 |
-
inputs=[pg_input_image],
|
497 |
-
outputs=[pg_caption_output]
|
498 |
-
)
|
499 |
-
|
500 |
-
pg_generate_button.click(
|
501 |
-
prompt_generator.generate_prompt,
|
502 |
-
inputs=[pg_seed, pg_custom, pg_subject, pg_artform, pg_photo_type, pg_body_types,
|
503 |
-
pg_default_tags, pg_roles, pg_hairstyles,
|
504 |
-
pg_additional_details, pg_photography_styles, pg_device, pg_photographer,
|
505 |
-
pg_artist, pg_digital_artform,
|
506 |
-
pg_place, pg_lighting, pg_clothing, pg_composition, pg_pose, pg_background],
|
507 |
-
outputs=[pg_output, gr.Number(visible=False), pg_t5xxl_output, pg_clip_l_output, pg_clip_g_output]
|
508 |
-
)
|
509 |
-
|
510 |
-
pg_add_caption_button.click(
|
511 |
-
prompt_generator.add_caption_to_prompt,
|
512 |
-
inputs=[pg_output, pg_caption_output],
|
513 |
-
outputs=[pg_output]
|
514 |
-
)
|
515 |
-
|
516 |
-
pg_generate_text_button.click(
|
517 |
-
huggingface_node.generate,
|
518 |
-
inputs=[pg_model, pg_output, pg_happy_talk, pg_compress, pg_compression_level,
|
519 |
-
pg_poster, pg_custom_base_prompt],
|
520 |
-
outputs=pg_text_output
|
521 |
-
)
|
522 |
-
|
523 |
-
def update_all_options(choice):
|
524 |
-
updates = {}
|
525 |
-
if choice == "Disabled":
|
526 |
-
for dropdown in [
|
527 |
-
pg_artform, pg_photo_type, pg_body_types, pg_default_tags,
|
528 |
-
pg_roles, pg_hairstyles, pg_clothing,
|
529 |
-
pg_place, pg_lighting, pg_composition, pg_pose, pg_background, pg_additional_details,
|
530 |
-
pg_photography_styles, pg_device, pg_photographer, pg_artist, pg_digital_artform
|
531 |
-
]:
|
532 |
-
updates[dropdown] = gr.update(value="disabled")
|
533 |
-
elif choice == "Random":
|
534 |
-
for dropdown in [
|
535 |
-
pg_artform, pg_photo_type, pg_body_types, pg_default_tags,
|
536 |
-
pg_roles, pg_hairstyles, pg_clothing,
|
537 |
-
pg_place, pg_lighting, pg_composition, pg_pose, pg_background, pg_additional_details,
|
538 |
-
pg_photography_styles, pg_device, pg_photographer, pg_artist, pg_digital_artform
|
539 |
-
]:
|
540 |
-
updates[dropdown] = gr.update(value="random")
|
541 |
-
else: # No Figure Random
|
542 |
-
for dropdown in [pg_photo_type, pg_body_types, pg_default_tags,
|
543 |
-
pg_roles, pg_hairstyles, pg_clothing, pg_pose, pg_additional_details]:
|
544 |
-
updates[dropdown] = gr.update(value="disabled")
|
545 |
-
for dropdown in [pg_artform, pg_place, pg_lighting, pg_composition,
|
546 |
-
pg_background, pg_photography_styles, pg_device, pg_photographer,
|
547 |
-
pg_artist, pg_digital_artform]:
|
548 |
-
updates[dropdown] = gr.update(value="random")
|
549 |
-
return updates
|
550 |
-
|
551 |
-
pg_global_option.change(
|
552 |
-
update_all_options,
|
553 |
-
inputs=[pg_global_option],
|
554 |
-
outputs=[
|
555 |
-
pg_artform, pg_photo_type, pg_body_types, pg_default_tags,
|
556 |
-
pg_roles, pg_hairstyles, pg_clothing,
|
557 |
-
pg_place, pg_lighting, pg_composition, pg_pose, pg_background, pg_additional_details,
|
558 |
-
pg_photography_styles, pg_device, pg_photographer, pg_artist, pg_digital_artform
|
559 |
-
]
|
560 |
-
)
|
561 |
-
|
562 |
-
return demo
|
563 |
-
|
564 |
-
if __name__ == "__main__":
|
565 |
-
demo = create_interface()
|
566 |
-
demo.launch()
|
567 |
-
|
568 |
-
|
569 |
def create_interface():
|
570 |
prompt_generator = PromptGenerator()
|
571 |
huggingface_node = HuggingFaceInferenceNode()
|
@@ -717,4 +563,4 @@ def create_interface():
|
|
717 |
|
718 |
if __name__ == "__main__":
|
719 |
demo = create_interface()
|
720 |
-
demo.launch()
|
|
|
322 |
class HuggingFaceInferenceNode:
|
323 |
|
324 |
def __init__(self):
|
325 |
+
self.client = InferenceClient("meta-llama/Meta-Llama-3.1-70B-Instruct") #
|
326 |
self.prompts_dir = "./prompts"
|
327 |
os.makedirs(self.prompts_dir, exist_ok=True)
|
328 |
|
|
|
379 |
{"role": "user", "content": user_message}
|
380 |
]
|
381 |
|
382 |
+
response = self.client.chat_completion( #
|
383 |
model="meta-llama/Meta-Llama-3.1-70B-Instruct",
|
384 |
max_tokens=1024,
|
385 |
temperature=0.7,
|
|
|
412 |
</center></p>
|
413 |
"""
|
414 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
415 |
def create_interface():
|
416 |
prompt_generator = PromptGenerator()
|
417 |
huggingface_node = HuggingFaceInferenceNode()
|
|
|
563 |
|
564 |
if __name__ == "__main__":
|
565 |
demo = create_interface()
|
566 |
+
demo.launch()
|