Update app.py
Browse files
app.py
CHANGED
|
@@ -423,32 +423,31 @@ def upload_pdf(files):
|
|
| 423 |
logging.warning("No files uploaded.")
|
| 424 |
status_message = " Keine Dateien zum Hochladen"
|
| 425 |
else:
|
| 426 |
-
|
| 427 |
-
|
| 428 |
-
|
| 429 |
-
|
| 430 |
-
|
| 431 |
-
|
| 432 |
-
|
| 433 |
-
|
| 434 |
-
|
| 435 |
-
|
| 436 |
-
|
| 437 |
-
|
| 438 |
-
|
| 439 |
-
|
| 440 |
-
|
| 441 |
-
|
| 442 |
-
|
| 443 |
-
|
| 444 |
-
|
| 445 |
-
logging.info(f"Existing file {upload_path} removed.")
|
| 446 |
-
|
| 447 |
-
# Datei zum Hugging Face Space hochladen
|
| 448 |
-
upload_file_to_huggingface(file.name, upload_path)
|
| 449 |
|
| 450 |
-
|
| 451 |
-
|
|
|
|
|
|
|
|
|
|
| 452 |
|
| 453 |
# Nachdem alle Dateien hochgeladen wurden, den Vektorstore neu laden
|
| 454 |
try:
|
|
|
|
| 423 |
logging.warning("No files uploaded.")
|
| 424 |
status_message = " Keine Dateien zum Hochladen"
|
| 425 |
else:
|
| 426 |
+
for file in files:
|
| 427 |
+
try:
|
| 428 |
+
# Extrahieren des Dateinamens aus dem vollen Pfad
|
| 429 |
+
filename = os.path.basename(file.name)
|
| 430 |
+
|
| 431 |
+
# Extrahieren der Dateiendung
|
| 432 |
+
file_extension = os.path.splitext(filename)[1]
|
| 433 |
+
# Bestimmen des Upload-Pfads basierend auf der Dateiendung
|
| 434 |
+
if file_extension == ".pdf":
|
| 435 |
+
upload_path = f"chroma/kkg/pdf/{filename}"
|
| 436 |
+
elif file_extension == ".docx":
|
| 437 |
+
upload_path = f"chroma/kkg/word/{filename}"
|
| 438 |
+
else:
|
| 439 |
+
upload_path = f"chroma/kkg/{filename}"
|
| 440 |
+
|
| 441 |
+
# Entfernen der vorhandenen Datei, falls sie existiert
|
| 442 |
+
if os.path.exists(upload_path):
|
| 443 |
+
os.remove(upload_path)
|
| 444 |
+
logging.info(f"Existing file {upload_path} removed.")
|
|
|
|
|
|
|
|
|
|
|
|
|
| 445 |
|
| 446 |
+
# Datei zum Hugging Face Space hochladen
|
| 447 |
+
upload_file_to_huggingface(file.name, upload_path)
|
| 448 |
+
|
| 449 |
+
except Exception as e:
|
| 450 |
+
logging.error(f"Error uploading file {file.name}: {e}")
|
| 451 |
|
| 452 |
# Nachdem alle Dateien hochgeladen wurden, den Vektorstore neu laden
|
| 453 |
try:
|