Spaces:
Runtime error
Runtime error
deepozzzie
commited on
Commit
·
752610d
1
Parent(s):
d862e0f
all
Browse files
app.py
CHANGED
@@ -17,31 +17,26 @@ from langchain.vectorstores import Chroma
|
|
17 |
from langchain.chains import ConversationalRetrievalChain
|
18 |
|
19 |
def loading_pdf():
|
|
|
20 |
return "Loading..."
|
21 |
|
22 |
def pdf_changes(pdf_doc, open_ai_key):
|
|
|
23 |
if openai_key is not None:
|
24 |
os.environ['OPENAI_API_KEY'] = open_ai_key
|
25 |
loader = OnlinePDFLoader(pdf_doc.name)
|
26 |
-
print('loader\n\n\n')
|
27 |
print(loader)
|
28 |
documents = loader.load()
|
29 |
-
print('documents\n\n\n')
|
30 |
print(documents)
|
31 |
text_splitter = CharacterTextSplitter(chunk_size=1000, chunk_overlap=0)
|
32 |
-
print('splitter\n\n\n')
|
33 |
print(text_splitter)
|
34 |
texts = text_splitter.split_documents(documents)
|
35 |
-
print('texts\n\n\n')
|
36 |
print(texts)
|
37 |
embeddings = OpenAIEmbeddings()
|
38 |
-
print('embeddings\n\n\n')
|
39 |
print(embeddings)
|
40 |
db = Chroma.from_documents(texts, embeddings)
|
41 |
-
print('db\n\n\n')
|
42 |
print(db)
|
43 |
retriever = db.as_retriever()
|
44 |
-
print('retriever\n\n\n')
|
45 |
print(retriever)
|
46 |
global qa
|
47 |
qa = ConversationalRetrievalChain.from_llm(
|
@@ -59,15 +54,11 @@ def add_text(history, text):
|
|
59 |
|
60 |
def bot(history):
|
61 |
response = infer(history[-1][0], history)
|
62 |
-
print('bot response:')
|
63 |
-
print(response)
|
64 |
history[-1][1] = ""
|
65 |
|
66 |
for character in response:
|
67 |
history[-1][1] += character
|
68 |
-
print("history")
|
69 |
time.sleep(0.05)
|
70 |
-
print(history)
|
71 |
yield history
|
72 |
|
73 |
|
@@ -83,8 +74,6 @@ def infer(question, history):
|
|
83 |
query = question
|
84 |
result = qa({"question": query, "chat_history": chat_history})
|
85 |
#print(result)
|
86 |
-
print("infer result")
|
87 |
-
print(result)
|
88 |
return result["answer"]
|
89 |
|
90 |
css="""
|
|
|
17 |
from langchain.chains import ConversationalRetrievalChain
|
18 |
|
19 |
def loading_pdf():
|
20 |
+
print("loading_pdf")
|
21 |
return "Loading..."
|
22 |
|
23 |
def pdf_changes(pdf_doc, open_ai_key):
|
24 |
+
print("pdf_change")
|
25 |
if openai_key is not None:
|
26 |
os.environ['OPENAI_API_KEY'] = open_ai_key
|
27 |
loader = OnlinePDFLoader(pdf_doc.name)
|
|
|
28 |
print(loader)
|
29 |
documents = loader.load()
|
|
|
30 |
print(documents)
|
31 |
text_splitter = CharacterTextSplitter(chunk_size=1000, chunk_overlap=0)
|
|
|
32 |
print(text_splitter)
|
33 |
texts = text_splitter.split_documents(documents)
|
|
|
34 |
print(texts)
|
35 |
embeddings = OpenAIEmbeddings()
|
|
|
36 |
print(embeddings)
|
37 |
db = Chroma.from_documents(texts, embeddings)
|
|
|
38 |
print(db)
|
39 |
retriever = db.as_retriever()
|
|
|
40 |
print(retriever)
|
41 |
global qa
|
42 |
qa = ConversationalRetrievalChain.from_llm(
|
|
|
54 |
|
55 |
def bot(history):
|
56 |
response = infer(history[-1][0], history)
|
|
|
|
|
57 |
history[-1][1] = ""
|
58 |
|
59 |
for character in response:
|
60 |
history[-1][1] += character
|
|
|
61 |
time.sleep(0.05)
|
|
|
62 |
yield history
|
63 |
|
64 |
|
|
|
74 |
query = question
|
75 |
result = qa({"question": query, "chat_history": chat_history})
|
76 |
#print(result)
|
|
|
|
|
77 |
return result["answer"]
|
78 |
|
79 |
css="""
|