# components/document_preview.py import streamlit as st from typing import Dict, List, Optional, Any from datetime import datetime def enhanced_document_preview(doc: Dict[str, Any]): """Enhanced document preview component.""" with st.container(): # Header with metadata col1, col2 = st.columns([3, 1]) with col1: st.subheader(doc['name']) st.text(f"Uploaded: {doc['upload_date']}") if doc.get('collections'): st.text(f"Collections: {', '.join(doc['collections'])}") with col2: st.button("Download PDF", key=f"download_{doc['id']}", use_container_width=True) st.button("Add to Collection", key=f"add_col_{doc['id']}", use_container_width=True) # Document preview tabs tab1, tab2, tab3 = st.tabs(["Preview", "Text Content", "Metadata"]) with tab1: if doc.get('thumbnail'): st.image(doc['thumbnail']) else: st.write("Preview not available") with tab2: st.text_area( "", value=doc['content'], height=400, disabled=True ) with tab3: col1, col2 = st.columns(2) with col1: st.write("**Document Info**") st.write(f"Size: {len(doc['content'])/1024:.1f} KB") st.write(f"Upload Date: {doc['upload_date']}") st.write(f"Document ID: {doc['id']}") with col2: st.write("**Collections**") for collection in doc.get('collections', []): st.write(f"• {collection}")