Spaces:
Sleeping
Sleeping
Commit
·
9c9aff4
1
Parent(s):
04f5154
big debug change
Browse files- app.py +26 -23
- documents_prep.py +3 -1
app.py
CHANGED
|
@@ -149,37 +149,39 @@ def initialize_system(repo_id, hf_token, download_dir, chunks_filename=None,
|
|
| 149 |
all_documents = []
|
| 150 |
chunks_df = None
|
| 151 |
|
|
|
|
| 152 |
if use_json_instead_csv and json_files_dir:
|
| 153 |
log_message("Используем JSON файлы вместо CSV")
|
| 154 |
-
from documents_prep import
|
| 155 |
|
| 156 |
-
#
|
| 157 |
-
|
| 158 |
-
|
| 159 |
-
|
| 160 |
-
|
|
|
|
|
|
|
|
|
|
| 161 |
else:
|
|
|
|
| 162 |
if chunks_filename:
|
| 163 |
log_message("Загружаем данные из CSV")
|
| 164 |
-
|
| 165 |
-
|
| 166 |
-
if table_data_dir:
|
| 167 |
-
log_message("Добавляю табличные данные")
|
| 168 |
-
from documents_prep import load_table_documents
|
| 169 |
|
| 170 |
-
|
| 171 |
-
|
| 172 |
-
|
| 173 |
-
|
| 174 |
-
|
| 175 |
-
|
| 176 |
-
|
| 177 |
-
from documents_prep import load_image_documents
|
| 178 |
|
| 179 |
-
|
| 180 |
-
|
| 181 |
-
|
| 182 |
-
|
|
|
|
|
|
|
|
|
|
| 183 |
|
| 184 |
log_message(f"Всего документов после всей обработки: {len(all_documents)}")
|
| 185 |
|
|
@@ -197,6 +199,7 @@ def initialize_system(repo_id, hf_token, download_dir, chunks_filename=None,
|
|
| 197 |
'table_number': doc.metadata.get('table_number', ''),
|
| 198 |
'image_number': doc.metadata.get('image_number', ''),
|
| 199 |
'section': doc.metadata.get('section', ''),
|
|
|
|
| 200 |
})
|
| 201 |
|
| 202 |
log_message(f"Система успешно инициализирована")
|
|
|
|
| 149 |
all_documents = []
|
| 150 |
chunks_df = None
|
| 151 |
|
| 152 |
+
# CHANGED: Use load_all_documents instead of loading separately
|
| 153 |
if use_json_instead_csv and json_files_dir:
|
| 154 |
log_message("Используем JSON файлы вместо CSV")
|
| 155 |
+
from documents_prep import load_all_documents
|
| 156 |
|
| 157 |
+
# This will handle text, tables, and images all together with proper logging
|
| 158 |
+
all_documents = load_all_documents(
|
| 159 |
+
repo_id=repo_id,
|
| 160 |
+
hf_token=hf_token,
|
| 161 |
+
json_dir=json_files_dir,
|
| 162 |
+
table_dir=table_data_dir if table_data_dir else "",
|
| 163 |
+
image_dir=image_data_dir if image_data_dir else ""
|
| 164 |
+
)
|
| 165 |
else:
|
| 166 |
+
# OLD PATH: Loading separately (fallback)
|
| 167 |
if chunks_filename:
|
| 168 |
log_message("Загружаем данные из CSV")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 169 |
|
| 170 |
+
if table_data_dir:
|
| 171 |
+
log_message("Добавляю табличные данные")
|
| 172 |
+
from documents_prep import load_table_documents
|
| 173 |
+
|
| 174 |
+
table_chunks = load_table_documents(repo_id, hf_token, table_data_dir)
|
| 175 |
+
log_message(f"Загружено {len(table_chunks)} табличных чанков")
|
| 176 |
+
all_documents.extend(table_chunks)
|
|
|
|
| 177 |
|
| 178 |
+
if image_data_dir:
|
| 179 |
+
log_message("Добавляю данные изображений")
|
| 180 |
+
from documents_prep import load_image_documents
|
| 181 |
+
|
| 182 |
+
image_documents = load_image_documents(repo_id, hf_token, image_data_dir)
|
| 183 |
+
log_message(f"Загружено {len(image_documents)} документов изображений")
|
| 184 |
+
all_documents.extend(image_documents)
|
| 185 |
|
| 186 |
log_message(f"Всего документов после всей обработки: {len(all_documents)}")
|
| 187 |
|
|
|
|
| 199 |
'table_number': doc.metadata.get('table_number', ''),
|
| 200 |
'image_number': doc.metadata.get('image_number', ''),
|
| 201 |
'section': doc.metadata.get('section', ''),
|
| 202 |
+
'connection_type': doc.metadata.get('connection_type', '') # ADD THIS
|
| 203 |
})
|
| 204 |
|
| 205 |
log_message(f"Система успешно инициализирована")
|
documents_prep.py
CHANGED
|
@@ -126,7 +126,8 @@ def chunk_table_by_content(table_data, doc_id, max_chars=MAX_CHARS_TABLE, max_ro
|
|
| 126 |
'row_end': current_rows[-1]['_idx'],
|
| 127 |
'total_rows': len(rows),
|
| 128 |
'chunk_size': len(content),
|
| 129 |
-
'is_complete_table': False
|
|
|
|
| 130 |
}
|
| 131 |
|
| 132 |
chunks.append(Document(text=content, metadata=metadata))
|
|
@@ -491,6 +492,7 @@ def load_image_documents(repo_id, hf_token, image_dir):
|
|
| 491 |
log_message(f"✓ Loaded {len(documents)} images (avg size: {avg_size:.0f} chars)")
|
| 492 |
|
| 493 |
return documents
|
|
|
|
| 494 |
def load_all_documents(repo_id, hf_token, json_dir, table_dir, image_dir):
|
| 495 |
"""Main loader - combines all document types"""
|
| 496 |
log_message("="*60)
|
|
|
|
| 126 |
'row_end': current_rows[-1]['_idx'],
|
| 127 |
'total_rows': len(rows),
|
| 128 |
'chunk_size': len(content),
|
| 129 |
+
'is_complete_table': False,
|
| 130 |
+
'connection_type': extract_connection_type(table_title) if table_title else '' # NEW
|
| 131 |
}
|
| 132 |
|
| 133 |
chunks.append(Document(text=content, metadata=metadata))
|
|
|
|
| 492 |
log_message(f"✓ Loaded {len(documents)} images (avg size: {avg_size:.0f} chars)")
|
| 493 |
|
| 494 |
return documents
|
| 495 |
+
|
| 496 |
def load_all_documents(repo_id, hf_token, json_dir, table_dir, image_dir):
|
| 497 |
"""Main loader - combines all document types"""
|
| 498 |
log_message("="*60)
|