# app.py import streamlit as st from transformers import BlipProcessor, BlipForConditionalGeneration from PIL import Image import torch st.title("AI Image Caption Generator") st.write("Upload an image and get a caption generated by an AI model!") uploaded_file = st.file_uploader("Upload an image", type=["jpg", "png", "jpeg"]) if uploaded_file: image = Image.open(uploaded_file).convert('RGB') st.image(image, caption="Uploaded Image", use_column_width=True) st.write("Generating caption...") processor = BlipProcessor.from_pretrained("Salesforce/blip-image-captioning-base") model = BlipForConditionalGeneration.from_pretrained("Salesforce/blip-image-captioning-base") inputs = processor(image, return_tensors="pt") out = model.generate(**inputs) caption = processor.decode(out[0], skip_special_tokens=True) st.success(f"📝 Caption: {caption}")