Update app.py
Browse files
app.py
CHANGED
|
@@ -12,7 +12,7 @@ embeddings = OpenAIEmbeddings()
|
|
| 12 |
|
| 13 |
from langchain.vectorstores import Chroma
|
| 14 |
|
| 15 |
-
from langchain.chains import
|
| 16 |
|
| 17 |
def loading_pdf():
|
| 18 |
return "Loading..."
|
|
@@ -24,11 +24,12 @@ def pdf_changes(pdf_doc):
|
|
| 24 |
db = Chroma.from_documents(texts, embeddings)
|
| 25 |
retriever = db.as_retriever()
|
| 26 |
global qa
|
| 27 |
-
qa =
|
| 28 |
llm=OpenAI(temperature=0.5),
|
| 29 |
-
chain_type="stuff",
|
| 30 |
retriever=retriever,
|
| 31 |
-
return_source_documents=
|
|
|
|
|
|
|
| 32 |
return "Ready"
|
| 33 |
|
| 34 |
def add_text(history, text):
|
|
@@ -43,9 +44,9 @@ def bot(history):
|
|
| 43 |
def infer(question):
|
| 44 |
|
| 45 |
query = question
|
| 46 |
-
result = qa({"query":
|
| 47 |
#print(result)
|
| 48 |
-
return result
|
| 49 |
|
| 50 |
css="""
|
| 51 |
#col-container {max-width: 700px; margin-left: auto; margin-right: auto;}
|
|
|
|
| 12 |
|
| 13 |
from langchain.vectorstores import Chroma
|
| 14 |
|
| 15 |
+
from langchain.chains import ConversationalRetrievalChain
|
| 16 |
|
| 17 |
def loading_pdf():
|
| 18 |
return "Loading..."
|
|
|
|
| 24 |
db = Chroma.from_documents(texts, embeddings)
|
| 25 |
retriever = db.as_retriever()
|
| 26 |
global qa
|
| 27 |
+
qa = ConversationalRetrievalChain.from_llm(
|
| 28 |
llm=OpenAI(temperature=0.5),
|
|
|
|
| 29 |
retriever=retriever,
|
| 30 |
+
return_source_documents=False)
|
| 31 |
+
global chat_history
|
| 32 |
+
chat_history = []
|
| 33 |
return "Ready"
|
| 34 |
|
| 35 |
def add_text(history, text):
|
|
|
|
| 44 |
def infer(question):
|
| 45 |
|
| 46 |
query = question
|
| 47 |
+
result = qa({"question": query, "chat_history": chat_history})
|
| 48 |
#print(result)
|
| 49 |
+
return result["answer"]
|
| 50 |
|
| 51 |
css="""
|
| 52 |
#col-container {max-width: 700px; margin-left: auto; margin-right: auto;}
|