Spaces:
Sleeping
Sleeping
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. | |