File size: 989 Bytes
b830598
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
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.
""")