Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -98,15 +98,22 @@ def embedder(uploaded_file_path):
|
|
| 98 |
)
|
| 99 |
documents = text_splitter.split_documents(raw_documents)
|
| 100 |
|
| 101 |
-
# ---
|
| 102 |
-
# 1.
|
| 103 |
-
sanitized_filename = original_filename.replace('.pdf', '').lower()
|
| 104 |
-
|
| 105 |
-
|
| 106 |
-
|
| 107 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 108 |
uuids = [f"{sanitized_filename}-{i}" for i in range(len(documents))]
|
| 109 |
-
# ---
|
| 110 |
|
| 111 |
batch_size = 100
|
| 112 |
for i in range(0, len(documents), batch_size):
|
|
@@ -120,7 +127,6 @@ def embedder(uploaded_file_path):
|
|
| 120 |
return f"Unable to create embeddings: {str(e)}", get_files_df()
|
| 121 |
|
| 122 |
|
| 123 |
-
|
| 124 |
# --- Gradio Interface Functions ---
|
| 125 |
def get_files_df():
|
| 126 |
files = get_stored_files()
|
|
|
|
| 98 |
)
|
| 99 |
documents = text_splitter.split_documents(raw_documents)
|
| 100 |
|
| 101 |
+
# --- INIZIO: CODICE CORRETTO ---
|
| 102 |
+
# 1. Rimuove l'estensione, gli spazi iniziali/finali e converte in minuscolo.
|
| 103 |
+
sanitized_filename = original_filename.replace('.pdf', '').strip().lower()
|
| 104 |
+
|
| 105 |
+
# 2. Sostituisce qualsiasi carattere non alfanumerico con un trattino.
|
| 106 |
+
sanitized_filename = re.sub(r'[^a-z0-9]', '-', sanitized_filename)
|
| 107 |
+
|
| 108 |
+
# 3. Sostituisce trattini multipli consecutivi con un singolo trattino.
|
| 109 |
+
sanitized_filename = re.sub(r'-+', '-', sanitized_filename)
|
| 110 |
+
|
| 111 |
+
# 4. (Opzionale ma consigliato) Rimuove eventuali trattini all'inizio o alla fine.
|
| 112 |
+
sanitized_filename = sanitized_filename.strip('-')
|
| 113 |
+
|
| 114 |
+
# 5. Usa il nome sanificato per generare gli ID.
|
| 115 |
uuids = [f"{sanitized_filename}-{i}" for i in range(len(documents))]
|
| 116 |
+
# --- FINE: CODICE CORRETTO ---
|
| 117 |
|
| 118 |
batch_size = 100
|
| 119 |
for i in range(0, len(documents), batch_size):
|
|
|
|
| 127 |
return f"Unable to create embeddings: {str(e)}", get_files_df()
|
| 128 |
|
| 129 |
|
|
|
|
| 130 |
# --- Gradio Interface Functions ---
|
| 131 |
def get_files_df():
|
| 132 |
files = get_stored_files()
|