|
import gradio as gr |
|
from PIL import Image |
|
from transformers import pipeline |
|
|
|
|
|
caption_pipeline = pipeline("image-to-text", model="nlpconnect/vit-gpt2-image-captioning") |
|
|
|
def generate_caption(image): |
|
|
|
image = Image.open(image).convert("RGB") |
|
|
|
|
|
result = caption_pipeline(image) |
|
caption = result[0]["generated_text"] |
|
|
|
return caption |
|
|
|
|
|
interface = gr.Interface(fn=generate_caption, |
|
inputs=gr.inputs.Image(type="pil", label="Upload an Image"), |
|
outputs=gr.outputs.Textbox(label="Generated Caption")) |
|
interface.launch() |
|
|