Pablo276 commited on
Commit
51458f9
·
verified ·
1 Parent(s): 2de98a7

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +15 -9
app.py CHANGED
@@ -98,15 +98,22 @@ def embedder(uploaded_file_path):
98
  )
99
  documents = text_splitter.split_documents(raw_documents)
100
 
101
- # --- START: CORRECTED CODE ---
102
- # 1. Sanitize the base filename to conform to Pinecone's rules.
103
- sanitized_filename = original_filename.replace('.pdf', '').lower()
104
- # 2. Replace all invalid characters (anything not a-z, 0-9, or -) with a hyphen.
105
- sanitized_filename = re.sub(r'[^a-z0-9-]', '-', sanitized_filename)
106
-
107
- # 3. Use the sanitized filename to generate the vector IDs.
 
 
 
 
 
 
 
108
  uuids = [f"{sanitized_filename}-{i}" for i in range(len(documents))]
109
- # --- END: CORRECTED CODE ---
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()