Spaces:
Build error
Build error
Update app.py
Browse files123345667894 unmodified lines141516171819201721222324import gradio as grfrom transformers import VisionEncoderDecoderModel, ViTImageProcessor, AutoTokenizerimport torchfrom PIL import Imageimport torch
# Load the image-captioning model and necessary processor/tokenizer# Load the image-captioning model and necessary processorsmodel = VisionEncoderDecoderModel.from_pretrained("nlpconnect/vit-gpt2-image-captioning")processor = ViTImageProcessor.from_pretrained("nlpconnect/vit-gpt2-image-captioning")tokenizer = AutoTokenizer.from_pretrained("nlpconnect/vit-gpt2-image-captioning")4 unmodified lines# Define the function to convert image to textdef image_to_text(image): try: # Check if image is loaded properly if image is None or not isinstance(image, Image.Image): return "Error: Invalid image type. Please upload a valid image."
# Preprocess image with padding # Preprocess the image with padding pixel_values = processor(images=image, return_tensors="pt", padding="max_length", truncation=True).pixel_values
# Generate text caption with padding consideredapp.py+7-3