File size: 1,813 Bytes
4152a02
79bef70
 
 
 
 
4152a02
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
79bef70
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# 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}")