Spaces:
Sleeping
Sleeping
Commit
·
52249e8
1
Parent(s):
52f7579
font is black + fixed table + image downloading issues
Browse files- app.py +4 -4
- documents_prep.py +9 -4
- utils.py +2 -3
app.py
CHANGED
|
@@ -22,10 +22,10 @@ def create_chunks_display_html(chunk_info):
|
|
| 22 |
bg_color = "#f8f9fa" if i % 2 == 0 else "#e9ecef"
|
| 23 |
html += f"""
|
| 24 |
<div style='background-color: {bg_color}; padding: 10px; margin: 5px 0; border-radius: 5px; border-left: 4px solid #007bff; color: black;'>
|
| 25 |
-
<strong>Документ:</strong> {chunk['document_id']}
|
| 26 |
-
<strong>Раздел:</strong> {chunk
|
| 27 |
-
<strong>Ранг:</strong> {i+1} | <strong>Размер:</strong> {chunk['chunk_size']}
|
| 28 |
-
<strong>Содержание:</strong><br>
|
| 29 |
<div style='background-color: white; padding: 8px; margin-top: 5px; border-radius: 3px; font-family: monospace; font-size: 12px; color: black; max-height: 200px; overflow-y: auto;'>
|
| 30 |
{chunk['chunk_text']}
|
| 31 |
</div>
|
|
|
|
| 22 |
bg_color = "#f8f9fa" if i % 2 == 0 else "#e9ecef"
|
| 23 |
html += f"""
|
| 24 |
<div style='background-color: {bg_color}; padding: 10px; margin: 5px 0; border-radius: 5px; border-left: 4px solid #007bff; color: black;'>
|
| 25 |
+
<strong style='color: black;'>Документ:</strong> <span style='color: black;'>{chunk['document_id']}</span><br>
|
| 26 |
+
<strong style='color: black;'>Раздел:</strong> <span style='color: black;'>{chunk.get('section_id', 'unknown')}</span><br>
|
| 27 |
+
<strong style='color: black;'>Ранг:</strong> <span style='color: black;'>{i+1}</span> | <strong style='color: black;'>Размер:</strong> <span style='color: black;'>{chunk['chunk_size']} символов</span><br>
|
| 28 |
+
<strong style='color: black;'>Содержание:</strong><br>
|
| 29 |
<div style='background-color: white; padding: 8px; margin-top: 5px; border-radius: 3px; font-family: monospace; font-size: 12px; color: black; max-height: 200px; overflow-y: auto;'>
|
| 30 |
{chunk['chunk_text']}
|
| 31 |
</div>
|
documents_prep.py
CHANGED
|
@@ -232,7 +232,7 @@ def load_json_documents(repo_id, hf_token, json_files_dir, download_dir):
|
|
| 232 |
log_message(f"Ошибка загрузки JSON документов: {str(e)}")
|
| 233 |
return [], []
|
| 234 |
|
| 235 |
-
|
| 236 |
def extract_section_title(section_text):
|
| 237 |
if not section_text.strip():
|
| 238 |
return ""
|
|
@@ -312,7 +312,8 @@ def table_to_document(table_data, document_id=None):
|
|
| 312 |
"table_number": table_data.get('table_number', 'unknown'),
|
| 313 |
"table_title": table_data.get('table_title', 'unknown'),
|
| 314 |
"document_id": doc_id or table_data.get('document_id', table_data.get('document', 'unknown')),
|
| 315 |
-
"section": table_data.get('section', 'unknown')
|
|
|
|
| 316 |
}
|
| 317 |
)
|
| 318 |
|
|
@@ -398,11 +399,13 @@ def load_image_data(repo_id, hf_token, image_data_dir):
|
|
| 398 |
log_message(f"Загружено {len(df)} записей изображений из файла {file_path}")
|
| 399 |
|
| 400 |
for _, row in df.iterrows():
|
|
|
|
|
|
|
| 401 |
content = f"Изображение: {row.get('№ Изображения', 'Неизвестно')}\n"
|
| 402 |
content += f"Название: {row.get('Название изображения', 'Неизвестно')}\n"
|
| 403 |
content += f"Описание: {row.get('Описание изображение', 'Неизвестно')}\n"
|
| 404 |
content += f"Документ: {row.get('Обозначение документа', 'Неизвестно')}\n"
|
| 405 |
-
content += f"Раздел: {
|
| 406 |
content += f"Файл: {row.get('Файл изображения', 'Неизвестно')}\n"
|
| 407 |
|
| 408 |
doc = Document(
|
|
@@ -412,7 +415,8 @@ def load_image_data(repo_id, hf_token, image_data_dir):
|
|
| 412 |
"image_number": row.get('№ Изображения', 'unknown'),
|
| 413 |
"document_id": row.get('Обозначение документа', 'unknown'),
|
| 414 |
"file_path": row.get('Файл изображения', 'unknown'),
|
| 415 |
-
"section":
|
|
|
|
| 416 |
}
|
| 417 |
)
|
| 418 |
image_documents.append(doc)
|
|
@@ -428,6 +432,7 @@ def load_image_data(repo_id, hf_token, image_data_dir):
|
|
| 428 |
log_message(f"Ошибка загрузки данных изображений: {str(e)}")
|
| 429 |
return []
|
| 430 |
|
|
|
|
| 431 |
def load_csv_chunks(repo_id, hf_token, chunks_filename, download_dir):
|
| 432 |
log_message("Загружаю данные чанков из CSV")
|
| 433 |
|
|
|
|
| 232 |
log_message(f"Ошибка загрузки JSON документов: {str(e)}")
|
| 233 |
return [], []
|
| 234 |
|
| 235 |
+
|
| 236 |
def extract_section_title(section_text):
|
| 237 |
if not section_text.strip():
|
| 238 |
return ""
|
|
|
|
| 312 |
"table_number": table_data.get('table_number', 'unknown'),
|
| 313 |
"table_title": table_data.get('table_title', 'unknown'),
|
| 314 |
"document_id": doc_id or table_data.get('document_id', table_data.get('document', 'unknown')),
|
| 315 |
+
"section": table_data.get('section', 'unknown'),
|
| 316 |
+
"section_id": table_data.get('section', 'unknown')
|
| 317 |
}
|
| 318 |
)
|
| 319 |
|
|
|
|
| 399 |
log_message(f"Загружено {len(df)} записей изображений из файла {file_path}")
|
| 400 |
|
| 401 |
for _, row in df.iterrows():
|
| 402 |
+
section_value = row.get('Раздел документа', row.get('section', 'Неизвестно'))
|
| 403 |
+
|
| 404 |
content = f"Изображение: {row.get('№ Изображения', 'Неизвестно')}\n"
|
| 405 |
content += f"Название: {row.get('Название изображения', 'Неизвестно')}\n"
|
| 406 |
content += f"Описание: {row.get('Описание изображение', 'Неизвестно')}\n"
|
| 407 |
content += f"Документ: {row.get('Обозначение документа', 'Неизвестно')}\n"
|
| 408 |
+
content += f"Раздел: {section_value}\n"
|
| 409 |
content += f"Файл: {row.get('Файл изображения', 'Неизвестно')}\n"
|
| 410 |
|
| 411 |
doc = Document(
|
|
|
|
| 415 |
"image_number": row.get('№ Изображения', 'unknown'),
|
| 416 |
"document_id": row.get('Обозначение документа', 'unknown'),
|
| 417 |
"file_path": row.get('Файл изображения', 'unknown'),
|
| 418 |
+
"section": section_value,
|
| 419 |
+
"section_id": section_value
|
| 420 |
}
|
| 421 |
)
|
| 422 |
image_documents.append(doc)
|
|
|
|
| 432 |
log_message(f"Ошибка загрузки данных изображений: {str(e)}")
|
| 433 |
return []
|
| 434 |
|
| 435 |
+
|
| 436 |
def load_csv_chunks(repo_id, hf_token, chunks_filename, download_dir):
|
| 437 |
log_message("Загружаю данные чанков из CSV")
|
| 438 |
|
utils.py
CHANGED
|
@@ -186,19 +186,18 @@ def answer_question(question, query_engine, reranker, current_model, chunks_df=N
|
|
| 186 |
</div>
|
| 187 |
</div>"""
|
| 188 |
|
| 189 |
-
# Релевантные чанки (text snippets)
|
| 190 |
chunk_info = []
|
| 191 |
for node in reranked_nodes:
|
|
|
|
| 192 |
chunk_info.append({
|
| 193 |
'document_id': node.metadata.get('document_id', 'unknown'),
|
| 194 |
-
'section_id':
|
| 195 |
'chunk_size': len(node.text),
|
| 196 |
'chunk_text': node.text
|
| 197 |
})
|
| 198 |
from app import create_chunks_display_html
|
| 199 |
chunks_html = create_chunks_display_html(chunk_info)
|
| 200 |
|
| 201 |
-
|
| 202 |
return answer_with_time, sources_html, chunks_html
|
| 203 |
|
| 204 |
except Exception as e:
|
|
|
|
| 186 |
</div>
|
| 187 |
</div>"""
|
| 188 |
|
|
|
|
| 189 |
chunk_info = []
|
| 190 |
for node in reranked_nodes:
|
| 191 |
+
section_id = node.metadata.get('section_id', node.metadata.get('section', 'unknown'))
|
| 192 |
chunk_info.append({
|
| 193 |
'document_id': node.metadata.get('document_id', 'unknown'),
|
| 194 |
+
'section_id': section_id,
|
| 195 |
'chunk_size': len(node.text),
|
| 196 |
'chunk_text': node.text
|
| 197 |
})
|
| 198 |
from app import create_chunks_display_html
|
| 199 |
chunks_html = create_chunks_display_html(chunk_info)
|
| 200 |
|
|
|
|
| 201 |
return answer_with_time, sources_html, chunks_html
|
| 202 |
|
| 203 |
except Exception as e:
|