CoolFace
Apppublic

MachineLearningReply/q-and-a-tool

sourceHugging Faceupdated 2y agoView on Hugging Face
0likes
utils.py57 linesDownload Raw Back to root
1from document_qa_engine import DocumentQAEngine2 3import streamlit as st4 5import logging6from yaml import load, SafeLoader, YAMLError7 8 9def load_authenticator_config(file_path='authenticator_config.yaml'):10    try:11        with open(file_path, 'r') as file:12            authenticator_config = load(file, Loader=SafeLoader)13            return authenticator_config14    except FileNotFoundError:15        logging.error(f"File {file_path} not found.")16    except YAMLError as error:17        logging.error(f"Error parsing YAML file: {error}")18 19 20def new_file():21    st.session_state['loaded_embeddings'] = None22    st.session_state['doc_id'] = None23    st.session_state['uploaded'] = True24    clear_memory()25 26 27def clear_memory():28    if st.session_state['memory']:29        st.session_state['memory'].clear()30 31 32def init_qa(model, api_key=None):33    print(f"Initializing QA with model: {model} and API key: {api_key}")34    return DocumentQAEngine(model, api_key=api_key)35 36 37def append_header():38    st.header('๐Ÿ“„ Document Insights :rainbow[AI] Assistant ๐Ÿ“š', divider='rainbow')39    st.text("๐Ÿ“ฅ Upload documents in PDF format. Get insights.. ask questions..")40 41 42def append_documentation_to_sidebar():43    with st.expander("Disclaimer"):44        st.markdown(45            """46            :warning: Do not upload sensitive data. We **temporarily** store text from the uploaded PDF documents solely47            for the purpose of processing your request, and we **do not assume responsibility** for any subsequent use48            or handling of the data submitted to third parties LLMs.49            """)50    with st.expander("Documentation"):51        st.markdown(52            """53            Upload document as PDF document. Once the spinner stops, you can proceed to ask your questions. The answers will54            be displayed in the right column. The system will answer your questions using the content of the document55            and mark refrences over the PDF viewer.56            """)57