Update app.py
Browse files
app.py
CHANGED
|
@@ -364,7 +364,8 @@ def upload_pdf(files):
|
|
| 364 |
if not files:
|
| 365 |
logging.warning("No files uploaded.")
|
| 366 |
return "Keine Dateien hochgeladen.", display_files()
|
| 367 |
-
|
|
|
|
| 368 |
with ThreadPoolExecutor() as pool:
|
| 369 |
for file in files:
|
| 370 |
try:
|
|
@@ -382,11 +383,35 @@ def upload_pdf(files):
|
|
| 382 |
upload_path = f"chroma/kkg/{filename}"
|
| 383 |
|
| 384 |
# Hochladen der Datei
|
| 385 |
-
pool.submit(upload_file_to_huggingface, file.name, upload_path)
|
|
|
|
| 386 |
except Exception as e:
|
| 387 |
-
logging.error(f"Error
|
| 388 |
-
|
| 389 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 390 |
|
| 391 |
"""
|
| 392 |
def upload_pdf(files):
|
|
@@ -410,13 +435,13 @@ def upload_pdf(files):
|
|
| 410 |
|
| 411 |
# Datei zum Hugging Face Space hochladen
|
| 412 |
upload_file_to_huggingface(file.name, upload_path)
|
| 413 |
-
|
| 414 |
-
#Vektorstore neu....
|
| 415 |
-
############################################
|
| 416 |
-
#create_vectorstore()
|
| 417 |
except Exception as e:
|
| 418 |
logging.error(f"Error uploading file {file.name}: {e}")
|
| 419 |
-
|
|
|
|
|
|
|
|
|
|
| 420 |
return f"Dateien erfolgreich hochgeladen.", display_files()
|
| 421 |
"""
|
| 422 |
|
|
@@ -593,15 +618,15 @@ with gr.Blocks(css=customCSS, theme=themeAlex) as demo:
|
|
| 593 |
with gr.Tab("Datei hochladen"):
|
| 594 |
upload_pdf_files = gr.Files(label="PDF- oder Word-Dateien hochladen", file_count="multiple")
|
| 595 |
output_text = gr.Textbox(label="Status")
|
| 596 |
-
renew_button = gr.Button("
|
| 597 |
file_list = gr.HTML(elem_id="file_list", show_label=False)
|
| 598 |
|
| 599 |
|
| 600 |
|
| 601 |
# Automatisches Ausführen der Upload-Funktion, wenn eine Datei hochgeladen wird
|
| 602 |
#upload_pdf_file.change(fn=upload_pdf, inputs=upload_pdf_file, outputs=output_text)
|
| 603 |
-
upload_pdf_files.change(fn=upload_pdf, inputs=upload_pdf_files, outputs=[output_text, file_list]) #, postprocess=display_files)
|
| 604 |
-
renew_button.click(fn=
|
| 605 |
#gr.HTML(update=display_files, elem_id="file_list", show_label=False)
|
| 606 |
demo.load(display_files, outputs=file_list)
|
| 607 |
|
|
|
|
| 364 |
if not files:
|
| 365 |
logging.warning("No files uploaded.")
|
| 366 |
return "Keine Dateien hochgeladen.", display_files()
|
| 367 |
+
|
| 368 |
+
futures = []
|
| 369 |
with ThreadPoolExecutor() as pool:
|
| 370 |
for file in files:
|
| 371 |
try:
|
|
|
|
| 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 as_completed(futures):
|
| 393 |
+
try:
|
| 394 |
+
future.result()
|
| 395 |
+
except Exception as e:
|
| 396 |
+
logging.error(f"Error during file upload: {e}")
|
| 397 |
+
|
| 398 |
+
# Nachdem alle Dateien hochgeladen wurden, den Vektorstore neu laden
|
| 399 |
+
try:
|
| 400 |
+
############################################
|
| 401 |
+
#Vektorstore neu....
|
| 402 |
+
############################################
|
| 403 |
+
create_and_save_vectorstore()
|
| 404 |
+
logging.info("Vektorstore successfully renewed.")
|
| 405 |
+
status_message = "Dateien wurden erfolgreich hochgeladen und Vektorstore wurde erneuert."
|
| 406 |
+
except Exception as e:
|
| 407 |
+
logging.error(f"Error renewing Vektorstore: {e}")
|
| 408 |
+
status_message = "Fehler beim Erneuern des Vektorstores."
|
| 409 |
+
|
| 410 |
+
return status_message, display_files()
|
| 411 |
+
|
| 412 |
+
|
| 413 |
+
|
| 414 |
+
|
| 415 |
|
| 416 |
"""
|
| 417 |
def upload_pdf(files):
|
|
|
|
| 435 |
|
| 436 |
# Datei zum Hugging Face Space hochladen
|
| 437 |
upload_file_to_huggingface(file.name, upload_path)
|
| 438 |
+
|
|
|
|
|
|
|
|
|
|
| 439 |
except Exception as e:
|
| 440 |
logging.error(f"Error uploading file {file.name}: {e}")
|
| 441 |
+
############################################
|
| 442 |
+
#Vektorstore neu....
|
| 443 |
+
############################################
|
| 444 |
+
#create_vectorstore()
|
| 445 |
return f"Dateien erfolgreich hochgeladen.", display_files()
|
| 446 |
"""
|
| 447 |
|
|
|
|
| 618 |
with gr.Tab("Datei hochladen"):
|
| 619 |
upload_pdf_files = gr.Files(label="PDF- oder Word-Dateien hochladen", file_count="multiple")
|
| 620 |
output_text = gr.Textbox(label="Status")
|
| 621 |
+
renew_button = gr.Button("Dateien hochladen", elem_id="renew_button")
|
| 622 |
file_list = gr.HTML(elem_id="file_list", show_label=False)
|
| 623 |
|
| 624 |
|
| 625 |
|
| 626 |
# Automatisches Ausführen der Upload-Funktion, wenn eine Datei hochgeladen wird
|
| 627 |
#upload_pdf_file.change(fn=upload_pdf, inputs=upload_pdf_file, outputs=output_text)
|
| 628 |
+
#upload_pdf_files.change(fn=upload_pdf, inputs=upload_pdf_files, outputs=[output_text, file_list]) #, postprocess=display_files)
|
| 629 |
+
renew_button.click(fn=upload_pdf, inputs=upload_pdf_files, outputs=[output_text, file_list])
|
| 630 |
#gr.HTML(update=display_files, elem_id="file_list", show_label=False)
|
| 631 |
demo.load(display_files, outputs=file_list)
|
| 632 |
|