alexnasa commited on
Commit
5138dea
Β·
verified Β·
1 Parent(s): 3edd428

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +13 -0
app.py CHANGED
@@ -244,11 +244,24 @@ def generate_image(
244
  if not cap or cap.strip() == "":
245
  try:
246
  captions[idx] = vlm_img_caption(img)
 
 
247
  except Exception as e:
248
  # if captioning fails, leave it empty or log as you wish
249
  print(f"Failed to generate caption for image {idx}: {e}")
250
  # β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”
251
 
 
 
 
 
 
 
 
 
 
 
 
252
  print(f"Length of images: {len(images)}")
253
  print(f"Length of captions: {len(captions)}")
254
 
 
244
  if not cap or cap.strip() == "":
245
  try:
246
  captions[idx] = vlm_img_caption(img)
247
+
248
+ gr.Info(f"ENT{idx+1} Prompt Missing. Auto Generating Caption")
249
  except Exception as e:
250
  # if captioning fails, leave it empty or log as you wish
251
  print(f"Failed to generate caption for image {idx}: {e}")
252
  # β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”
253
 
254
+ # β€”β€”β€” Build a default prompt if none was provided β€”β€”β€”
255
+ if not prompt or prompt.strip() == "":
256
+
257
+ # collect ENT1, ENT2, … for every non-None image
258
+ ents = [f"ENT{i+1}" for i, img in enumerate(images) if img is not None]
259
+ # join them with spaces (or β€œ and ” if you prefer)
260
+ prompt = " and ".join(ents)
261
+ # e.g. prompt becomes "ENT1 ENT2" or "ENT1 ENT2 ENT3"
262
+ gr.Info(f"Prompt Not Provided, Defaulting to {prompt}")
263
+ # β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”
264
+
265
  print(f"Length of images: {len(images)}")
266
  print(f"Length of captions: {len(captions)}")
267