File size: 905 Bytes
2e7bac9
4e57b06
 
2e7bac9
 
 
 
 
4e57b06
2e7bac9
 
 
 
 
4e57b06
2e7bac9
 
 
 
 
 
 
 
 
4e57b06
2e7bac9
 
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
import gradio as gr
from transformers import pipeline

# Load the image-to-text pipeline
image_to_text_pipelines = {
    "Salesforce/blip-image-captioning-base": pipeline("image-to-text", model="Salesforce/blip-image-captioning-base"),
    # Add more models if needed
}

def generate_caption(input_image, model_name="Salesforce/blip-image-captioning-base"):
    # Generate caption for the input image using the selected model
    image_to_text_pipeline = image_to_text_pipelines[model_name]
    caption = image_to_text_pipeline(input_image)[0]['generated_text']
    return caption

# Interface for launching the model
interface = gr.Interface(
    fn=generate_caption,
    inputs=gr.Image(type='pil', label="Input Image"),
    outputs="text",
    title="Image Captioning Model",
    description="This model generates captions for images.",
    theme="default",
)

# Launch the interface
interface.launch()