Spaces:
Sleeping
Sleeping
File size: 771 Bytes
ce36534 973104b f3b340f ce36534 973104b ce36534 973104b ce36534 973104b |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
import os
import gradio as gr
from transformers import pipeline
# Initialize the image-to-text pipeline with the specified model
pipe = pipeline("image-to-text", model="Salesforce/blip-image-captioning-base")
def launch(input):
"""
Function to generate image caption.
Args:
input (PIL.Image): Input image for captioning.
Returns:
str: Generated caption for the input image.
"""
out = pipe(input)
return out[0]['generated_text']
# Create a Gradio interface for the image-to-text pipeline
iface = gr.Interface(
fn=launch, # Function to generate captions
inputs=gr.Image(type='pil'), # Input type: Image (PIL format)
outputs="text" # Output type: Text
)
# Launch the Gradio interface
iface.launch()
|