scmlewis commited on
Commit
8566c6a
ยท
verified ยท
1 Parent(s): 4e16e7a

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +21 -6
app.py CHANGED
@@ -6,11 +6,11 @@ from PIL import Image
6
  from collections import deque
7
  import numpy as np
8
 
9
- # Load main BLIP model for English captioning
10
  processor = BlipProcessor.from_pretrained("Salesforce/blip-image-captioning-base")
11
  model = BlipForConditionalGeneration.from_pretrained("Salesforce/blip-image-captioning-base")
12
 
13
- # Load YOLOv5 small model for object detection using ultralytics package
14
  detect_model = YOLO('yolov5s.pt')
15
 
16
  # Session memory for last 15 images and captions
@@ -52,16 +52,31 @@ def generate_caption(image):
52
  return result_text, gallery
53
 
54
  with gr.Blocks() as iface:
55
- gr.Markdown("# Image Captioning with Object Detection")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
56
 
57
- image_input = gr.Image(type="pil", label="Upload Image")
 
 
58
 
59
  caption_output = gr.Textbox(label="Caption and Detected Objects", lines=3, interactive=False)
60
 
61
  gallery = gr.Gallery(label="Last 15 Images and Captions", scale=3)
62
 
63
- generate_btn = gr.Button("Generate Caption")
64
-
65
  def on_generate(image):
66
  if image is None:
67
  return "Please upload an image.", []
 
6
  from collections import deque
7
  import numpy as np
8
 
9
+ # Load main BLIP model for image captioning
10
  processor = BlipProcessor.from_pretrained("Salesforce/blip-image-captioning-base")
11
  model = BlipForConditionalGeneration.from_pretrained("Salesforce/blip-image-captioning-base")
12
 
13
+ # Load YOLOv5 model for object detection using ultralytics
14
  detect_model = YOLO('yolov5s.pt')
15
 
16
  # Session memory for last 15 images and captions
 
52
  return result_text, gallery
53
 
54
  with gr.Blocks() as iface:
55
+ gr.Markdown(
56
+ "# ๐Ÿ–ผ๏ธ Image Captioning with Object Detection"
57
+ )
58
+
59
+ gr.Markdown(
60
+ """
61
+ ### ๐Ÿ‘‹ Welcome!
62
+ Upload an image and click **Generate Caption** to discover:
63
+ - ๐ŸŽฏ The **objects** detected in your image
64
+ - ๐Ÿ—’๏ธ A **caption** created automatically by the AI
65
+
66
+ ๐Ÿ” Your last 15 results are displayed below for quick reference.
67
+ ๐Ÿ’ก Tip: Upload clear, well-lit images for best results!
68
+ """,
69
+ elem_id="instructions"
70
+ )
71
 
72
+ with gr.Column():
73
+ image_input = gr.Image(type="pil", label="Upload Image")
74
+ generate_btn = gr.Button("Generate Caption")
75
 
76
  caption_output = gr.Textbox(label="Caption and Detected Objects", lines=3, interactive=False)
77
 
78
  gallery = gr.Gallery(label="Last 15 Images and Captions", scale=3)
79
 
 
 
80
  def on_generate(image):
81
  if image is None:
82
  return "Please upload an image.", []