use qdrant instead
Browse files
app.py
CHANGED
@@ -6,6 +6,8 @@ from langchain.document_loaders import TextLoader
|
|
6 |
from langchain.text_splitter import CharacterTextSplitter
|
7 |
from langchain.embeddings import OpenAIEmbeddings
|
8 |
from langchain.vectorstores import FAISS
|
|
|
|
|
9 |
from langchain.memory import ConversationBufferMemory
|
10 |
from langchain.document_loaders import TextLoader
|
11 |
from tempfile import NamedTemporaryFile
|
@@ -15,11 +17,13 @@ def main():
|
|
15 |
# Initialize the Streamlit app
|
16 |
st.title('Document-Based Q&A System')
|
17 |
|
18 |
-
# API Key input securely
|
19 |
-
|
20 |
-
if api_key:
|
21 |
-
os.environ["OPENAI_API_KEY"] = api_key
|
22 |
-
st.success("API Key has been set!")
|
|
|
|
|
23 |
|
24 |
# File uploader
|
25 |
uploaded_file = st.file_uploader("Upload your document", type=['txt'])
|
@@ -35,9 +39,15 @@ def main():
|
|
35 |
data = text_splitter.split_documents(data)
|
36 |
|
37 |
# Create vector store
|
|
|
38 |
embeddings = OpenAIEmbeddings()
|
39 |
-
vectorstore = FAISS.from_documents(data, embedding=embeddings)
|
40 |
-
|
|
|
|
|
|
|
|
|
|
|
41 |
# Create conversation chain
|
42 |
llm = ChatOpenAI(temperature=0.3, model_name="gpt-4-turbo")
|
43 |
memory = ConversationBufferMemory(
|
|
|
6 |
from langchain.text_splitter import CharacterTextSplitter
|
7 |
from langchain.embeddings import OpenAIEmbeddings
|
8 |
from langchain.vectorstores import FAISS
|
9 |
+
from langchain_community.vectorstores import Qdrant
|
10 |
+
|
11 |
from langchain.memory import ConversationBufferMemory
|
12 |
from langchain.document_loaders import TextLoader
|
13 |
from tempfile import NamedTemporaryFile
|
|
|
17 |
# Initialize the Streamlit app
|
18 |
st.title('Document-Based Q&A System')
|
19 |
|
20 |
+
# API Key input securely, API KEY defined in settings
|
21 |
+
# api_key = st.text_input("Enter your OpenAI API key:", type="password")
|
22 |
+
# if api_key:
|
23 |
+
# os.environ["OPENAI_API_KEY"] = api_key
|
24 |
+
# st.success("API Key has been set!")
|
25 |
+
|
26 |
+
|
27 |
|
28 |
# File uploader
|
29 |
uploaded_file = st.file_uploader("Upload your document", type=['txt'])
|
|
|
39 |
data = text_splitter.split_documents(data)
|
40 |
|
41 |
# Create vector store
|
42 |
+
|
43 |
embeddings = OpenAIEmbeddings()
|
44 |
+
#vectorstore = FAISS.from_documents(data, embedding=embeddings)
|
45 |
+
vectorstore = Qdrant.from_documents(
|
46 |
+
data,
|
47 |
+
embeddings,
|
48 |
+
location=":memory:", # Local mode with in-memory storage only
|
49 |
+
collection_name="my_documents",
|
50 |
+
)
|
51 |
# Create conversation chain
|
52 |
llm = ChatOpenAI(temperature=0.3, model_name="gpt-4-turbo")
|
53 |
memory = ConversationBufferMemory(
|