Update app.py
Browse files
app.py
CHANGED
@@ -363,38 +363,39 @@ def generate_auswahl(prompt_in, file, file_history, chatbot, history, anzahl_doc
|
|
363 |
def upload_pdf(files):
|
364 |
if not files:
|
365 |
logging.warning("No files uploaded.")
|
366 |
-
|
367 |
-
|
368 |
-
|
369 |
-
|
370 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
371 |
try:
|
372 |
-
|
373 |
-
|
374 |
-
|
375 |
-
# Extrahieren der Dateiendung
|
376 |
-
file_extension = os.path.splitext(filename)[1]
|
377 |
-
# Bestimmen des Upload-Pfads basierend auf der Dateiendung
|
378 |
-
if file_extension == ".pdf":
|
379 |
-
upload_path = f"chroma/kkg/pdf/{filename}"
|
380 |
-
elif file_extension == ".docx":
|
381 |
-
upload_path = f"chroma/kkg/word/{filename}"
|
382 |
-
else:
|
383 |
-
upload_path = f"chroma/kkg/{filename}"
|
384 |
-
|
385 |
-
# Hochladen der Datei
|
386 |
-
future = pool.submit(upload_file_to_huggingface, file.name, upload_path)
|
387 |
-
futures.append(future)
|
388 |
except Exception as e:
|
389 |
-
logging.error(f"Error
|
390 |
-
|
391 |
-
# Warten, bis alle Uploads abgeschlossen sind
|
392 |
-
for future in futures:
|
393 |
-
try:
|
394 |
-
future.result()
|
395 |
-
except Exception as e:
|
396 |
-
logging.error(f"Error during file upload: {e}")
|
397 |
-
status_message = "Fehler beim Hochladen der Dateien."
|
398 |
|
399 |
# Nachdem alle Dateien hochgeladen wurden, den Vektorstore neu laden
|
400 |
try:
|
@@ -403,10 +404,10 @@ def upload_pdf(files):
|
|
403 |
############################################
|
404 |
create_vectorstore()
|
405 |
logging.info("Vektorstore successfully renewed.")
|
406 |
-
status_message
|
407 |
except Exception as e:
|
408 |
logging.error(f"Error renewing Vektorstore: {e}")
|
409 |
-
status_message
|
410 |
|
411 |
return status_message, display_files()
|
412 |
|
|
|
363 |
def upload_pdf(files):
|
364 |
if not files:
|
365 |
logging.warning("No files uploaded.")
|
366 |
+
status_message = " Keine Dateien zum Hochladen"
|
367 |
+
else:
|
368 |
+
futures = []
|
369 |
+
with ThreadPoolExecutor() as pool:
|
370 |
+
for file in files:
|
371 |
+
try:
|
372 |
+
# Extrahieren des Dateinamens aus dem vollen Pfad
|
373 |
+
filename = os.path.basename(file.name)
|
374 |
+
|
375 |
+
# Extrahieren der Dateiendung
|
376 |
+
file_extension = os.path.splitext(filename)[1]
|
377 |
+
# Bestimmen des Upload-Pfads basierend auf der Dateiendung
|
378 |
+
if file_extension == ".pdf":
|
379 |
+
upload_path = f"chroma/kkg/pdf/{filename}"
|
380 |
+
elif file_extension == ".docx":
|
381 |
+
upload_path = f"chroma/kkg/word/{filename}"
|
382 |
+
else:
|
383 |
+
upload_path = f"chroma/kkg/{filename}"
|
384 |
+
|
385 |
+
# Hochladen der Datei
|
386 |
+
future = pool.submit(upload_file_to_huggingface, file.name, upload_path)
|
387 |
+
futures.append(future)
|
388 |
+
except Exception as e:
|
389 |
+
logging.error(f"Error preparing upload for file {file.name}: {e}")
|
390 |
+
|
391 |
+
# Warten, bis alle Uploads abgeschlossen sind
|
392 |
+
for future in futures:
|
393 |
try:
|
394 |
+
future.result()
|
395 |
+
status_message = "Dateien fertig hochgeladen"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
396 |
except Exception as e:
|
397 |
+
logging.error(f"Error during file upload: {e}")
|
398 |
+
status_message = "Fehler beim Hochladen der Dateien."
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
399 |
|
400 |
# Nachdem alle Dateien hochgeladen wurden, den Vektorstore neu laden
|
401 |
try:
|
|
|
404 |
############################################
|
405 |
create_vectorstore()
|
406 |
logging.info("Vektorstore successfully renewed.")
|
407 |
+
status_message += " - Vektorstore wurde erneuert."
|
408 |
except Exception as e:
|
409 |
logging.error(f"Error renewing Vektorstore: {e}")
|
410 |
+
status_message += " - Fehler beim Erneuern des Vektorstores."
|
411 |
|
412 |
return status_message, display_files()
|
413 |
|