import streamlit as st from transformers import pipeline # Initialize the model captioner = pipeline("image-to-text", model="Salesforce/blip-image-captioning-base") # Streamlit app title st.title("Image Captioning with Transformers") # Input for the image URL image_url = st.text_input("Enter the URL of an image", "https://www.simplilearn.com/ice9/free_resources_article_thumb/random_forest_algorithm.jpg") # Display the image if image_url: st.image(image_url, caption="Input Image", use_column_width=True) # Generate the caption if st.button("Generate Caption"): with st.spinner("Generating caption..."): caption = captioner(image_url) st.write("**Caption:**", caption[0]['generated_text']) # Add some information about the app st.write(""" This app uses a pre-trained model from the Hugging Face Transformers library to generate captions for images. Enter an image URL above and click "Generate Caption" to see the result. """)