nickdigger commited on
Commit
ed602d3
·
verified ·
1 Parent(s): ff34e9d

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +13 -9
app.py CHANGED
@@ -48,7 +48,7 @@ def cleanup_storage():
48
 
49
  TITLE = """
50
  <div style="text-align:center;margin:20px 0;">
51
- <h1>🎨 JoyCaption Three-Tone + Q&A (v3.2 ZeroGPU)</h1>
52
  <p><strong>✅ Blog-friendly captions • SEO optimized • Longer descriptions • ZeroGPU optimized</strong></p>
53
  </div><hr>
54
  """
@@ -88,8 +88,8 @@ CAPTION_PROMPTS = {
88
  "max_tokens": 600
89
  },
90
  "uncensored_keywords": {
91
- "system": "You are a detailed image captioner.",
92
- "prompt": "Create a comprehensive description of this image. Describe the people, their appearance, clothing, poses, facial expressions, setting, and atmosphere in detail.",
93
  "temperature": 0.6,
94
  "top_p": 0.9,
95
  "max_tokens": 600
@@ -137,9 +137,12 @@ def safe_generate_caption_direct(image, tone, max_chars=1000, keywords_text="",
137
  if tone == "casual_friend" and keywords_text and keywords_text.strip():
138
  base_prompt += f" Pay special attention to these elements if present: {keywords_text.strip()}"
139
 
140
- # Handle custom instructions for uncensored_keywords (third) tone ONLY
141
- if tone == "uncensored_keywords" and custom_instruction and custom_instruction.strip():
142
- base_prompt += f" Make sure that you mention: {custom_instruction.strip()}"
 
 
 
143
 
144
  # Use conversation format
145
  convo = [
@@ -292,8 +295,8 @@ def generate_casual_friend_only(image, keywords_text="", custom_instruction=""):
292
 
293
  @spaces.GPU(duration=50)
294
  @torch.no_grad()
295
- def generate_uncensored_keywords_only(image, custom_instruction=""):
296
- result = safe_generate_caption_direct(image, "uncensored_keywords", max_chars=1000, custom_instruction=custom_instruction) if image else "❌ Upload image first"
297
  gc.collect()
298
  return result
299
 
@@ -341,6 +344,7 @@ def answer_question(image, question):
341
  temperature=0.3, # Lower temperature for more accurate Q&A
342
  top_p=0.8,
343
  top_k=None,
 
344
  use_cache=True,
345
  pad_token_id=processor.tokenizer.eos_token_id,
346
  eos_token_id=processor.tokenizer.eos_token_id
@@ -413,7 +417,7 @@ with gr.Blocks(title="JoyCaption Three-Tone + Q&A", theme=gr.themes.Soft()) as d
413
 
414
  g1.click(generate_engaging_only, [image_input, custom_instruction_input], out1)
415
  g2.click(generate_casual_friend_only, [image_input, keywords_input, custom_instruction_input], out2)
416
- g3.click(generate_uncensored_keywords_only, [image_input, custom_instruction_input], out3)
417
  ask_btn.click(answer_question, [image_input, question_input], qa_output)
418
 
419
  def handle_export(k, c, q, e1, e2, e3, qa, img):
 
48
 
49
  TITLE = """
50
  <div style="text-align:center;margin:20px 0;">
51
+ <h1>🎨 JoyCaption Three-Tone + Q&A (v3.3 ZeroGPU)</h1>
52
  <p><strong>✅ Blog-friendly captions • SEO optimized • Longer descriptions • ZeroGPU optimized</strong></p>
53
  </div><hr>
54
  """
 
88
  "max_tokens": 600
89
  },
90
  "uncensored_keywords": {
91
+ "system": "You are a helpful image captioner.",
92
+ "prompt": "Describe this image.",
93
  "temperature": 0.6,
94
  "top_p": 0.9,
95
  "max_tokens": 600
 
137
  if tone == "casual_friend" and keywords_text and keywords_text.strip():
138
  base_prompt += f" Pay special attention to these elements if present: {keywords_text.strip()}"
139
 
140
+ # Handle custom instructions and keywords for uncensored_keywords (third) tone ONLY
141
+ if tone == "uncensored_keywords":
142
+ if custom_instruction and custom_instruction.strip():
143
+ base_prompt += f" Make sure that you mention: {custom_instruction.strip()}"
144
+ if keywords_text and keywords_text.strip():
145
+ base_prompt += f" You are allowed to use these keywords: {keywords_text.strip()}"
146
 
147
  # Use conversation format
148
  convo = [
 
295
 
296
  @spaces.GPU(duration=50)
297
  @torch.no_grad()
298
+ def generate_uncensored_keywords_only(image, keywords_text="", custom_instruction=""):
299
+ result = safe_generate_caption_direct(image, "uncensored_keywords", max_chars=1000, keywords_text=keywords_text, custom_instruction=custom_instruction) if image else "❌ Upload image first"
300
  gc.collect()
301
  return result
302
 
 
344
  temperature=0.3, # Lower temperature for more accurate Q&A
345
  top_p=0.8,
346
  top_k=None,
347
+ repetition_penalty=1.1,
348
  use_cache=True,
349
  pad_token_id=processor.tokenizer.eos_token_id,
350
  eos_token_id=processor.tokenizer.eos_token_id
 
417
 
418
  g1.click(generate_engaging_only, [image_input, custom_instruction_input], out1)
419
  g2.click(generate_casual_friend_only, [image_input, keywords_input, custom_instruction_input], out2)
420
+ g3.click(generate_uncensored_keywords_only, [image_input, keywords_input, custom_instruction_input], out3)
421
  ask_btn.click(answer_question, [image_input, question_input], qa_output)
422
 
423
  def handle_export(k, c, q, e1, e2, e3, qa, img):