Spaces:
Runtime error
Runtime error
Commit ·
1ff6edf
1
Parent(s): ef6d41e
updating chunking
Browse files
app.py
CHANGED
|
@@ -5,11 +5,13 @@ import time
|
|
| 5 |
from langchain.document_loaders import OnlinePDFLoader
|
| 6 |
from langchain.document_loaders import PyPDFLoader
|
| 7 |
|
| 8 |
-
from langchain.text_splitter import CharacterTextSplitter
|
| 9 |
from langchain.llms import OpenAI
|
| 10 |
from langchain.embeddings import OpenAIEmbeddings
|
| 11 |
from langchain.vectorstores import Chroma
|
| 12 |
from langchain.chains import ConversationalRetrievalChain
|
|
|
|
|
|
|
| 13 |
|
| 14 |
def loading_pdf():
|
| 15 |
return "Loading..."
|
|
@@ -27,12 +29,24 @@ def pdf_changes(pdf_doc = None, open_ai_key=None):
|
|
| 27 |
# prepare data for pdf loads, not a fan of the chunk size and overlap
|
| 28 |
|
| 29 |
pdf_path = "investor_ppm.pdf" #pdf_doc.name
|
| 30 |
-
loader =
|
| 31 |
documents = loader.load()
|
| 32 |
-
text_splitter =
|
| 33 |
texts = text_splitter.split_documents(documents)
|
| 34 |
|
| 35 |
# create embeddings, should download and store somewhere safe
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 36 |
embeddings = OpenAIEmbeddings()
|
| 37 |
db = Chroma.from_documents(texts, embeddings)
|
| 38 |
|
|
@@ -72,9 +86,7 @@ def infer(question, history):
|
|
| 72 |
|
| 73 |
chat_history = res
|
| 74 |
#print(chat_history)
|
| 75 |
-
query = question
|
| 76 |
-
English: \
|
| 77 |
-
Chinese (Simplified):"
|
| 78 |
|
| 79 |
result = qa({"question": query, "chat_history": chat_history})
|
| 80 |
#print(result)
|
|
|
|
| 5 |
from langchain.document_loaders import OnlinePDFLoader
|
| 6 |
from langchain.document_loaders import PyPDFLoader
|
| 7 |
|
| 8 |
+
from langchain.text_splitter import CharacterTextSplitter, RecursiveCharacterTextSplitter
|
| 9 |
from langchain.llms import OpenAI
|
| 10 |
from langchain.embeddings import OpenAIEmbeddings
|
| 11 |
from langchain.vectorstores import Chroma
|
| 12 |
from langchain.chains import ConversationalRetrievalChain
|
| 13 |
+
from langchain.prompts import PromptTemplate
|
| 14 |
+
|
| 15 |
|
| 16 |
def loading_pdf():
|
| 17 |
return "Loading..."
|
|
|
|
| 29 |
# prepare data for pdf loads, not a fan of the chunk size and overlap
|
| 30 |
|
| 31 |
pdf_path = "investor_ppm.pdf" #pdf_doc.name
|
| 32 |
+
loader = PyPDFLoader(pdf_path)
|
| 33 |
documents = loader.load()
|
| 34 |
+
text_splitter = RecursiveCharacterTextSplitter(chunk_size=1000, chunk_overlap=100)
|
| 35 |
texts = text_splitter.split_documents(documents)
|
| 36 |
|
| 37 |
# create embeddings, should download and store somewhere safe
|
| 38 |
+
"""
|
| 39 |
+
persist_directory = "docs/chroma"
|
| 40 |
+
|
| 41 |
+
embedding = OpenAIEmbeddings()
|
| 42 |
+
|
| 43 |
+
# translates into embeddings
|
| 44 |
+
vectordb = Chroma(
|
| 45 |
+
persist_directory=persist_directory,
|
| 46 |
+
embedding_function=embedding
|
| 47 |
+
)
|
| 48 |
+
"""
|
| 49 |
+
|
| 50 |
embeddings = OpenAIEmbeddings()
|
| 51 |
db = Chroma.from_documents(texts, embeddings)
|
| 52 |
|
|
|
|
| 86 |
|
| 87 |
chat_history = res
|
| 88 |
#print(chat_history)
|
| 89 |
+
query = question
|
|
|
|
|
|
|
| 90 |
|
| 91 |
result = qa({"question": query, "chat_history": chat_history})
|
| 92 |
#print(result)
|