Commit
·
c283844
1
Parent(s):
a2de0a4
print summary in bot field
Browse files
app.py
CHANGED
@@ -52,6 +52,7 @@ def pdf_changes(pdf_doc):
|
|
52 |
)
|
53 |
|
54 |
# Generate summary using StuffDocumentsChain
|
|
|
55 |
full_summary = stuff_chain.run(documents)
|
56 |
|
57 |
# Other existing logic for Chroma, embeddings, and retrieval
|
@@ -67,7 +68,7 @@ def pdf_changes(pdf_doc):
|
|
67 |
return_source_documents=False
|
68 |
)
|
69 |
|
70 |
-
return f"Ready. Full Summary
|
71 |
|
72 |
except Exception as e:
|
73 |
return f"Error processing PDF: {str(e)}"
|
@@ -87,12 +88,18 @@ def add_text(history, text):
|
|
87 |
return history, ""
|
88 |
|
89 |
def bot(history):
|
90 |
-
|
|
|
|
|
|
|
|
|
|
|
91 |
sentences = ' \n'.join(response.split('. '))
|
92 |
formatted_response = f"**Bot:**\n\n{sentences}"
|
93 |
history[-1][1] = formatted_response
|
94 |
return history
|
95 |
|
|
|
96 |
def infer(question, history):
|
97 |
try:
|
98 |
res = []
|
|
|
52 |
)
|
53 |
|
54 |
# Generate summary using StuffDocumentsChain
|
55 |
+
global full_summary
|
56 |
full_summary = stuff_chain.run(documents)
|
57 |
|
58 |
# Other existing logic for Chroma, embeddings, and retrieval
|
|
|
68 |
return_source_documents=False
|
69 |
)
|
70 |
|
71 |
+
return f"Ready. Full Summary loaded."
|
72 |
|
73 |
except Exception as e:
|
74 |
return f"Error processing PDF: {str(e)}"
|
|
|
88 |
return history, ""
|
89 |
|
90 |
def bot(history):
|
91 |
+
global full_summary
|
92 |
+
if 'summary' in history[-1][0].lower(): # Check if the last question asks for a summary
|
93 |
+
response = full_summary
|
94 |
+
else:
|
95 |
+
response = infer(history[-1][0], history)
|
96 |
+
|
97 |
sentences = ' \n'.join(response.split('. '))
|
98 |
formatted_response = f"**Bot:**\n\n{sentences}"
|
99 |
history[-1][1] = formatted_response
|
100 |
return history
|
101 |
|
102 |
+
|
103 |
def infer(question, history):
|
104 |
try:
|
105 |
res = []
|