Spaces:
Sleeping
Sleeping
Update config.py
Browse files
config.py
CHANGED
|
@@ -1,23 +1,23 @@
|
|
| 1 |
import os
|
| 2 |
from pathlib import Path
|
| 3 |
-
import csv #
|
| 4 |
import logging
|
| 5 |
|
| 6 |
-
# ---
|
| 7 |
-
#
|
| 8 |
logging.basicConfig(level=logging.INFO, format='%(asctime)s - %(name)s - %(levelname)s - %(message)s')
|
| 9 |
logger = logging.getLogger(__name__)
|
| 10 |
|
| 11 |
-
# API
|
| 12 |
HF_TOKEN = os.environ.get("HF_TOKEN", None)
|
| 13 |
MEDGEMMA_ENDPOINT_URL = os.environ.get("MEDGEMMA_ENDPOINT_URL", None)
|
| 14 |
|
| 15 |
-
# ---
|
| 16 |
-
#
|
| 17 |
-
BASE_DIR = Path(__file__).parent.resolve() #
|
| 18 |
STATIC_DIR = BASE_DIR / 'static'
|
| 19 |
|
| 20 |
-
# ---
|
| 21 |
AVAILABLE_REPORTS = []
|
| 22 |
MANIFEST_CSV_PATH = STATIC_DIR / 'reports_manifest.csv'
|
| 23 |
|
|
@@ -25,69 +25,68 @@ if MANIFEST_CSV_PATH.is_file():
|
|
| 25 |
try:
|
| 26 |
with open(MANIFEST_CSV_PATH, mode='r', encoding='utf-8') as csvfile:
|
| 27 |
reader = csv.DictReader(csvfile)
|
| 28 |
-
#
|
| 29 |
required_headers = {'case_display_name', 'image_path', 'report_path'}
|
| 30 |
if not required_headers.issubset(reader.fieldnames):
|
| 31 |
logger.error(
|
| 32 |
-
f"CSV
|
| 33 |
)
|
| 34 |
else:
|
| 35 |
for row in reader:
|
| 36 |
case_name = row['case_display_name']
|
| 37 |
-
image_path_from_csv = row['image_path'] #
|
| 38 |
-
report_path_from_csv = row['report_path'] #
|
| 39 |
|
| 40 |
-
#
|
| 41 |
if not image_path_from_csv:
|
| 42 |
-
logger.warning(f"
|
| 43 |
continue
|
| 44 |
|
| 45 |
-
#
|
| 46 |
abs_image_path_to_check = BASE_DIR / image_path_from_csv
|
| 47 |
if not abs_image_path_to_check.is_file():
|
| 48 |
-
logger.warning(f"
|
| 49 |
continue
|
| 50 |
|
| 51 |
-
|
| 52 |
image_file_for_config = image_path_from_csv
|
| 53 |
|
| 54 |
-
report_file_for_config = "" #
|
| 55 |
-
if report_path_from_csv: #
|
| 56 |
-
#
|
| 57 |
abs_report_path_to_check = BASE_DIR / report_path_from_csv
|
| 58 |
if not abs_report_path_to_check.is_file():
|
| 59 |
logger.warning(
|
| 60 |
-
f"
|
| 61 |
-
f"
|
| 62 |
)
|
| 63 |
-
# report_file_for_config
|
| 64 |
else:
|
| 65 |
-
#
|
| 66 |
-
#
|
| 67 |
-
#
|
| 68 |
if report_path_from_csv.startswith('static/') or report_path_from_csv.startswith('static\\'):
|
| 69 |
-
#
|
| 70 |
-
#
|
| 71 |
report_file_for_config = report_path_from_csv
|
| 72 |
else:
|
| 73 |
logger.warning(
|
| 74 |
-
f"
|
| 75 |
-
f"
|
| 76 |
)
|
| 77 |
-
# report_file_for_config
|
| 78 |
AVAILABLE_REPORTS.append({
|
| 79 |
"name": case_name,
|
| 80 |
"image_file": image_file_for_config, # static/images/report1.jpg
|
| 81 |
-
"report_file": report_file_for_config, # static/reports/report1.txt
|
| 82 |
"image_type": row['image_type']
|
| 83 |
})
|
| 84 |
AVAILABLE_REPORTS.sort(key=lambda x: x['name'])
|
| 85 |
-
logger.info(f"
|
| 86 |
|
| 87 |
except Exception as e:
|
| 88 |
-
logger.error(f"
|
| 89 |
else:
|
| 90 |
-
logger.warning(f"
|
| 91 |
|
| 92 |
-
# ---
|
| 93 |
-
DEFAULT_REPORT_INFO = AVAILABLE_REPORTS[0] if AVAILABLE_REPORTS else None
|
|
|
|
| 1 |
import os
|
| 2 |
from pathlib import Path
|
| 3 |
+
import csv # CSV ๋ชจ๋ ์ํฌํธ
|
| 4 |
import logging
|
| 5 |
|
| 6 |
+
# --- ์ค์ ---
|
| 7 |
+
# ๊ธฐ๋ณธ ๋ก๊น
์ค์ (์ ํ์ฌํญ, ํ์์ ๋ฐ๋ผ ์กฐ์ )
|
| 8 |
logging.basicConfig(level=logging.INFO, format='%(asctime)s - %(name)s - %(levelname)s - %(message)s')
|
| 9 |
logger = logging.getLogger(__name__)
|
| 10 |
|
| 11 |
+
# API ์ค์
|
| 12 |
HF_TOKEN = os.environ.get("HF_TOKEN", None)
|
| 13 |
MEDGEMMA_ENDPOINT_URL = os.environ.get("MEDGEMMA_ENDPOINT_URL", None)
|
| 14 |
|
| 15 |
+
# --- pathlib์ ์ฌ์ฉํ ๊ฒฝ๋ก ์ค์ ---
|
| 16 |
+
# ์ ํ๋ฆฌ์ผ์ด์
์ ๊ธฐ๋ณธ ๋๋ ํ ๋ฆฌ ๊ฒฐ์
|
| 17 |
+
BASE_DIR = Path(__file__).parent.resolve() # ์ ๋ ๊ฒฝ๋ก๋ฅผ ์ํด resolve() ์ฌ์ฉ
|
| 18 |
STATIC_DIR = BASE_DIR / 'static'
|
| 19 |
|
| 20 |
+
# --- CSV์์ ์ฌ์ฉ ๊ฐ๋ฅํ ๋ณด๊ณ ์/์ด๋ฏธ์ง ์ ๋ก๋ ---
|
| 21 |
AVAILABLE_REPORTS = []
|
| 22 |
MANIFEST_CSV_PATH = STATIC_DIR / 'reports_manifest.csv'
|
| 23 |
|
|
|
|
| 25 |
try:
|
| 26 |
with open(MANIFEST_CSV_PATH, mode='r', encoding='utf-8') as csvfile:
|
| 27 |
reader = csv.DictReader(csvfile)
|
| 28 |
+
# ์์๋๋ CSV ํค๋: 'image_type', 'case_display_name', 'image_path', 'report_path'
|
| 29 |
required_headers = {'case_display_name', 'image_path', 'report_path'}
|
| 30 |
if not required_headers.issubset(reader.fieldnames):
|
| 31 |
logger.error(
|
| 32 |
+
f"CSV ํ์ผ {MANIFEST_CSV_PATH}์ ๋ค์ ํ์ ํค๋๊ฐ ๋๋ฝ๋์์ต๋๋ค: {required_headers - set(reader.fieldnames)}"
|
| 33 |
)
|
| 34 |
else:
|
| 35 |
for row in reader:
|
| 36 |
case_name = row['case_display_name']
|
| 37 |
+
image_path_from_csv = row['image_path'] # ์: static/images/report1.jpg
|
| 38 |
+
report_path_from_csv = row['report_path'] # ์: static/reports/report1.txt ๋๋ ๋น ๋ฌธ์์ด
|
| 39 |
|
| 40 |
+
# image_path_from_csv ์ ํจ์ฑ ๊ฒ์ฌ (๋น์ด์์ผ๋ฉด ์ ๋จ)
|
| 41 |
if not image_path_from_csv:
|
| 42 |
+
logger.warning(f"์ผ์ด์ค '{case_name}'์ CSV์์ image_path๊ฐ ๋น์ด์์ต๋๋ค. ์ด ํญ๋ชฉ์ ๊ฑด๋๋๋๋ค.")
|
| 43 |
continue
|
| 44 |
|
| 45 |
+
# ์ด๋ฏธ์ง ํ์ผ ๊ฒ์ฆ์ ์ํ ์ ๋ ๊ฒฝ๋ก ๊ตฌ์ฑ (CSV์ ๊ฒฝ๋ก๋ BASE_DIR ๊ธฐ์ค ์๋ ๊ฒฝ๋ก)
|
| 46 |
abs_image_path_to_check = BASE_DIR / image_path_from_csv
|
| 47 |
if not abs_image_path_to_check.is_file():
|
| 48 |
+
logger.warning(f"์ผ์ด์ค '{case_name}'์ ์ด๋ฏธ์ง ํ์ผ์ '{abs_image_path_to_check}'์์ ์ฐพ์ ์ ์์ต๋๋ค. ์ด ํญ๋ชฉ์ ๊ฑด๋๋๋๋ค.")
|
| 49 |
continue
|
| 50 |
|
|
|
|
| 51 |
image_file_for_config = image_path_from_csv
|
| 52 |
|
| 53 |
+
report_file_for_config = "" # ๋ณด๊ณ ์๊ฐ ์๊ฑฐ๋ ์ค๋ฅ๊ฐ ์์ผ๋ฉด ๊ธฐ๋ณธ๊ฐ์ ๋น ๋ฌธ์์ด
|
| 54 |
+
if report_path_from_csv: # ๋ณด๊ณ ์ ๊ฒฝ๋ก๋ ์ ํ์ฌํญ
|
| 55 |
+
# ๋ณด๊ณ ์ ํ์ผ ๊ฒ์ฆ์ ์ํ ์ ๋ ๊ฒฝ๋ก ๊ตฌ์ฑ (CSV์ ๊ฒฝ๋ก๋ BASE_DIR ๊ธฐ์ค ์๋ ๊ฒฝ๋ก)
|
| 56 |
abs_report_path_to_check = BASE_DIR / report_path_from_csv
|
| 57 |
if not abs_report_path_to_check.is_file():
|
| 58 |
logger.warning(
|
| 59 |
+
f"์ผ์ด์ค '{case_name}'์ ์ง์ ๋ ๋ณด๊ณ ์ ํ์ผ '{abs_report_path_to_check}'์(๋ฅผ) ์ฐพ์ ์ ์์ต๋๋ค. "
|
| 60 |
+
f"์ด ๏ฟฝ๏ฟฝ๏ฟฝ๋ชฉ์ ๋ํด ๋ณด๊ณ ์ ํ์ผ ์์ด ์งํํฉ๋๋ค."
|
| 61 |
)
|
| 62 |
+
# report_file_for_config๋ ""๋ก ์ ์ง
|
| 63 |
else:
|
| 64 |
+
# ํ์ผ (BASE_DIR / report_path_from_csv)์ด ์กด์ฌํจ.
|
| 65 |
+
# ์ด์ report_path_from_csv ๋ฌธ์์ด ์์ฒด๊ฐ "static/"์ผ๋ก ์์ํ๋์ง ํ์ธ
|
| 66 |
+
# CSV ๋ด์ฉ์ ๋ํ ๊ฐ์ ์ ๋ฐ๋ผ.
|
| 67 |
if report_path_from_csv.startswith('static/') or report_path_from_csv.startswith('static\\'):
|
| 68 |
+
# ๊ฒฝ๋ก๊ฐ ์ฌ๋ฐ๋ฅธ ํ์(static/์ผ๋ก ์์)์ด๊ณ ํ์ผ์ด ์กด์ฌํจ.
|
| 69 |
+
# ๊ฒฝ๋ก๋ฅผ ๊ทธ๋๋ก ์ ์ฅ (์: "static/reports/report1.txt").
|
| 70 |
report_file_for_config = report_path_from_csv
|
| 71 |
else:
|
| 72 |
logger.warning(
|
| 73 |
+
f"CSV์ ์ผ์ด์ค '{case_name}'์ ๋ํ ๋ณด๊ณ ์ ๊ฒฝ๋ก '{report_path_from_csv}'๊ฐ "
|
| 74 |
+
f"์๋ชป๋ ํ์์
๋๋ค ('static/'์ผ๋ก ์์ํ์ง ์์). ๋ณด๊ณ ์ ๊ฒฝ๋ก๊ฐ ์ง์ ๋์ง ์์ ๊ฒ์ผ๋ก ์ฒ๋ฆฌํฉ๋๋ค."
|
| 75 |
)
|
| 76 |
+
# report_file_for_config๋ ""๋ก ์ ์ง
|
| 77 |
AVAILABLE_REPORTS.append({
|
| 78 |
"name": case_name,
|
| 79 |
"image_file": image_file_for_config, # static/images/report1.jpg
|
| 80 |
+
"report_file": report_file_for_config, # static/reports/report1.txt ๋๋ ""
|
| 81 |
"image_type": row['image_type']
|
| 82 |
})
|
| 83 |
AVAILABLE_REPORTS.sort(key=lambda x: x['name'])
|
| 84 |
+
logger.info(f"CSV์์ {len(AVAILABLE_REPORTS)}๊ฐ์ ๋ณด๊ณ ์/์ด๋ฏธ์ง ์์ ๋ก๋ํ์ต๋๋ค.")
|
| 85 |
|
| 86 |
except Exception as e:
|
| 87 |
+
logger.error(f"CSV ํ์ผ {MANIFEST_CSV_PATH} ์ฝ๊ธฐ ๋๋ ์ฒ๋ฆฌ ์ค ์ค๋ฅ ๋ฐ์: {e}", exc_info=True)
|
| 88 |
else:
|
| 89 |
+
logger.warning(f"{MANIFEST_CSV_PATH}์์ ๋งค๋ํ์คํธ CSV ํ์ผ์ ์ฐพ์ ์ ์์ต๋๋ค. AVAILABLE_REPORTS๊ฐ ๋น์ด์๊ฒ ๋ฉ๋๋ค.")
|
| 90 |
|
| 91 |
+
# --- ์ ํ์ฌํญ: ํ์ํ ๊ฒฝ์ฐ ๊ธฐ๋ณธ ๋ณด๊ณ ์ ์ ์ ---
|
| 92 |
+
DEFAULT_REPORT_INFO = AVAILABLE_REPORTS[0] if AVAILABLE_REPORTS else None
|