File size: 1,978 Bytes
2846658
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
59b0827
 
2846658
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
from document_qa_engine import DocumentQAEngine

import streamlit as st

import logging
from yaml import load, SafeLoader, YAMLError


def load_authenticator_config(file_path='authenticator_config.yaml'):
    try:
        with open(file_path, 'r') as file:
            authenticator_config = load(file, Loader=SafeLoader)
            return authenticator_config
    except FileNotFoundError:
        logging.error(f"File {file_path} not found.")
    except YAMLError as error:
        logging.error(f"Error parsing YAML file: {error}")


def new_file():
    st.session_state['loaded_embeddings'] = None
    st.session_state['doc_id'] = None
    st.session_state['uploaded'] = True
    clear_memory()


def clear_memory():
    if st.session_state['memory']:
        st.session_state['memory'].clear()


def init_qa(model, api_key=None):
    print(f"Initializing QA with model: {model} and API key: {api_key}")
    return DocumentQAEngine(model, api_key=api_key)


def append_header():
    st.header('πŸ“„ Document Insights :rainbow[AI] Assistant πŸ“š', divider='rainbow')
    st.text("πŸ“₯ Upload documents in PDF format. Get insights.. ask questions..")


def append_documentation_to_sidebar():
    with st.expander("Disclaimer"):
        st.markdown(
            """
            :warning: Do not upload sensitive data. We **temporarily** store text from the uploaded PDF documents solely
            for the purpose of processing your request, and we **do not assume responsibility** for any subsequent use
            or handling of the data submitted to third parties LLMs.
            """)
    with st.expander("Documentation"):
        st.markdown(
            """
            Upload a CV as PDF document. Once the spinner stops, you can proceed to ask your questions. The answers will
            be displayed in the right column. The system will answer your questions using the content of the document
            and mark refrences over the PDF viewer.
            """)