Update app.py
Browse files
app.py
CHANGED
@@ -393,28 +393,32 @@ async def upload_pdf(file):
|
|
393 |
"""
|
394 |
|
395 |
def upload_pdf(files):
|
396 |
-
if files
|
397 |
-
return
|
|
|
398 |
for file in files:
|
399 |
-
|
400 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
401 |
|
402 |
-
|
403 |
-
|
404 |
-
|
405 |
-
|
406 |
-
|
407 |
-
|
408 |
-
|
409 |
-
|
410 |
-
upload_path = f"chroma/kkg/{filename}"
|
411 |
-
|
412 |
-
# Datei zum Hugging Face Space hochladen
|
413 |
-
upload_file_to_huggingface(file.name, upload_path)
|
414 |
-
############################################
|
415 |
-
#Vektorstore neu....
|
416 |
-
############################################
|
417 |
-
#create_vectorstore()
|
418 |
|
419 |
return f"Dateien erfolgreich hochgeladen.", display_files()
|
420 |
|
|
|
393 |
"""
|
394 |
|
395 |
def upload_pdf(files):
|
396 |
+
if not files:
|
397 |
+
return "Keine Dateien hochgeladen.", display_files()
|
398 |
+
|
399 |
for file in files:
|
400 |
+
try:
|
401 |
+
# Extrahieren des Dateinamens aus dem vollen Pfad
|
402 |
+
filename = os.path.basename(file.name)
|
403 |
+
|
404 |
+
# Extrahieren der Dateiendung
|
405 |
+
file_extension = os.path.splitext(filename)[1]
|
406 |
+
# Bestimmen des Upload-Pfads basierend auf der Dateiendung
|
407 |
+
if file_extension == ".pdf":
|
408 |
+
upload_path = f"chroma/kkg/pdf/{filename}"
|
409 |
+
elif file_extension == ".docx":
|
410 |
+
upload_path = f"chroma/kkg/word/{filename}"
|
411 |
+
else:
|
412 |
+
upload_path = f"chroma/kkg/{filename}"
|
413 |
|
414 |
+
# Datei zum Hugging Face Space hochladen
|
415 |
+
upload_file_to_huggingface(file.name, upload_path)
|
416 |
+
############################################
|
417 |
+
#Vektorstore neu....
|
418 |
+
############################################
|
419 |
+
#create_vectorstore()
|
420 |
+
except Exception as e:
|
421 |
+
logging.error(f"Error uploading file {file.name}: {e}")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
422 |
|
423 |
return f"Dateien erfolgreich hochgeladen.", display_files()
|
424 |
|