Spaces:
Sleeping
Sleeping
File size: 814 Bytes
0f2351b | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 | from transformers import pipeline
import gradio as gr
# Load pre-trained image captioning model
captioner = pipeline("image-to-text", model="Salesforce/blip-image-captioning-base")
# Define function to get caption
def get_image_caption(image):
if image is None:
return "Please upload an image."
caption = captioner(image)[0]['generated_text']
return caption
# Build Gradio app
with gr.Blocks() as image_captioning_app:
gr.Markdown("## 🖼️ Image Captioning App")
with gr.Row():
image_input = gr.Image(type="pil", label="Upload an Image")
caption_output = gr.Textbox(label="Image Caption")
generate_button = gr.Button("Generate Caption")
generate_button.click(fn=get_image_caption, inputs=image_input, outputs=caption_output)
image_captioning_app.launch()
|