File size: 875 Bytes
b830598
abcfd78
b830598
abcfd78
 
b830598
abcfd78
 
b830598
abcfd78
 
b830598
abcfd78
 
 
 
 
 
 
 
 
 
 
 
 
 
b830598
abcfd78
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
29
import streamlit as st
from transformers import pipeline

# Initialize the image captioning pipeline
captioner = pipeline("image-to-text", model="Salesforce/blip-image-captioning-base")

# Streamlit app title
st.title("Image to Text Captioning")

# Input for image URL
image_url = st.text_input("Enter the URL of the image:")

# If an image URL is provided
if image_url:
    try:
        # Display the image
        st.image(image_url, caption="Provided Image", use_column_width=True)
        
        # Generate the caption
        caption = captioner(image_url)
        
        # Display the caption
        st.write("**Generated Caption:**")
        st.write(caption[0]['generated_text'])
    except Exception as e:
        st.error(f"An error occurred: {e}")

# To run this app, save this code to a file (e.g., `app.py`) and run `streamlit run app.py` in your terminal.