| import streamlit as st |
| from PIL import Image |
| from transformers import AutoFeatureExtractor, AutoModelForImageCaptioning, AutoTokenizer |
|
|
| |
| model_name = "Salesforce/blip-image-captioning-large" |
| feature_extractor = AutoFeatureExtractor.from_pretrained(model_name) |
| tokenizer = AutoTokenizer.from_pretrained(model_name) |
| model = AutoModelForImageCaptioning.from_pretrained(model_name) |
|
|
| |
| st.title("Image Information Extractor") |
| st.write("Upload an image, and this app will extract information from it.") |
|
|
| |
| image = st.file_uploader("Upload an image", type=["jpg", "png", "jpeg"]) |
|
|
| if image: |
| |
| st.image(image, use_column_width=True, caption="Uploaded Image") |
|
|
| |
| image = Image.open(image) |
| st.write("Extracting information from the image...") |
|
|
| |
| inputs = tokenizer(image, return_tensors="pt") |
| with st.spinner("Generating caption..."): |
| captions = model.generate(**inputs) |
| caption = tokenizer.decode(captions[0], skip_special_tokens=True) |
|
|
| |
| st.write("Image Description:") |
| st.write(caption) |
|
|
| |
|
|
| st.sidebar.text("Built with ❤️ by Your Name") |
|
|