Tas01 commited on
Commit
7ef80a5
·
verified ·
1 Parent(s): d87b7cb

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +64 -44
app.py CHANGED
@@ -343,6 +343,26 @@ class ImageStoryteller:
343
  scene_type = analysis['scenes'][0]['type'] if analysis['scenes'] else "unknown"
344
 
345
  return story, detected_objects, scene_type
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
346
 
347
  # FIXED: Added the missing method
348
  # def create_story_overlay(self, image, story):
@@ -351,58 +371,58 @@ class ImageStoryteller:
351
  # # For now, let's just return the story text
352
  # return story
353
 
354
- def create_story_overlay(self, image, story):
355
- """Create story overlay as separate black image with bigger fonts"""
356
- img_np = np.array(image)
357
- height, width = 800, 800#img_np.shape[:2]
358
 
359
- # Create a separate black image for the story (1/3 of original height)
360
- overlay_height = height // 1
361
- overlay = np.zeros((overlay_height, width, 3), dtype=np.uint8)
362
 
363
- # Add text to the black overlay with bigger fonts
364
- font = cv2.FONT_HERSHEY_SIMPLEX
365
- font_scale = 1 # Much bigger font
366
- font_color = (255, 255, 255) # White text
367
- thickness = 1 # Thicker text
368
- line_spacing = 25 # More spacing for bigger text
369
 
370
- # Split story into lines (max 40 characters per line for bigger text)
371
- words = story.split()
372
- lines = []
373
- current_line = ""
374
 
375
- for word in words:
376
- if len(current_line + word) <= 40:
377
- current_line += word + " "
378
- else:
379
- lines.append(current_line.strip())
380
- current_line = word + " "
381
- if current_line:
382
- lines.append(current_line.strip())
383
 
384
- # Limit to 5 lines maximum for bigger text
385
- # if len(lines) > 5: # If you want to keep some limit but indicate truncation
386
- # lines = lines[:5]
387
- # lines.append("... [Story continues]") # Indicate truncation
388
 
389
 
390
- # Calculate text block height for centering
391
- total_text_height = len(lines) * line_spacing
392
- start_y = (overlay_height - total_text_height) // + 60
393
 
394
- # Add each line of text, centered
395
- y_offset = start_y
396
- for line in lines:
397
- # Calculate text size for centering
398
- text_size = cv2.getTextSize(line, font, font_scale, thickness)[0]
399
- text_x = (width - text_size[0]) // 2
400
-
401
- cv2.putText(overlay, line, (text_x, y_offset),
402
- font, font_scale, font_color, thickness, cv2.LINE_AA)
403
- y_offset += line_spacing
404
 
405
- return Image.fromarray(overlay)
406
 
407
  def remove_background(self, image):
408
  """Remove background using rembg"""
@@ -705,7 +725,7 @@ with gr.Blocks(title="Who says AI isn’t creative? Watch it turn a single image
705
  with gr.Column():
706
  story_output = gr.Textbox(
707
  label="🔍 Story",
708
- height=None,
709
  # show_download_button=True
710
 
711
  lines=10,
 
343
  scene_type = analysis['scenes'][0]['type'] if analysis['scenes'] else "unknown"
344
 
345
  return story, detected_objects, scene_type
346
+
347
+ def create_story_overlay(self, image, story):
348
+ """Create formatted text with caption and story for textbox display"""
349
+
350
+ # Generate caption (first sentence of the story)
351
+ caption = ""
352
+ sentences = story.split('. ')
353
+ if sentences:
354
+ caption = sentences[0].strip()
355
+ if not caption.endswith('.'):
356
+ caption += '.'
357
+
358
+ # Format the text with caption separated from story
359
+ # Using a separator line of dashes
360
+ separator = "─" * 40
361
+
362
+ # Format the complete text for the textbox
363
+ formatted_text = f"{caption}\n{separator}\n{story}"
364
+
365
+ return formatted_text
366
 
367
  # FIXED: Added the missing method
368
  # def create_story_overlay(self, image, story):
 
371
  # # For now, let's just return the story text
372
  # return story
373
 
374
+ # def create_story_overlay(self, image, story):
375
+ # """Create story overlay as separate black image with bigger fonts"""
376
+ # img_np = np.array(image)
377
+ # height, width = 800, 800#img_np.shape[:2]
378
 
379
+ # # Create a separate black image for the story (1/3 of original height)
380
+ # overlay_height = height // 1
381
+ # overlay = np.zeros((overlay_height, width, 3), dtype=np.uint8)
382
 
383
+ # # Add text to the black overlay with bigger fonts
384
+ # font = cv2.FONT_HERSHEY_SIMPLEX
385
+ # font_scale = 1 # Much bigger font
386
+ # font_color = (255, 255, 255) # White text
387
+ # thickness = 1 # Thicker text
388
+ # line_spacing = 25 # More spacing for bigger text
389
 
390
+ # # Split story into lines (max 40 characters per line for bigger text)
391
+ # words = story.split()
392
+ # lines = []
393
+ # current_line = ""
394
 
395
+ # for word in words:
396
+ # if len(current_line + word) <= 40:
397
+ # current_line += word + " "
398
+ # else:
399
+ # lines.append(current_line.strip())
400
+ # current_line = word + " "
401
+ # if current_line:
402
+ # lines.append(current_line.strip())
403
 
404
+ # # Limit to 5 lines maximum for bigger text
405
+ # # if len(lines) > 5: # If you want to keep some limit but indicate truncation
406
+ # # lines = lines[:5]
407
+ # # lines.append("... [Story continues]") # Indicate truncation
408
 
409
 
410
+ # # Calculate text block height for centering
411
+ # total_text_height = len(lines) * line_spacing
412
+ # start_y = (overlay_height - total_text_height) // + 60
413
 
414
+ # # Add each line of text, centered
415
+ # y_offset = start_y
416
+ # for line in lines:
417
+ # # Calculate text size for centering
418
+ # text_size = cv2.getTextSize(line, font, font_scale, thickness)[0]
419
+ # text_x = (width - text_size[0]) // 2
420
+
421
+ # cv2.putText(overlay, line, (text_x, y_offset),
422
+ # font, font_scale, font_color, thickness, cv2.LINE_AA)
423
+ # y_offset += line_spacing
424
 
425
+ # return Image.fromarray(overlay)
426
 
427
  def remove_background(self, image):
428
  """Remove background using rembg"""
 
725
  with gr.Column():
726
  story_output = gr.Textbox(
727
  label="🔍 Story",
728
+ # height=None,
729
  # show_download_button=True
730
 
731
  lines=10,