File size: 2,084 Bytes
5d4ad83
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
import streamlit as st
from typing import Union, List
from src.utils import logger

logger = logger.get_logger()

PAGE_TITLE = "PDF Extractor"
PAGE_LAYOUT = "wide"


def config_homepage(page_title=PAGE_TITLE):
    """

    Configures the Streamlit homepage with essential settings.



    This function sets up the page title, icon, layout, and sidebar state.

    It also defines custom menu items for better navigation.



    Args:

        page_title (str): The title displayed on the browser tab (default is PAGE_TITLE).



    Key Features:

    - Ensures `st.set_page_config()` is called only once to avoid errors.

    - Uses constants for improved maintainability and consistency.

    - Provides links for help, bug reporting, and an 'About' section.



    Example:

        >>> config_homepage("My Custom App")

    """
    if "page_config_set" not in st.session_state:
        st.set_page_config(
            page_title=page_title,
            layout=PAGE_LAYOUT,
            initial_sidebar_state="collapsed",
        )
        # st.session_state.page_config_set = True

def upload_file(

    file_types: Union[str, List[str]] = "pdf",

    label: str = "📤 Upload a file",

    help_text: str = "Upload your file for processing.",

    allow_multiple: bool = True,

):
    """

    Streamlit file uploader widget with options.



    Args:

        file_types (str or list): Allowed file type(s), e.g., "pdf" or ["pdf", "docx"].

        label (str): Label displayed above the uploader.

        help_text (str): Tooltip help text.

        allow_multiple (bool): Allow multiple file uploads.



    Returns:

        Uploaded file(s): A single file object or a list of file objects.

    """
    if isinstance(file_types, str):
        file_types = [file_types]

    uploaded_files = st.file_uploader(
        label=label,
        type=file_types,
        help=help_text,
        accept_multiple_files=allow_multiple
    )

    if st.button("Submit"):
        st.session_state.pdf_file = uploaded_files
        return uploaded_files