Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -72,6 +72,23 @@ def load_db():
|
|
72 |
embedding_function=embedding)
|
73 |
return vectordb
|
74 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
75 |
|
76 |
# Initialize langchain LLM chain
|
77 |
def initialize_llmchain(llm_model, temperature, max_tokens, top_k, vector_db, progress=gr.Progress()):
|
@@ -217,13 +234,39 @@ def initialize_database(list_file_obj, chunk_size, chunk_overlap, progress=gr.Pr
|
|
217 |
progress(0.25, desc="Caricamento documenti..")
|
218 |
# Load document and create splits
|
219 |
doc_splits = load_doc(list_file_path, chunk_size, chunk_overlap)
|
|
|
220 |
# Create or load vector database
|
221 |
-
progress(0.5, desc="Generazione vector database...")
|
222 |
# global vector_db
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
223 |
vector_db = create_db(doc_splits, collection_name)
|
224 |
progress(0.9, desc="Fatto!")
|
225 |
-
return vector_db, collection_name, "Completato!"
|
226 |
|
|
|
227 |
|
228 |
def initialize_LLM(llm_option, llm_temperature, max_tokens, top_k, vector_db, progress=gr.Progress()):
|
229 |
# print("llm_option",llm_option)
|
|
|
72 |
embedding_function=embedding)
|
73 |
return vectordb
|
74 |
|
75 |
+
def delete_db(vectordb):
|
76 |
+
# Rimuovi tutte le raccolte
|
77 |
+
collections = vectordb.collections
|
78 |
+
for collection in collections:
|
79 |
+
print(f"Cancellando raccolta: {collection}")
|
80 |
+
vectordb.delete_collection(collection)
|
81 |
+
|
82 |
+
# Rimuovi il client ChromaDB
|
83 |
+
vectordb.client.close()
|
84 |
+
|
85 |
+
# Rimuovi il database principale
|
86 |
+
db_path = vectordb.client.path
|
87 |
+
if os.path.exists(db_path):
|
88 |
+
os.remove(db_path)
|
89 |
+
print(f"Rimosso file database principale: {db_path}")
|
90 |
+
|
91 |
+
print("Tutte le raccolte e il database sono stati completamente eliminati.")
|
92 |
|
93 |
# Initialize langchain LLM chain
|
94 |
def initialize_llmchain(llm_model, temperature, max_tokens, top_k, vector_db, progress=gr.Progress()):
|
|
|
234 |
progress(0.25, desc="Caricamento documenti..")
|
235 |
# Load document and create splits
|
236 |
doc_splits = load_doc(list_file_path, chunk_size, chunk_overlap)
|
237 |
+
|
238 |
# Create or load vector database
|
239 |
+
#progress(0.5, desc="Generazione vector database...")
|
240 |
# global vector_db
|
241 |
+
#vector_db = create_db(doc_splits, collection_name)
|
242 |
+
#progress(0.9, desc="Fatto!")
|
243 |
+
#return vector_db, collection_name, "Completato!"
|
244 |
+
|
245 |
+
# Controlla se il database esiste già
|
246 |
+
if vector_db is not None:
|
247 |
+
print("Database esistente trovato. Stiamo per eliminarlo.")
|
248 |
+
|
249 |
+
# Eliminare il database esistente
|
250 |
+
vector_db.client.close()
|
251 |
+
db_path = vector_db.client.path
|
252 |
+
if os.path.exists(db_path):
|
253 |
+
os.remove(db_path)
|
254 |
+
print(f"Rimosso file database principale: {db_path}")
|
255 |
+
|
256 |
+
# Rimuovi eventuali raccolte
|
257 |
+
collections = vector_db.collections
|
258 |
+
for collection in collections:
|
259 |
+
print(f"Cancellando raccolta: {collection}")
|
260 |
+
vector_db.delete_collection(collection)
|
261 |
+
|
262 |
+
print("Tutte le raccolte e il database sono stati completamente eliminati.")
|
263 |
+
|
264 |
+
# Creare o caricare il nuovo database
|
265 |
+
progress(0.5, desc="Generazione vector database...")
|
266 |
vector_db = create_db(doc_splits, collection_name)
|
267 |
progress(0.9, desc="Fatto!")
|
|
|
268 |
|
269 |
+
return vector_db, collection_name, "Completato!"
|
270 |
|
271 |
def initialize_LLM(llm_option, llm_temperature, max_tokens, top_k, vector_db, progress=gr.Progress()):
|
272 |
# print("llm_option",llm_option)
|