File size: 586 Bytes
b522f96
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
import gradio as gr
from transformers import pipeline

# Pretrained vision-to-text model
captioner = pipeline("image-to-text", model="nlpconnect/vit-gpt2-image-captioning")

def generate_caption(image):
    result = captioner(image)[0]['generated_text']
    return result

# Gradio UI
demo = gr.Interface(
    fn=generate_caption,
    inputs=gr.Image(type="filepath"),
    outputs=gr.Textbox(label="Generated Caption"),
    title="Mini Image Captioner",
    description="Upload an image and get a natural language caption (Vision + LLM)"
)

if __name__ == "__main__":
    demo.launch()