fancyfeast commited on
Commit
40e61c6
·
1 Parent(s): 27c9477

Update the modes. Add more Extras. Work on usage guide.

Browse files
Files changed (1) hide show
  1. app.py +121 -17
app.py CHANGED
@@ -8,10 +8,91 @@ from typing import Generator
8
 
9
 
10
  MODEL_PATH = "fancyfeast/llama-joycaption-beta-one-hf-llava"
11
- TITLE = "<h1><center>JoyCaption Beta One - (2025-05-10a)</center></h1>JoyCaption is an image captioning model"
 
 
 
 
 
 
 
 
 
 
 
 
 
12
  DESCRIPTION = """
13
  <div>
14
- <p></p>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
15
  <p>🚨🚨🚨 If the "Help improve JoyCaption" box is checked, the _text_ query you write will be logged and I _might_ use it to help improve JoyCaption.
16
  It does not log images, user data, etc; only the text query. I cannot see what images you send, and frankly, I don't want to. But knowing what kinds of instructions
17
  and queries users want JoyCaption to handle will help guide me in building JoyCaption's dataset. This dataset will be made public. As always, the model itself is completely
@@ -19,33 +100,46 @@ public and free to use outside of this space. And, of course, I have no control
19
  </div>
20
  """
21
 
22
- PLACEHOLDER = """
23
- """
24
  CAPTION_TYPE_MAP = {
25
  "Descriptive": [
26
- "Write a descriptive caption for this image in a formal tone.",
27
- "Write a descriptive caption for this image in a formal tone within {word_count} words.",
28
- "Write a {length} descriptive caption for this image in a formal tone.",
29
  ],
30
- "Descriptive (Informal)": [
31
  "Write a descriptive caption for this image in a casual tone.",
32
  "Write a descriptive caption for this image in a casual tone within {word_count} words.",
33
  "Write a {length} descriptive caption for this image in a casual tone.",
34
  ],
 
 
 
 
 
35
  "Stable Diffusion Prompt": [
36
- "Write a stable diffusion prompt for this image.",
37
- "Write a stable diffusion prompt for this image within {word_count} words.",
38
- "Write a {length} stable diffusion prompt for this image.",
39
  ],
40
  "MidJourney": [
41
  "Write a MidJourney prompt for this image.",
42
  "Write a MidJourney prompt for this image within {word_count} words.",
43
  "Write a {length} MidJourney prompt for this image.",
44
  ],
45
- "Booru tag list": [
46
- "Write a list of Booru tags for this image.",
47
- "Write a list of Booru tags for this image within {word_count} words.",
48
- "Write a {length} list of Booru tags for this image.",
 
 
 
 
 
 
 
 
 
 
49
  ],
50
  "Booru-like tag list": [
51
  "Write a list of Booru-like tags for this image.",
@@ -158,7 +252,7 @@ with gr.Blocks() as demo:
158
 
159
  with gr.Row():
160
  with gr.Column():
161
- input_image = gr.Image(type="pil", label="Input Image")
162
 
163
  caption_type = gr.Dropdown(
164
  choices=list(CAPTION_TYPE_MAP.keys()),
@@ -191,7 +285,17 @@ with gr.Blocks() as demo:
191
  "If applicable, mention the likely use of artificial or natural lighting sources.",
192
  "Do NOT use any ambiguous language.",
193
  "Include whether the image is sfw, suggestive, or nsfw.",
194
- "ONLY describe the most important elements of the image."
 
 
 
 
 
 
 
 
 
 
195
  ],
196
  label="Extra Options"
197
  )
 
8
 
9
 
10
  MODEL_PATH = "fancyfeast/llama-joycaption-beta-one-hf-llava"
11
+ TITLE = """<style>
12
+ .joy-header {display:flex; align-items:center; justify-content:center;
13
+ gap:16px; margin:4px 0 12px;}
14
+ .joy-header h1{margin:0; font-size:1.9rem; line-height:1.2;}
15
+ .joy-header p {margin:2px 0 0; font-size:0.9rem; color:#666;}
16
+ </style>
17
+
18
+ <div class="joy-header">
19
+ <div>
20
+ <h1>JoyCaption <span style="font-weight:400">Beta&nbsp;One</span></h1>
21
+ <p>Image-captioning model &nbsp;|&nbsp; build 2025-05-10a</p>
22
+ </div>
23
+ </div>
24
+ <hr>"""
25
  DESCRIPTION = """
26
  <div>
27
+ <h2>Quick-start</h2>
28
+ <ol>
29
+ <li><strong>Upload or drop</strong> an image in the left-hand panel.</li>
30
+ <li>Pick a <strong>Caption Type</strong> and, if you wish, adjust the
31
+ <strong>Caption Length</strong>.</li>
32
+ <li>(Optional) tick any <strong>Extra Options</strong> checkboxes
33
+ &nbsp;–&nbsp;these add or remove specific details in the caption.</li>
34
+ <li>(Optional) expand <em>Generation settings</em> to tune
35
+ <code>temperature</code>, <code>top-p</code>, or
36
+ <code>max&nbsp;tokens</code>.</li>
37
+ <li>Press <kbd>Caption</kbd>.
38
+ The prompt sent to the model appears in the <em>Prompt</em> box (editable),
39
+ and the resulting caption streams into the <em>Caption</em> box.</li>
40
+ </ol>
41
+
42
+ <!-- ───────────────────── Caption-type reference ──────────────────── -->
43
+ <h2>Caption Types</h2>
44
+ <table>
45
+ <tr><th>Mode</th><th>What it does</th></tr>
46
+ <tr><td><strong>Descriptive</strong></td>
47
+ <td>Formal, detailed prose description.</td></tr>
48
+ <tr><td><strong>Descriptive&nbsp;(Casual)</strong></td>
49
+ <td>Similar to Descriptive but with a friendlier, conversational tone.</td></tr>
50
+ <tr><td><strong>Straightforward</strong></td>
51
+ <td>Objective, no fluff, and more succinct than Descriptive.</td></tr>
52
+ <tr><td><strong>Stable Diffusion Prompt</strong></td>
53
+ <td>Reverse-engineers a prompt that could have produced the image in a
54
+ SD/T2I model.</td></tr>
55
+ <tr><td><strong>MidJourney</strong></td>
56
+ <td>Same idea as above but tuned to MidJourney’s prompt style.</td></tr>
57
+ <tr><td><strong>Danbooru tag list</strong></td>
58
+ <td>Comma-separated tags strictly following Danbooru conventions
59
+ (artist:, copyright:, etc.). Lower-case underscores only.</td></tr>
60
+ <tr><td><strong>e621 tag list</strong></td>
61
+ <td>Alphabetical, namespaced tags in e621 style – includes species/meta
62
+ tags when relevant.</td></tr>
63
+ <tr><td><strong>rul34 tag list</strong></td>
64
+ <td>Rule34 style alphabetical tag dump; artist/copyright/character
65
+ prefixes first.</td></tr>
66
+ <tr><td><strong>Booru-like tag list</strong></td>
67
+ <td>Looser tag list when you want labels but not a specific Booru format.</td></tr>
68
+ <tr><td><strong>Art Critic</strong></td>
69
+ <td>Paragraph of art-historical commentary: composition, symbolism, style,
70
+ lighting, movement, etc.</td></tr>
71
+ <tr><td><strong>Product Listing</strong></td>
72
+ <td>Short marketing copy as if selling the depicted object.</td></tr>
73
+ <tr><td><strong>Social Media Post</strong></td>
74
+ <td>Catchy caption aimed at platforms like Instagram or BlueSky.</td></tr>
75
+ </table>
76
+
77
+ <!-- ───────────────────── Extras + generation notes ───────────────── -->
78
+ <h3>Extra Options</h3>
79
+ <p>These check-boxes fine-tune what the model should or should not mention:
80
+ lighting, camera angle, aesthetic rating, profanity, etc.
81
+ Toggle them before hitting <kbd>Caption</kbd>; the prompt box will update
82
+ instantly.</p>
83
+
84
+ <h3>Generation settings</h3>
85
+ <ul>
86
+ <li><strong>Temperature</strong> – randomness.
87
+ 0&nbsp;=&nbsp;deterministic; higher =&nbsp;more variety.</li>
88
+ <li><strong>Top-p</strong> – nucleus sampling cutoff. Lower =&nbsp;safer,
89
+ higher =&nbsp;freer.</li>
90
+ <li><strong>Max&nbsp;New Tokens</strong> – hard stop for the model’s output length.</li>
91
+ </ul>
92
+
93
+ <p>Enjoy experimenting, and feel free to open an issue if you
94
+ spot any bugs or have feature ideas!</p>
95
+ <hr>
96
  <p>🚨🚨🚨 If the "Help improve JoyCaption" box is checked, the _text_ query you write will be logged and I _might_ use it to help improve JoyCaption.
97
  It does not log images, user data, etc; only the text query. I cannot see what images you send, and frankly, I don't want to. But knowing what kinds of instructions
98
  and queries users want JoyCaption to handle will help guide me in building JoyCaption's dataset. This dataset will be made public. As always, the model itself is completely
 
100
  </div>
101
  """
102
 
 
 
103
  CAPTION_TYPE_MAP = {
104
  "Descriptive": [
105
+ "Write a detailed description for this image.",
106
+ "Write a detailed description for this image in {word_count} words or less.",
107
+ "Write a {length} detailed description for this image.",
108
  ],
109
+ "Descriptive (Casual)": [
110
  "Write a descriptive caption for this image in a casual tone.",
111
  "Write a descriptive caption for this image in a casual tone within {word_count} words.",
112
  "Write a {length} descriptive caption for this image in a casual tone.",
113
  ],
114
+ "Straightforward": [
115
+ "Write a straightforward caption for this image. Begin with the main subject and medium. Mention pivotal elements—people, objects, scenery—using confident, definite language. Focus on concrete details like color, shape, texture, and spatial relationships. Show how elements interact. Omit mood and speculative wording. If text is present, quote it exactly. Note any watermarks, signatures, or compression artifacts. Never mention what's absent, resolution, or unobservable details. Vary your sentence structure and keep the description concise, without starting with “This image is…” or similar phrasing.",
116
+ "Write a straightforward caption for this image within {word_count} words. Begin with the main subject and medium. Mention pivotal elements—people, objects, scenery—using confident, definite language. Focus on concrete details like color, shape, texture, and spatial relationships. Show how elements interact. Omit mood and speculative wording. If text is present, quote it exactly. Note any watermarks, signatures, or compression artifacts. Never mention what's absent, resolution, or unobservable details. Vary your sentence structure and keep the description concise, without starting with “This image is…” or similar phrasing.",
117
+ "Write a {length} straightforward caption for this image. Begin with the main subject and medium. Mention pivotal elements—people, objects, scenery—using confident, definite language. Focus on concrete details like color, shape, texture, and spatial relationships. Show how elements interact. Omit mood and speculative wording. If text is present, quote it exactly. Note any watermarks, signatures, or compression artifacts. Never mention what's absent, resolution, or unobservable details. Vary your sentence structure and keep the description concise, without starting with “This image is…” or similar phrasing.",
118
+ ],
119
  "Stable Diffusion Prompt": [
120
+ "Output a stable diffusion prompt that is indistinguishable from a real stable diffusion prompt.",
121
+ "Output a stable diffusion prompt that is indistinguishable from a real stable diffusion prompt. {word_count} words or less.",
122
+ "Output a {length} stable diffusion prompt that is indistinguishable from a real stable diffusion prompt.",
123
  ],
124
  "MidJourney": [
125
  "Write a MidJourney prompt for this image.",
126
  "Write a MidJourney prompt for this image within {word_count} words.",
127
  "Write a {length} MidJourney prompt for this image.",
128
  ],
129
+ "Danbooru tag list": [
130
+ "Generate only comma-separated Danbooru tags (lowercase_underscores). Strict order: `artist:`, `copyright:`, `character:`, `meta:`, then general tags. Include counts (1girl), appearance, clothing, accessories, pose, expression, actions, background. Use precise Danbooru syntax. No extra text.",
131
+ "Generate only comma-separated Danbooru tags (lowercase_underscores). Strict order: `artist:`, `copyright:`, `character:`, `meta:`, then general tags. Include counts (1girl), appearance, clothing, accessories, pose, expression, actions, background. Use precise Danbooru syntax. No extra text. {word_count} words or less.",
132
+ "Generate only comma-separated Danbooru tags (lowercase_underscores). Strict order: `artist:`, `copyright:`, `character:`, `meta:`, then general tags. Include counts (1girl), appearance, clothing, accessories, pose, expression, actions, background. Use precise Danbooru syntax. No extra text. {length} length.",
133
+ ],
134
+ "e621 tag list": [
135
+ "Write a comma-separated list of e621 tags in alphabetical order for this image. Start with the artist, copyright, character, species, meta, and lore tags (if any), prefixed by 'artist:', 'copyright:', 'character:', 'species:', 'meta:', and 'lore:'. Then all the general tags.",
136
+ "Write a comma-separated list of e621 tags in alphabetical order for this image. Start with the artist, copyright, character, species, meta, and lore tags (if any), prefixed by 'artist:', 'copyright:', 'character:', 'species:', 'meta:', and 'lore:'. Then all the general tags. Keep it under {word_count} words.",
137
+ "Write a {length} comma-separated list of e621 tags in alphabetical order for this image. Start with the artist, copyright, character, species, meta, and lore tags (if any), prefixed by 'artist:', 'copyright:', 'character:', 'species:', 'meta:', and 'lore:'. Then all the general tags.",
138
+ ],
139
+ "rul34 tag list": [
140
+ "Write a comma-separated list of rule34 tags in alphabetical order for this image. Start with the artist, copyright, character, and meta tags (if any), prefixed by 'artist:', 'copyright:', 'character:', and 'meta:'. Then all the general tags.",
141
+ "Write a comma-separated list of rule34 tags in alphabetical order for this image. Start with the artist, copyright, character, and meta tags (if any), prefixed by 'artist:', 'copyright:', 'character:', and 'meta:'. Then all the general tags. Keep it under {word_count} words.",
142
+ "Write a {length} comma-separated list of rule34 tags in alphabetical order for this image. Start with the artist, copyright, character, and meta tags (if any), prefixed by 'artist:', 'copyright:', 'character:', and 'meta:'. Then all the general tags.",
143
  ],
144
  "Booru-like tag list": [
145
  "Write a list of Booru-like tags for this image.",
 
252
 
253
  with gr.Row():
254
  with gr.Column():
255
+ input_image = gr.Image(type="pil", label="Input Image", height=512, width=512)
256
 
257
  caption_type = gr.Dropdown(
258
  choices=list(CAPTION_TYPE_MAP.keys()),
 
285
  "If applicable, mention the likely use of artificial or natural lighting sources.",
286
  "Do NOT use any ambiguous language.",
287
  "Include whether the image is sfw, suggestive, or nsfw.",
288
+ "ONLY describe the most important elements of the image.",
289
+ "If it is a work of art, do not include the artist's name or the title of the work.",
290
+ "Identify the image orientation (portrait, landscape, or square) and aspect ratio if obvious.",
291
+ """Use vulgar slang and profanity, such as (but not limited to) "fucking," "slut," "cock," etc.""",
292
+ "Do NOT use polite euphemisms—lean into blunt, casual phrasing.",
293
+ "Include information about the ages of any people/characters when applicable.",
294
+ "Mention whether the image depicts an extreme close-up, close-up, medium close-up, medium shot, cowboy shot, medium wide shot, wide shot, or extreme wide shot.",
295
+ "Do not mention the mood/feeling/etc of the image.",
296
+ "Explicitly specify the vantage height (eye-level, low-angle worm’s-eye, bird’s-eye, drone, rooftop, etc.).",
297
+ "If there is a watermark, you must mention it.",
298
+ """Your response will be used by a text-to-image model, so avoid useless meta phrases like “This image shows…”, "You are looking at...", etc.""",
299
  ],
300
  label="Extra Options"
301
  )