Spaces:
Build error
Build error
Update app.py
Browse files10 unmodified lines1112131415161718192010 unmodified lines# Function to convert image to text (captioning)def image_to_text(image):try:# Preprocess the imagepixel_values = processor(images=image, return_tensors="pt").pixel_values# Generate captionoutput_ids = model.generate(pixel_values, max_length=16, num_beams=4, early_stopping=True)caption = tokenizer.decode(output_ids[0], skip_special_tokens=True)return caption.strip()except Exception as e:10 unmodified lines1112131415161718192021222310 unmodified lines# Function to convert image to text (captioning)def image_to_text(image):try:# Preprocess the image with paddingpixel_values = processor(images=image, return_tensors="pt", padding=True).pixel_values# Generate caption with padding handledoutput_ids = model.generate(pixel_values, max_length=16, num_beams=4, early_stopping=True)# Decode the output ids to textcaption = tokenizer.decode(output_ids[0], skip_special_tokens=True)return caption.strip()except Exception as e:
app.py+6-3