my_chatbot_1 / app.py
Zaheer786124's picture
Update app.py
2709f08 verified
raw
history blame
1.23 kB
import streamlit as st
from PIL import Image
from transformers import CLIPProcessor, CLIPModel
# Title of the Streamlit app
st.title("Product Image Title and Description Generator")
# Load the pre-trained Hugging Face CLIP model
model_name = "openai/clip-vit-base-patch32"
model = CLIPModel.from_pretrained(model_name)
processor = CLIPProcessor.from_pretrained(model_name)
# Image upload
uploaded_file = st.file_uploader("Upload a product image (JPG, JPEG, PNG):", type=["jpg", "jpeg", "png"])
if uploaded_file:
# Open and display the uploaded image
image = Image.open(uploaded_file)
st.image(image, caption="Uploaded Image", use_column_width=True)
# Process the uploaded image using CLIP model to generate a description
st.write("Processing the image...")
inputs = processor(images=image, text=["What is in this image?"], return_tensors="pt")
outputs = model(**inputs)
# Example output (you can refine the output generation further)
generated_description = "This is a stylish jacket suitable for cold weather."
# Display the generated title and description
st.write("Generated Product Title: Stylish Jacket")
st.write(f"Generated Product Description: {generated_description}")