Spaces:
Build error
Build error
start
Browse files
app.py
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import streamlit as st
|
| 2 |
+
from transformers import pipeline
|
| 3 |
+
|
| 4 |
+
# Initialize the model
|
| 5 |
+
captioner = pipeline("image-to-text", model="Salesforce/blip-image-captioning-base")
|
| 6 |
+
|
| 7 |
+
# Streamlit app title
|
| 8 |
+
st.title("Image Captioning with Transformers")
|
| 9 |
+
|
| 10 |
+
# Input for the image URL
|
| 11 |
+
image_url = st.text_input("Enter the URL of an image", "https://www.simplilearn.com/ice9/free_resources_article_thumb/random_forest_algorithm.jpg")
|
| 12 |
+
|
| 13 |
+
# Display the image
|
| 14 |
+
if image_url:
|
| 15 |
+
st.image(image_url, caption="Input Image", use_column_width=True)
|
| 16 |
+
|
| 17 |
+
# Generate the caption
|
| 18 |
+
if st.button("Generate Caption"):
|
| 19 |
+
with st.spinner("Generating caption..."):
|
| 20 |
+
caption = captioner(image_url)
|
| 21 |
+
st.write("**Caption:**", caption[0]['generated_text'])
|
| 22 |
+
|
| 23 |
+
# Add some information about the app
|
| 24 |
+
st.write("""
|
| 25 |
+
This app uses a pre-trained model from the Hugging Face Transformers library to generate captions for images.
|
| 26 |
+
Enter an image URL above and click "Generate Caption" to see the result.
|
| 27 |
+
""")
|