Spaces:
Sleeping
Sleeping
Update app.py
Browse files
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
|
| 10 |
processor = BlipProcessor.from_pretrained("Salesforce/blip-image-captioning-base")
|
| 11 |
model = BlipForConditionalGeneration.from_pretrained("Salesforce/blip-image-captioning-base")
|
| 12 |
|
| 13 |
-
# Load YOLOv5
|
| 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(
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 56 |
|
| 57 |
-
|
|
|
|
|
|
|
| 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.", []
|