Testing2 / app.py
mkoot007's picture
Update app.py
5b4361c
raw
history blame
1.39 kB
import streamlit as st
from PIL import Image
from transformers import AutoFeatureExtractor, AutoModelForImageCaptioning, AutoTokenizer
# Load the image captioning model
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)
# Streamlit app title and description
st.title("Image Information Extractor")
st.write("Upload an image, and this app will extract information from it.")
# Upload image
image = st.file_uploader("Upload an image", type=["jpg", "png", "jpeg"])
if image:
# Display the uploaded image
st.image(image, use_column_width=True, caption="Uploaded Image")
# Process the image and extract information
image = Image.open(image)
st.write("Extracting information from the image...")
# Use the image captioning model to generate a description
inputs = tokenizer(image, return_tensors="pt")
with st.spinner("Generating caption..."):
captions = model.generate(**inputs)
caption = tokenizer.decode(captions[0], skip_special_tokens=True)
# Display the image description
st.write("Image Description:")
st.write(caption)
# You can add more processing or explanations here if needed
st.sidebar.text("Built with ❤️ by Your Name")