Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -1,4 +1,5 @@
|
|
1 |
import streamlit as st
|
|
|
2 |
import pickle
|
3 |
from PyPDF2 import PdfReader
|
4 |
from streamlit_extras.add_vertical_space import add_vertical_space
|
@@ -99,10 +100,16 @@ def main():
|
|
99 |
VectorStore = load_pdf(pdf)
|
100 |
max_tokens = 100 # Initial max tokens
|
101 |
chain = load_chatbot(max_tokens=max_tokens)
|
102 |
-
docs = VectorStore.similarity_search(query=query, k=
|
103 |
with get_openai_callback() as cb:
|
104 |
response = chain.run(input_documents=docs, question=query)
|
|
|
105 |
|
|
|
|
|
|
|
|
|
|
|
106 |
# Check if the response ends with a sentence-ending punctuation
|
107 |
while not response.strip().endswith(('.', '!', '?')) and max_tokens < MAX_TOKEN_LIMIT:
|
108 |
max_tokens += 50 # Increase the max_tokens limit
|
|
|
1 |
import streamlit as st
|
2 |
+
import re
|
3 |
import pickle
|
4 |
from PyPDF2 import PdfReader
|
5 |
from streamlit_extras.add_vertical_space import add_vertical_space
|
|
|
100 |
VectorStore = load_pdf(pdf)
|
101 |
max_tokens = 100 # Initial max tokens
|
102 |
chain = load_chatbot(max_tokens=max_tokens)
|
103 |
+
docs = VectorStore.similarity_search(query=query, k=1)
|
104 |
with get_openai_callback() as cb:
|
105 |
response = chain.run(input_documents=docs, question=query)
|
106 |
+
|
107 |
|
108 |
+
# Filtering similar responses (a simple example using set to remove duplicate sentences)
|
109 |
+
response_sentences = response.split('. ')
|
110 |
+
unique_sentences = set(response_sentences)
|
111 |
+
filtered_response = '. '.join(unique_sentences)
|
112 |
+
|
113 |
# Check if the response ends with a sentence-ending punctuation
|
114 |
while not response.strip().endswith(('.', '!', '?')) and max_tokens < MAX_TOKEN_LIMIT:
|
115 |
max_tokens += 50 # Increase the max_tokens limit
|