Severian commited on
Commit
f45fc1b
·
verified ·
1 Parent(s): dee132c

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +25 -8
app.py CHANGED
@@ -130,16 +130,16 @@ CAPTION_TYPE_MAP = {
130
  ],
131
 
132
  ("style_prompt", "formal", False, False): [
133
- "Analyze this image through the lens of {style} art. Describe how it aligns with or diverges from {style_characteristics}.",
134
- "Examine this artwork in the context of the {style} movement, focusing on {style_focus} and how these elements are represented or reinterpreted in the image."
135
  ],
136
  ("style_prompt", "formal", False, True): [
137
- "Within {word_count} words, compare this image to the {style} style, highlighting elements that reflect or contrast with its key characteristics.",
138
- "Compose a concise {word_count}-word analysis of how this artwork relates to the {style} movement, noting its adherence to or departure from typical {style} elements."
139
  ],
140
  ("style_prompt", "formal", True, False): [
141
- "Write a {length} critique of this image, exploring its relationship to the {style} movement. Discuss composition, technique, and thematic elements in this context.",
142
- "Develop a {length} analysis of how this artwork incorporates or challenges the principles of {style}, considering its visual language and artistic approach."
143
  ],
144
  ("style_prompt", "informal", False, False): [
145
  "Imagine this image is in an exhibition of {style} art. Describe what makes it fit in or stand out from other {style} pieces.",
@@ -291,7 +291,10 @@ def stream_chat(input_image: Image.Image, caption_type: str, caption_tone: str,
291
 
292
  # Add style prompt details if applicable
293
  if caption_type == "style_prompt":
294
- prompt_str += f" Include details about using a {lens_type} lens, {film_stock} film stock, {composition} composition, and {lighting} lighting."
 
 
 
295
 
296
  print(f"Prompt: {prompt_str}")
297
 
@@ -345,6 +348,10 @@ def stream_chat(input_image: Image.Image, caption_type: str, caption_tone: str,
345
 
346
  caption = tokenizer.batch_decode(generate_ids, skip_special_tokens=False, clean_up_tokenization_spaces=False)[0]
347
 
 
 
 
 
348
  return caption.strip()
349
 
350
  css = """
@@ -478,7 +485,17 @@ with gr.Blocks(theme="Hev832/Applio", css=css) as demo:
478
  run_button = gr.Button("Make My Caption!")
479
 
480
  with gr.Column():
481
- output_caption = gr.Textbox(label="Your Amazing Caption Appears Here", lines=10)
 
 
 
 
 
 
 
 
 
 
482
 
483
  run_button.click(fn=stream_chat, inputs=[input_image, caption_type, caption_tone, caption_length, lens_type, film_stock, composition, lighting], outputs=[output_caption])
484
 
 
130
  ],
131
 
132
  ("style_prompt", "formal", False, False): [
133
+ "Generate a detailed stable diffusion prompt to recreate this image, including style, composition, and key elements.",
134
+ "Craft a comprehensive prompt for an AI art generator to produce an image in the same style and mood as this artwork."
135
  ],
136
  ("style_prompt", "formal", False, True): [
137
+ "Within {word_count} words, create a precise stable diffusion prompt capturing the essence of this image.",
138
+ "Compose a concise AI art prompt of {word_count} words to replicate this artwork's style and content."
139
  ],
140
  ("style_prompt", "formal", True, False): [
141
+ "Write a {length} stable diffusion prompt that thoroughly describes this image's style, subject, and artistic techniques.",
142
+ "Develop a {length} detailed prompt for AI art generation, breaking down the key visual elements and artistic approach of this image."
143
  ],
144
  ("style_prompt", "informal", False, False): [
145
  "Imagine this image is in an exhibition of {style} art. Describe what makes it fit in or stand out from other {style} pieces.",
 
291
 
292
  # Add style prompt details if applicable
293
  if caption_type == "style_prompt":
294
+ prompt_str += (f" The prompt should specifically include details about using a {lens_type} lens, "
295
+ f"{film_stock} film stock, {composition} composition, and {lighting} lighting. "
296
+ f"Format the output as a comma-separated list of descriptors and modifiers, "
297
+ f"suitable for direct input into a Stable Diffusion interface.")
298
 
299
  print(f"Prompt: {prompt_str}")
300
 
 
348
 
349
  caption = tokenizer.batch_decode(generate_ids, skip_special_tokens=False, clean_up_tokenization_spaces=False)[0]
350
 
351
+ # For style_prompt, format the output for easy copying into image generation platforms
352
+ if caption_type == "style_prompt":
353
+ caption = "Stable Diffusion Prompt: " + caption.replace("\n", ", ")
354
+
355
  return caption.strip()
356
 
357
  css = """
 
485
  run_button = gr.Button("Make My Caption!")
486
 
487
  with gr.Column():
488
+ output_caption = gr.Textbox(label="Your Image Generation Prompt (Copy this for Stable Diffusion)", lines=10)
489
+
490
+ gr.Markdown("""
491
+ ## How to Use Your Generated Prompt:
492
+ 1. For "Style Prompt" captions, the output is formatted for direct use in Stable Diffusion.
493
+ 2. Simply copy the entire text from the output box.
494
+ 3. Paste it into your preferred Stable Diffusion interface or any other AI image generation platform.
495
+ 4. Adjust or add to the prompt as desired to fine-tune your image generation.
496
+
497
+ Remember, you can always regenerate or modify the prompt to get different results!
498
+ """)
499
 
500
  run_button.click(fn=stream_chat, inputs=[input_image, caption_type, caption_tone, caption_length, lens_type, film_stock, composition, lighting], outputs=[output_caption])
501