Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -66,6 +66,21 @@ def load_document(file: NamedTemporaryFile, parser: str = "llamaparse") -> List[
|
|
66 |
def get_embeddings():
|
67 |
return HuggingFaceEmbeddings(model_name="sentence-transformers/stsb-roberta-large")
|
68 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
69 |
def update_vectors(files, parser):
|
70 |
global uploaded_documents
|
71 |
logging.info(f"Entering update_vectors with {len(files)} files and parser: {parser}")
|
@@ -78,7 +93,7 @@ def update_vectors(files, parser):
|
|
78 |
label="Select documents to query"
|
79 |
)
|
80 |
|
81 |
-
embed =
|
82 |
total_chunks = 0
|
83 |
|
84 |
all_data = []
|
@@ -111,12 +126,19 @@ def update_vectors(files, parser):
|
|
111 |
database.save_local("faiss_database")
|
112 |
logging.info("FAISS database saved")
|
113 |
|
|
|
|
|
|
|
|
|
114 |
return f"Vector store updated successfully. Processed {total_chunks} chunks from {len(files)} files using {parser}.", gr.CheckboxGroup(
|
115 |
choices=[doc["name"] for doc in uploaded_documents],
|
116 |
value=[doc["name"] for doc in uploaded_documents if doc["selected"]],
|
117 |
label="Select documents to query"
|
118 |
)
|
119 |
|
|
|
|
|
|
|
120 |
def generate_chunked_response(prompt, model, max_tokens=10000, num_calls=3, temperature=0.2, should_stop=False):
|
121 |
print(f"Starting generate_chunked_response with {num_calls} calls")
|
122 |
full_response = ""
|
|
|
66 |
def get_embeddings():
|
67 |
return HuggingFaceEmbeddings(model_name="sentence-transformers/stsb-roberta-large")
|
68 |
|
69 |
+
# File to store the list of uploaded documents
|
70 |
+
DOCUMENTS_FILE = "uploaded_documents.json"
|
71 |
+
|
72 |
+
def load_uploaded_documents():
|
73 |
+
global uploaded_documents
|
74 |
+
if os.path.exists(DOCUMENTS_FILE):
|
75 |
+
with open(DOCUMENTS_FILE, 'r') as f:
|
76 |
+
uploaded_documents = json.load(f)
|
77 |
+
else:
|
78 |
+
uploaded_documents = []
|
79 |
+
|
80 |
+
def save_uploaded_documents():
|
81 |
+
with open(DOCUMENTS_FILE, 'w') as f:
|
82 |
+
json.dump(uploaded_documents, f)
|
83 |
+
|
84 |
def update_vectors(files, parser):
|
85 |
global uploaded_documents
|
86 |
logging.info(f"Entering update_vectors with {len(files)} files and parser: {parser}")
|
|
|
93 |
label="Select documents to query"
|
94 |
)
|
95 |
|
96 |
+
embed = HuggingFaceEmbeddings(model_name="sentence-transformers/stsb-roberta-large")
|
97 |
total_chunks = 0
|
98 |
|
99 |
all_data = []
|
|
|
126 |
database.save_local("faiss_database")
|
127 |
logging.info("FAISS database saved")
|
128 |
|
129 |
+
# Save the updated list of documents
|
130 |
+
save_uploaded_documents()
|
131 |
+
logging.info("Uploaded documents list saved")
|
132 |
+
|
133 |
return f"Vector store updated successfully. Processed {total_chunks} chunks from {len(files)} files using {parser}.", gr.CheckboxGroup(
|
134 |
choices=[doc["name"] for doc in uploaded_documents],
|
135 |
value=[doc["name"] for doc in uploaded_documents if doc["selected"]],
|
136 |
label="Select documents to query"
|
137 |
)
|
138 |
|
139 |
+
# Make sure to call this function at the start of your script
|
140 |
+
load_uploaded_documents()
|
141 |
+
|
142 |
def generate_chunked_response(prompt, model, max_tokens=10000, num_calls=3, temperature=0.2, should_stop=False):
|
143 |
print(f"Starting generate_chunked_response with {num_calls} calls")
|
144 |
full_response = ""
|