sahalhes's picture
k
9cf29f4
raw
history blame contribute delete
591 Bytes
import gradio as gr
from transformers import pipeline
pipe = pipeline("image-to-text", model="nlpconnect/vit-gpt2-image-captioning")
def generate_caption(image):
result = pipe(image)
return result[0]["generated_text"].strip()
title = "🖼️ Image Caption Generator"
description = "Upload an image and get a caption"
demo = gr.Interface(
fn=generate_caption,
inputs=gr.Image(type="pil"),
outputs=gr.Textbox(label="Generated Caption"),
title=title,
description=description,
flagging_mode="never"
)
if __name__ == "__main__":
demo.launch(share=False)