Describer / app.py
Jangai's picture
Update app.py
761cd02 verified
raw
history blame
779 Bytes
import gradio as gr
from PIL import Image
from transformers import pipeline
# Initialize the pipeline with the image captioning model
caption_pipeline = pipeline("image-to-text", model="nlpconnect/vit-gpt2-image-captioning")
def generate_caption(image):
# Convert the PIL Image to the format expected by the model
image = Image.open(image).convert("RGB")
# Use the pipeline to generate a caption
result = caption_pipeline(image)
caption = result[0]["generated_text"]
return caption
# Setup the Gradio interface
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()