from PIL import Image from io import BytesIO import base64 def base64_to_image(base64_data): """Convert base64 image data to PIL Image""" try: if not base64_data: return None image_bytes = base64.b64decode(base64_data) return Image.open(BytesIO(image_bytes)) except Exception as e: print(f"Image conversion error: {e}") return None def display_images(current_images): """Format images for Gradio gallery display""" if not current_images: return None return [ (img["image"], f"{img['caption']} (Source: {img['source']}, Page: {img['page']})") for img in current_images if img.get("image") ] def display_tables(current_tables): """Format tables for HTML display""" if not current_tables: return None html = "" for table in current_tables: html += f"""
Source: {table['source']}, Page: {table['page']}