Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -9,7 +9,6 @@ from langchain_core.prompts import ChatPromptTemplate, MessagesPlaceholder
|
|
9 |
from langchain_core.messages import HumanMessage, AIMessage
|
10 |
from langchain.memory import ConversationBufferMemory
|
11 |
from langchain.document_loaders import PyPDFLoader
|
12 |
-
from fuzzywuzzy import process
|
13 |
|
14 |
# Set page config
|
15 |
st.set_page_config(page_title="Tbank Assistant", layout="wide")
|
@@ -91,13 +90,13 @@ if "OPENAI_API_KEY" in os.environ:
|
|
91 |
|
92 |
document_chain = create_stuff_documents_chain(chat, question_answering_prompt)
|
93 |
|
94 |
-
|
95 |
|
96 |
-
return retriever, document_chain
|
97 |
|
98 |
# Load components
|
99 |
with st.spinner("Initializing Tbank Assistant..."):
|
100 |
-
retriever, document_chain
|
101 |
|
102 |
# Initialize memory for each session
|
103 |
if "memory" not in st.session_state:
|
@@ -115,11 +114,6 @@ if "OPENAI_API_KEY" in os.environ:
|
|
115 |
with st.chat_message(message["role"]):
|
116 |
st.markdown(message["content"])
|
117 |
|
118 |
-
def fuzzy_match(query, choices, threshold=80):
|
119 |
-
result = process.extractOne(query, choices)
|
120 |
-
if result and result[1] >= threshold:
|
121 |
-
return result[0]
|
122 |
-
return None
|
123 |
|
124 |
# React to user input
|
125 |
if prompt := st.chat_input("What would you like to know about Tbank?"):
|
@@ -131,10 +125,10 @@ if "OPENAI_API_KEY" in os.environ:
|
|
131 |
with st.chat_message("assistant"):
|
132 |
message_placeholder = st.empty()
|
133 |
|
134 |
-
# Fuzzy match important terms
|
135 |
-
matched_term = fuzzy_match(prompt.lower(), important_terms)
|
136 |
-
if matched_term:
|
137 |
-
|
138 |
|
139 |
# Retrieve relevant documents
|
140 |
docs = retriever.get_relevant_documents(prompt)
|
|
|
9 |
from langchain_core.messages import HumanMessage, AIMessage
|
10 |
from langchain.memory import ConversationBufferMemory
|
11 |
from langchain.document_loaders import PyPDFLoader
|
|
|
12 |
|
13 |
# Set page config
|
14 |
st.set_page_config(page_title="Tbank Assistant", layout="wide")
|
|
|
90 |
|
91 |
document_chain = create_stuff_documents_chain(chat, question_answering_prompt)
|
92 |
|
93 |
+
|
94 |
|
95 |
+
return retriever, document_chain
|
96 |
|
97 |
# Load components
|
98 |
with st.spinner("Initializing Tbank Assistant..."):
|
99 |
+
retriever, document_chain = initialize_components()
|
100 |
|
101 |
# Initialize memory for each session
|
102 |
if "memory" not in st.session_state:
|
|
|
114 |
with st.chat_message(message["role"]):
|
115 |
st.markdown(message["content"])
|
116 |
|
|
|
|
|
|
|
|
|
|
|
117 |
|
118 |
# React to user input
|
119 |
if prompt := st.chat_input("What would you like to know about Tbank?"):
|
|
|
125 |
with st.chat_message("assistant"):
|
126 |
message_placeholder = st.empty()
|
127 |
|
128 |
+
# # Fuzzy match important terms
|
129 |
+
# matched_term = fuzzy_match(prompt.lower(), important_terms)
|
130 |
+
# if matched_term:
|
131 |
+
# prompt = f"{prompt} (Matched term: {matched_term})"
|
132 |
|
133 |
# Retrieve relevant documents
|
134 |
docs = retriever.get_relevant_documents(prompt)
|