Spaces:
Sleeping
Sleeping
Update app.py
Browse files8 unmodified lines910111212131475 unmodified lines90919294939496959697981009910010110211 unmodified lines1141151161181191201211221171181195 unmodified lines1251261271341351361371281291301311321331348 unmodified linesfrom langchain_core.messages import HumanMessage, AIMessagefrom langchain.memory import ConversationBufferMemoryfrom langchain.document_loaders import PyPDFLoaderfrom fuzzywuzzy import process
# Set page configst.set_page_config(page_title="Tbank Assistant", layout="wide")75 unmodified lines
document_chain = create_stuff_documents_chain(chat, question_answering_prompt)
important_terms = ["Tbank", "Chairman", "CEO", "products", "services"] # Add more terms as needed
return retriever, document_chain, important_terms return retriever, document_chain
# Load components with st.spinner("Initializing Tbank Assistant..."): retriever, document_chain, important_terms = initialize_components() retriever, document_chain = initialize_components()
# Initialize memory for each session if "memory" not in st.session_state:11 unmodified lines with st.chat_message(message["role"]): st.markdown(message["content"])
def fuzzy_match(query, choices, threshold=80): result = process.extractOne(query, choices) if result and result[1] >= threshold: return result[0] return None
# React to user input if prompt := st.chat_input("What would you like to know about Tbank?"):5 unmodified lines with st.chat_message("assistant"): message_placeholder = st.empty()
# Fuzzy match important terms matched_term = fuzzy_match(prompt.lower(), important_terms) if matched_term: prompt = f"{prompt} (Matched term: {matched_term})" # # Fuzzy match important terms # matched_term = fuzzy_match(prompt.lower(), important_terms) # if matched_term: # prompt = f"{prompt} (Matched term: {matched_term})"
# Retrieve relevant documents docs = retriever.get_relevant_documents(prompt)app.py+7-13