Spaces:
Build error
Build error
import streamlit as st | |
from PIL import Image | |
from transformers import pipeline | |
# Create an image captioning pipeline using Hugging Face Transformers | |
image_captioner = pipeline("image-captioning") | |
# Streamlit app header | |
st.title("Hugging Face Transformer Image-to-Text App") | |
# File uploader for image | |
uploaded_image = st.file_uploader("Upload an image", type=["jpg", "png", "jpeg"]) | |
if uploaded_image: | |
# Display the uploaded image | |
image = Image.open(uploaded_image) | |
st.image(image, caption="Uploaded Image", use_column_width=True) | |
# Perform image captioning when an image is uploaded | |
caption = image_captioner(uploaded_image)[0]["caption"] | |
# Display the generated caption | |
st.subheader("Generated Caption:") | |
st.write(caption) |