Spaces:
Runtime error
Runtime error
Commit
·
e6fff0b
1
Parent(s):
64722c6
pep 8
Browse files
app.py
CHANGED
|
@@ -2,7 +2,7 @@ import time
|
|
| 2 |
import streamlit as st
|
| 3 |
from PyPDF2 import PdfReader
|
| 4 |
from langchain.text_splitter import CharacterTextSplitter
|
| 5 |
-
from langchain.embeddings import OpenAIEmbeddings
|
| 6 |
from langchain.vectorstores import FAISS
|
| 7 |
from langchain.chat_models import ChatOpenAI
|
| 8 |
from langchain.memory import ConversationBufferMemory
|
|
@@ -112,16 +112,11 @@ def handle_userinput(user_question):
|
|
| 112 |
# Display AI response
|
| 113 |
st.write(bot_template.replace("{{MSG}}", message.content), unsafe_allow_html=True)
|
| 114 |
|
| 115 |
-
# THIS DOESNT WORK, SOMEONE PLS FIX
|
| 116 |
-
# Display source document information if available in the message
|
| 117 |
-
if hasattr(message, 'source') and message.source:
|
| 118 |
-
st.write(f"Source Document: {message.source}", unsafe_allow_html=True)
|
| 119 |
-
|
| 120 |
|
| 121 |
def safe_vec_store():
|
| 122 |
# USE VECTARA INSTEAD
|
| 123 |
os.makedirs('vectorstore', exist_ok=True)
|
| 124 |
-
filename = '
|
| 125 |
file_path = os.path.join('vectorstore', filename)
|
| 126 |
vector_store = st.session_state.vectorstore
|
| 127 |
|
|
@@ -131,18 +126,21 @@ def safe_vec_store():
|
|
| 131 |
|
| 132 |
|
| 133 |
def main():
|
| 134 |
-
st.set_page_config(page_title="Doc Verify RAG", page_icon=":
|
| 135 |
st.write(css, unsafe_allow_html=True)
|
|
|
|
|
|
|
| 136 |
if "openai_api_key" not in st.session_state:
|
| 137 |
st.session_state.openai_api_key = False
|
| 138 |
if "openai_org" not in st.session_state:
|
| 139 |
st.session_state.openai_org = False
|
| 140 |
if "classify" not in st.session_state:
|
| 141 |
st.session_state.classify = False
|
|
|
|
| 142 |
def set_pw():
|
| 143 |
st.session_state.openai_api_key = True
|
|
|
|
| 144 |
st.subheader("Your documents")
|
| 145 |
-
# OPENAI_ORG_ID = st.text_input("OPENAI ORG ID:")
|
| 146 |
OPENAI_API_KEY = st.text_input("OPENAI API KEY:", type="password",
|
| 147 |
disabled=st.session_state.openai_api_key, on_change=set_pw)
|
| 148 |
if st.session_state.classify:
|
|
@@ -179,19 +177,18 @@ def main():
|
|
| 179 |
st.session_state.conversation = get_conversation_chain(vec)
|
| 180 |
st.success("data loaded")
|
| 181 |
|
| 182 |
-
|
| 183 |
if "conversation" not in st.session_state:
|
| 184 |
st.session_state.conversation = None
|
| 185 |
if "chat_history" not in st.session_state:
|
| 186 |
st.session_state.chat_history = None
|
| 187 |
|
| 188 |
-
st.header("Doc Verify RAG :hospital:")
|
| 189 |
user_question = st.text_input("Ask a question about your documents:")
|
| 190 |
if user_question:
|
| 191 |
handle_userinput(user_question)
|
| 192 |
with st.sidebar:
|
| 193 |
-
st.subheader("Classification
|
| 194 |
-
classifier_docs = st.file_uploader("Upload your instructions here and click on 'Process'",
|
|
|
|
| 195 |
filenames = [file.name for file in classifier_docs if file is not None]
|
| 196 |
|
| 197 |
if st.button("Process Classification"):
|
|
@@ -200,8 +197,6 @@ def main():
|
|
| 200 |
st.warning("set classify")
|
| 201 |
time.sleep(3)
|
| 202 |
|
| 203 |
-
|
| 204 |
-
# Save and Load Embeddings
|
| 205 |
if st.button("Save Embeddings"):
|
| 206 |
if "vectorstore" in st.session_state:
|
| 207 |
safe_vec_store()
|
|
|
|
| 2 |
import streamlit as st
|
| 3 |
from PyPDF2 import PdfReader
|
| 4 |
from langchain.text_splitter import CharacterTextSplitter
|
| 5 |
+
from langchain.embeddings import OpenAIEmbeddings
|
| 6 |
from langchain.vectorstores import FAISS
|
| 7 |
from langchain.chat_models import ChatOpenAI
|
| 8 |
from langchain.memory import ConversationBufferMemory
|
|
|
|
| 112 |
# Display AI response
|
| 113 |
st.write(bot_template.replace("{{MSG}}", message.content), unsafe_allow_html=True)
|
| 114 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 115 |
|
| 116 |
def safe_vec_store():
|
| 117 |
# USE VECTARA INSTEAD
|
| 118 |
os.makedirs('vectorstore', exist_ok=True)
|
| 119 |
+
filename = 'vectors' + datetime.now().strftime('%Y%m%d%H%M') + '.pkl'
|
| 120 |
file_path = os.path.join('vectorstore', filename)
|
| 121 |
vector_store = st.session_state.vectorstore
|
| 122 |
|
|
|
|
| 126 |
|
| 127 |
|
| 128 |
def main():
|
| 129 |
+
st.set_page_config(page_title="Doc Verify RAG", page_icon=":mag:")
|
| 130 |
st.write(css, unsafe_allow_html=True)
|
| 131 |
+
st.header("Doc Verify RAG :mag:")
|
| 132 |
+
|
| 133 |
if "openai_api_key" not in st.session_state:
|
| 134 |
st.session_state.openai_api_key = False
|
| 135 |
if "openai_org" not in st.session_state:
|
| 136 |
st.session_state.openai_org = False
|
| 137 |
if "classify" not in st.session_state:
|
| 138 |
st.session_state.classify = False
|
| 139 |
+
|
| 140 |
def set_pw():
|
| 141 |
st.session_state.openai_api_key = True
|
| 142 |
+
|
| 143 |
st.subheader("Your documents")
|
|
|
|
| 144 |
OPENAI_API_KEY = st.text_input("OPENAI API KEY:", type="password",
|
| 145 |
disabled=st.session_state.openai_api_key, on_change=set_pw)
|
| 146 |
if st.session_state.classify:
|
|
|
|
| 177 |
st.session_state.conversation = get_conversation_chain(vec)
|
| 178 |
st.success("data loaded")
|
| 179 |
|
|
|
|
| 180 |
if "conversation" not in st.session_state:
|
| 181 |
st.session_state.conversation = None
|
| 182 |
if "chat_history" not in st.session_state:
|
| 183 |
st.session_state.chat_history = None
|
| 184 |
|
|
|
|
| 185 |
user_question = st.text_input("Ask a question about your documents:")
|
| 186 |
if user_question:
|
| 187 |
handle_userinput(user_question)
|
| 188 |
with st.sidebar:
|
| 189 |
+
st.subheader("Classification instructions")
|
| 190 |
+
classifier_docs = st.file_uploader("Upload your instructions here and click on 'Process'",
|
| 191 |
+
accept_multiple_files=True)
|
| 192 |
filenames = [file.name for file in classifier_docs if file is not None]
|
| 193 |
|
| 194 |
if st.button("Process Classification"):
|
|
|
|
| 197 |
st.warning("set classify")
|
| 198 |
time.sleep(3)
|
| 199 |
|
|
|
|
|
|
|
| 200 |
if st.button("Save Embeddings"):
|
| 201 |
if "vectorstore" in st.session_state:
|
| 202 |
safe_vec_store()
|