Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,8 +1,4 @@
|
|
| 1 |
import os
|
| 2 |
-
#os.environ["PYDANTIC_V1_STYLE"] = "1"
|
| 3 |
-
#os.environ["PYDANTIC_SKIP_VALIDATING_CORE_SCHEMAS"] = "1"
|
| 4 |
-
# --------------------------------------------------------------------------
|
| 5 |
-
|
| 6 |
from flask import Flask, render_template, jsonify, request, Response
|
| 7 |
from flask_socketio import SocketIO, emit
|
| 8 |
import uuid
|
|
@@ -44,7 +40,6 @@ import leximind_prompts
|
|
| 44 |
# --- 전역 변수 ---
|
| 45 |
connected_clients = 0
|
| 46 |
search_document_number = 30
|
| 47 |
-
Filtered_search = False
|
| 48 |
filters = {"regulation_part": []}
|
| 49 |
|
| 50 |
# --- 경로 설정 ---
|
|
@@ -138,9 +133,9 @@ Search_each_all_mode = True # 기본값을 클라이언트에서 제어 가능
|
|
| 138 |
|
| 139 |
@socketio.on('search_query')
|
| 140 |
def handle_search_query(data):
|
| 141 |
-
global Filtered_search
|
| 142 |
global filters
|
| 143 |
global Search_each_all_mode
|
|
|
|
| 144 |
|
| 145 |
# 세션 ID 생성
|
| 146 |
session_id = str(uuid.uuid4())
|
|
@@ -185,7 +180,6 @@ def handle_search_query(data):
|
|
| 185 |
logger.info(f"Query: Translated_query : {Translated_query}")
|
| 186 |
|
| 187 |
if selected_regulations:
|
| 188 |
-
Filtered_search = True
|
| 189 |
cont_selected_num = 0
|
| 190 |
|
| 191 |
# 파일로 저장
|
|
@@ -193,7 +187,7 @@ def handle_search_query(data):
|
|
| 193 |
|
| 194 |
if os.path.exists(output_path):
|
| 195 |
os.remove(output_path)
|
| 196 |
-
|
| 197 |
|
| 198 |
# 통합 검색 모드 - 타입별로 그룹화
|
| 199 |
grouped_regulations = group_regulations_by_type(selected_regulations)
|
|
@@ -201,7 +195,7 @@ def handle_search_query(data):
|
|
| 201 |
|
| 202 |
# 타입별로 필터 생성
|
| 203 |
combined_filters = create_combined_filters(grouped_regulations)
|
| 204 |
-
|
| 205 |
|
| 206 |
combined_cleaned_filter = {k: v for k, v in combined_filters.items() if v}
|
| 207 |
|
|
@@ -230,7 +224,7 @@ def handle_search_query(data):
|
|
| 230 |
|
| 231 |
# 법규 타입별 필터 생성
|
| 232 |
current_filters = create_filter_by_type(RegType, RegName)
|
| 233 |
-
|
| 234 |
|
| 235 |
Rag_Results = search_DB_from_multiple_regions(Translated_query, regions, region_rag_objects, current_filters, False) #마지막 False값은 유사한 값에 대한 검색을 하지 않겠다는 의미
|
| 236 |
|
|
@@ -282,7 +276,6 @@ def handle_search_query(data):
|
|
| 282 |
emit('search_complete', {'status': 'completed', 'message': '통합 검색이 완료되었습니다.'})
|
| 283 |
|
| 284 |
else:
|
| 285 |
-
Filtered_search = False
|
| 286 |
emit('search_status', {'status': 'searching_all', 'message': '전체 법규에서 검색 중...'})
|
| 287 |
|
| 288 |
# 필터 없이 검색
|
|
@@ -492,7 +485,6 @@ def Gemma3_AI_Translate(query_txt):
|
|
| 492 |
# --- 검색 ---
|
| 493 |
# 검색 함수 수정
|
| 494 |
def search_DB_from_multiple_regions(query, selected_regions, region_rag_objects, custom_filters=None, failsafe_mode=True):
|
| 495 |
-
global Filtered_search
|
| 496 |
global filters
|
| 497 |
|
| 498 |
if not selected_regions:
|
|
|
|
| 1 |
import os
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2 |
from flask import Flask, render_template, jsonify, request, Response
|
| 3 |
from flask_socketio import SocketIO, emit
|
| 4 |
import uuid
|
|
|
|
| 40 |
# --- 전역 변수 ---
|
| 41 |
connected_clients = 0
|
| 42 |
search_document_number = 30
|
|
|
|
| 43 |
filters = {"regulation_part": []}
|
| 44 |
|
| 45 |
# --- 경로 설정 ---
|
|
|
|
| 133 |
|
| 134 |
@socketio.on('search_query')
|
| 135 |
def handle_search_query(data):
|
|
|
|
| 136 |
global filters
|
| 137 |
global Search_each_all_mode
|
| 138 |
+
global current_dir
|
| 139 |
|
| 140 |
# 세션 ID 생성
|
| 141 |
session_id = str(uuid.uuid4())
|
|
|
|
| 180 |
logger.info(f"Query: Translated_query : {Translated_query}")
|
| 181 |
|
| 182 |
if selected_regulations:
|
|
|
|
| 183 |
cont_selected_num = 0
|
| 184 |
|
| 185 |
# 파일로 저장
|
|
|
|
| 187 |
|
| 188 |
if os.path.exists(output_path):
|
| 189 |
os.remove(output_path)
|
| 190 |
+
logger.info(f"기존 파일 삭제 완료: {output_path}")
|
| 191 |
|
| 192 |
# 통합 검색 모드 - 타입별로 그룹화
|
| 193 |
grouped_regulations = group_regulations_by_type(selected_regulations)
|
|
|
|
| 195 |
|
| 196 |
# 타입별로 필터 생성
|
| 197 |
combined_filters = create_combined_filters(grouped_regulations)
|
| 198 |
+
logger.info(f"통합 필터: {combined_filters}")
|
| 199 |
|
| 200 |
combined_cleaned_filter = {k: v for k, v in combined_filters.items() if v}
|
| 201 |
|
|
|
|
| 224 |
|
| 225 |
# 법규 타입별 필터 생성
|
| 226 |
current_filters = create_filter_by_type(RegType, RegName)
|
| 227 |
+
logger.info(f"생성된 필터: {current_filters}")
|
| 228 |
|
| 229 |
Rag_Results = search_DB_from_multiple_regions(Translated_query, regions, region_rag_objects, current_filters, False) #마지막 False값은 유사한 값에 대한 검색을 하지 않겠다는 의미
|
| 230 |
|
|
|
|
| 276 |
emit('search_complete', {'status': 'completed', 'message': '통합 검색이 완료되었습니다.'})
|
| 277 |
|
| 278 |
else:
|
|
|
|
| 279 |
emit('search_status', {'status': 'searching_all', 'message': '전체 법규에서 검색 중...'})
|
| 280 |
|
| 281 |
# 필터 없이 검색
|
|
|
|
| 485 |
# --- 검색 ---
|
| 486 |
# 검색 함수 수정
|
| 487 |
def search_DB_from_multiple_regions(query, selected_regions, region_rag_objects, custom_filters=None, failsafe_mode=True):
|
|
|
|
| 488 |
global filters
|
| 489 |
|
| 490 |
if not selected_regions:
|