from transformers import pipeline import gradio as gr # Load the image-to-text model pipe = pipeline("image-to-text", model="Salesforce/blip-image-captioning-base") # Function to generate captions def generate_caption(image): # Renamed 'input' to avoid conflict out = pipe(image) return out[0].get("generated_text", "No caption generated") # Safe key access # Create the Gradio Interface iface = gr.Interface(fn=generate_caption, inputs=gr.Image(type="pil"), outputs="text") # Launch the app iface.launch()