Spaces:
Sleeping
Sleeping
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,25 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# app.py
|
2 |
+
|
3 |
+
from transformers import pipeline
|
4 |
+
import gradio as gr
|
5 |
+
|
6 |
+
# Load the image captioning pipeline
|
7 |
+
pipe = pipeline("image-to-text", model="Salesforce/blip-image-captioning-base")
|
8 |
+
|
9 |
+
# Define the function that gets the caption
|
10 |
+
def caption_image(image):
|
11 |
+
result = pipe(image)
|
12 |
+
return result[0]["generated_text"]
|
13 |
+
|
14 |
+
# Build the Gradio interface
|
15 |
+
interface = gr.Interface(
|
16 |
+
fn=caption_image,
|
17 |
+
inputs=gr.Image(type="pil"),
|
18 |
+
outputs="text",
|
19 |
+
title="🖼️ BLIP Image Captioning",
|
20 |
+
description="Upload an image and get a caption using Salesforce's BLIP image captioning model."
|
21 |
+
)
|
22 |
+
|
23 |
+
# Launch the app
|
24 |
+
if __name__ == "__main__":
|
25 |
+
interface.launch()
|