Spaces:
Sleeping
Sleeping
| # app.py | |
| import streamlit as st | |
| from utils import ImageCaptioningModel | |
| import tempfile | |
| # Initialize the BLIP Image Captioning model | |
| captioning_model = ImageCaptioningModel() | |
| # Streamlit UI | |
| st.title("🖼️ Image Captioning with BLIP") | |
| st.write("Upload an image and the model will generate a description.") | |
| # Upload Image | |
| uploaded_file = st.file_uploader("Choose an image...", type=["jpg", "jpeg", "png"]) | |
| if uploaded_file is not None: | |
| # Display uploaded image | |
| st.image(uploaded_file, caption="Uploaded Image", use_column_width=True) | |
| # Save file temporarily | |
| with tempfile.NamedTemporaryFile(delete=False, suffix=".jpg") as temp_file: | |
| temp_file.write(uploaded_file.getbuffer()) | |
| temp_file_path = temp_file.name | |
| # Generate caption | |
| with st.spinner("Generating caption..."): | |
| caption = captioning_model.generate_caption(temp_file_path) | |
| # Show caption result | |
| st.success("Generated Caption:") | |
| st.write(f"**{caption}**") | |