Spaces:
Sleeping
Sleeping
File size: 1,077 Bytes
ce36534 f3b340f 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 31 32 33 34 35 36 37 |
import os
import gradio as gr
from transformers import pipeline
# # Initialize the pipeline with the image-to-text model
# model_path = "Salesforce/blip-image-captioning-base"
# if not os.path.exists(model_path):
# raise FileNotFoundError(f"Model path {model_path} does not exist. Please provide a valid path.")
# Initialize the image-to-text pipeline with the specified model
pipe = pipeline("image-to-text", model="Salesforce/blip-image-captioning-base")
#pipe = pipeline("image-to-text", model=model_path)
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()
|