Spaces:
Sleeping
Sleeping
Commit ·
30336c3
1
Parent(s): 4834e86
normalize anyways + max row = 15 + max chars = 3000
Browse files- config.py +2 -2
- documents_prep.py +21 -4
config.py
CHANGED
|
@@ -52,8 +52,8 @@ DEFAULT_MODEL = "Gemini 2.5 Flash"
|
|
| 52 |
CHUNK_SIZE = 1500
|
| 53 |
CHUNK_OVERLAP = 128
|
| 54 |
|
| 55 |
-
MAX_CHARS_TABLE =
|
| 56 |
-
MAX_ROWS_TABLE =
|
| 57 |
|
| 58 |
CUSTOM_PROMPT = """
|
| 59 |
Вы являетесь высокоспециализированным Ассистентом для анализа нормативных документов (AIEXP). Ваша цель - предоставлять точные, корректные и контекстно релевантные ответы исключительно на основе предоставленного контекста из нормативной документации.
|
|
|
|
| 52 |
CHUNK_SIZE = 1500
|
| 53 |
CHUNK_OVERLAP = 128
|
| 54 |
|
| 55 |
+
MAX_CHARS_TABLE = 3000
|
| 56 |
+
MAX_ROWS_TABLE = 15
|
| 57 |
|
| 58 |
CUSTOM_PROMPT = """
|
| 59 |
Вы являетесь высокоспециализированным Ассистентом для анализа нормативных документов (AIEXP). Ваша цель - предоставлять точные, корректные и контекстно релевантные ответы исключительно на основе предоставленного контекста из нормативной документации.
|
documents_prep.py
CHANGED
|
@@ -34,11 +34,16 @@ def chunk_text_documents(documents):
|
|
| 34 |
|
| 35 |
return chunked
|
| 36 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 37 |
def extract_connection_type(text):
|
| 38 |
-
"""Extract connection type like С-25, У-14, etc. from text"""
|
| 39 |
import re
|
| 40 |
-
match = re.search(r'[
|
| 41 |
-
|
|
|
|
|
|
|
| 42 |
|
| 43 |
def chunk_table_by_content(table_data, doc_id, max_chars=MAX_CHARS_TABLE, max_rows=MAX_ROWS_TABLE):
|
| 44 |
headers = table_data.get('headers', [])
|
|
@@ -183,7 +188,10 @@ def format_table_header(doc_id, table_identifier, table_num, table_title, sectio
|
|
| 183 |
type_match = re.search(r'[СУUTC]-?\d+(?:-\d+)?', table_title)
|
| 184 |
if type_match:
|
| 185 |
connection_type = type_match.group(0)
|
| 186 |
-
|
|
|
|
|
|
|
|
|
|
| 187 |
|
| 188 |
if table_num and table_num != table_identifier:
|
| 189 |
content += f"НОМЕР ТАБЛИЦЫ: {table_num}\n"
|
|
@@ -443,6 +451,15 @@ def load_table_documents(repo_id, hf_token, table_dir):
|
|
| 443 |
log_message(f"Error loading {file_path}: {e}")
|
| 444 |
|
| 445 |
log_message(f"✓ Loaded {len(all_chunks)} table chunks")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 446 |
return all_chunks
|
| 447 |
|
| 448 |
|
|
|
|
| 34 |
|
| 35 |
return chunked
|
| 36 |
|
| 37 |
+
def normalize_connection_type(s):
|
| 38 |
+
# Replace Cyrillic С/с with Latin C/c
|
| 39 |
+
return s.replace('С', 'C').replace('с', 'c')
|
| 40 |
+
|
| 41 |
def extract_connection_type(text):
|
|
|
|
| 42 |
import re
|
| 43 |
+
match = re.search(r'[СCс]-?\d+(?:-\d+)?', text)
|
| 44 |
+
if match:
|
| 45 |
+
return normalize_connection_type(match.group(0))
|
| 46 |
+
return ''
|
| 47 |
|
| 48 |
def chunk_table_by_content(table_data, doc_id, max_chars=MAX_CHARS_TABLE, max_rows=MAX_ROWS_TABLE):
|
| 49 |
headers = table_data.get('headers', [])
|
|
|
|
| 188 |
type_match = re.search(r'[СУUTC]-?\d+(?:-\d+)?', table_title)
|
| 189 |
if type_match:
|
| 190 |
connection_type = type_match.group(0)
|
| 191 |
+
# NORMALIZE: Convert Cyrillic to Latin for consistency
|
| 192 |
+
connection_type_normalized = connection_type.replace('С', 'C').replace('У', 'U').replace('Т', 'T')
|
| 193 |
+
# Show BOTH in content for searchability
|
| 194 |
+
content += f"ТИП СОЕДИНЕНИЯ: {connection_type} ({connection_type_normalized})\n"
|
| 195 |
|
| 196 |
if table_num and table_num != table_identifier:
|
| 197 |
content += f"НОМЕР ТАБЛИЦЫ: {table_num}\n"
|
|
|
|
| 451 |
log_message(f"Error loading {file_path}: {e}")
|
| 452 |
|
| 453 |
log_message(f"✓ Loaded {len(all_chunks)} table chunks")
|
| 454 |
+
|
| 455 |
+
log_message("="*60)
|
| 456 |
+
log_message("CONNECTION TYPE ENCODING CHECK:")
|
| 457 |
+
for chunk in all_chunks[:50]: # Check first 50
|
| 458 |
+
conn_type = chunk.metadata.get('connection_type', '')
|
| 459 |
+
if 'C' in conn_type or 'С' in conn_type:
|
| 460 |
+
# Show both representations
|
| 461 |
+
log_message(f" Original: '{conn_type}' | Bytes: {conn_type.encode('utf-8')}")
|
| 462 |
+
log_message("="*60)
|
| 463 |
return all_chunks
|
| 464 |
|
| 465 |
|