Spaces:
Build error
Build error
Update app.py
Browse files1234567894 unmodified lines14151617181920import gradio as grfrom transformers import VisionEncoderDecoderModel, ViTImageProcessor, AutoTokenizerimport torchfrom PIL import Image# Load the image-captioning model and necessary processor/tokenizermodel = 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:# Preprocess image with paddingpixel_values = processor(images=image, return_tensors="pt", padding="max_length", truncation=True).pixel_values# Generate text caption with padding considered1234567894 unmodified lines1415161718192021222324import gradio as grfrom transformers import VisionEncoderDecoderModel, ViTImageProcessor, AutoTokenizerfrom PIL import Imageimport torch# 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 properlyif image is None or not isinstance(image, Image.Image):return "Error: Invalid image type. Please upload a valid image."# Preprocess the image with paddingpixel_values = processor(images=image, return_tensors="pt", padding="max_length", truncation=True).pixel_values# Generate text caption with padding considered
app.py+7-3