Skip to content

Commit 6d978de

Browse files
Merge pull request #40 from Pseudo-Lab/39-feature-extend-domain-auto-detection-and-update-cli-documentation
feat: Extend domain auto-detection for all prefixes
2 parents b528f0c + 96137ba commit 6d978de

2 files changed

Lines changed: 66 additions & 13 deletions

File tree

README.md

Lines changed: 41 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -271,12 +271,50 @@ uv run python -m generate_synthetic_table.cli path/to/table_image.png \
271271
**옵션 설명:**
272272
| 옵션 | 설명 | 기본값 |
273273
|------|------|--------|
274-
| `image` | 입력 이미지 또는 HTML 파일 경로 | (필수) |
275-
| `--provider` | LLM 제공자 (`openai`, `gemini`, `gemini_pool`, `vllm`) | `openai` |
276-
| `--model` | 사용할 모델명 | `gpt-4.1-mini` |
274+
| `image` | 입력 이미지, HTML 파일, 또는 폴더 경로 | (필수) |
275+
| `--provider` | LLM 제공자 (`openai`, `gemini`, `gemini_pool`, `claude`, `vllm`) | `openai` |
276+
| `--model` | 사용할 모델명 | `gpt-4o-mini` |
277277
| `--temperature` | 생성 다양성 조절 | `0.2` |
278278
| `--config-path` | gemini_pool용 설정 파일 경로 | `apis/gemini_keys.yaml` |
279+
| `--base-url` | vLLM 또는 OpenAI 호환 엔드포인트 URL | (선택) |
279280
| `--save-json` | 결과 JSON 저장 경로 | (선택) |
281+
| `--domain` | 프롬프트 도메인 (`medical`, `public`, `insurance`, `finance`, `academic`, `business`) | 자동 감지 |
282+
| `--qa-only` | 합성 데이터 생성 없이 이미지에서 직접 QA만 생성 | `false` |
283+
| `--output-dir` | 배치 처리 결과 저장 디렉토리 | `./qa_output` |
284+
| `--max-workers` | 배치 처리 시 병렬 워커 수 | `3` |
285+
| `--sampling` | 테이블당 랜덤 이미지 샘플링 활성화 | `false` |
286+
| `--min-k` | 테이블당 최소 샘플링 이미지 수 | `2` |
287+
| `--max-k` | 테이블당 최대 샘플링 이미지 수 | `3` |
288+
| `--num-samples` | 테이블당 생성할 랜덤 배치 수 | `1` |
289+
| `--pair-mode` | Public 데이터용 순차 페어 처리 (0-1, 2-3...) | `false` |
290+
291+
### 도메인별 프롬프트
292+
293+
`--domain` 옵션을 사용하여 특정 도메인에 맞는 프롬프트를 적용할 수 있습니다. 각 도메인별 프롬프트는 `generate_synthetic_table/prompts/` 폴더에 정의되어 있습니다.
294+
295+
| 도메인 | 설명 | 자동 감지 조건 |
296+
|--------|------|----------------|
297+
| `medical` | 의료 데이터 (환자 바이탈, 진단명, 약물 용량, 검사 수치 등) | ✅ 파일/폴더명이 `M_`로 시작 |
298+
| `public` | 공공 데이터 | ✅ 파일/폴더명이 `P_`로 시작 |
299+
| `insurance` | 보험 데이터 | ✅ 파일/폴더명이 `I_`로 시작 |
300+
| `finance` | 금융 데이터 | ✅ 파일/폴더명이 `F_`로 시작 |
301+
| `academic` | 학술 데이터 | ✅ 파일/폴더명이 `A_`로 시작 |
302+
| `business` | 비즈니스 데이터 | ✅ 파일/폴더명이 `B_`로 시작 |
303+
304+
**도메인 사용 예시:**
305+
```bash
306+
# Medical 도메인으로 합성 데이터 생성
307+
uv run python -m generate_synthetic_table.cli path/to/medical_table.png \
308+
--domain medical --provider gemini_pool --save-json output.json
309+
310+
# 폴더 배치 처리 (Medical 도메인)
311+
uv run python -m generate_synthetic_table.cli ./Medical/Table/ \
312+
--domain medical --max-workers 5 --output-dir ./output
313+
314+
# QA만 생성 (합성 데이터 생성 단계 스킵)
315+
uv run python -m generate_synthetic_table.cli path/to/table.png \
316+
--domain medical --qa-only --save-json output.json
317+
```
280318

281319
### 실행 예시 및 결과
282320

generate_synthetic_table/runner.py

Lines changed: 25 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,25 @@
3434
from data_organizer import TableDataOrganizer
3535

3636

37+
# Domain auto-detection mapping: prefix -> domain name
38+
_DOMAIN_PREFIX_MAP = {
39+
"M_": "medical",
40+
"P_": "public",
41+
"I_": "insurance",
42+
"F_": "finance",
43+
"A_": "academic",
44+
"B_": "business",
45+
}
46+
47+
48+
def _auto_detect_domain(name: str) -> str | None:
49+
"""Auto-detect domain from file/folder name prefix."""
50+
for prefix, domain in _DOMAIN_PREFIX_MAP.items():
51+
if name.startswith(prefix):
52+
return domain
53+
return None
54+
55+
3756
def build_arg_parser() -> argparse.ArgumentParser:
3857
"""Create the common argument parser used by CLI entrypoints."""
3958

@@ -401,12 +420,10 @@ def run_with_args(args: argparse.Namespace) -> TableState | Dict | None:
401420
# Single file processing
402421
# Auto-detect domain if not provided
403422
domain = args.domain
404-
if not domain and input_path.name.startswith("P_"):
405-
domain = "public"
406-
print(f"Auto-detected domain: {domain}")
407-
elif not domain and input_path.name.startswith("I_"):
408-
domain = "insurance"
409-
print(f"Auto-detected domain: {domain}")
423+
if not domain:
424+
domain = _auto_detect_domain(input_path.name)
425+
if domain:
426+
print(f"Auto-detected domain: {domain}")
410427

411428
# 체크포인팅 활성화 시 메시지 출력
412429
if enable_checkpointing:
@@ -559,10 +576,8 @@ def run_batch_for_folder(
559576
output_dir.mkdir(parents=True, exist_ok=True)
560577

561578
# Auto-detect domain if not provided
562-
if not domain and folder.name.startswith("P_"):
563-
domain = "public"
564-
elif not domain and folder.name.startswith("I_"):
565-
domain = "insurance"
579+
if not domain:
580+
domain = _auto_detect_domain(folder.name)
566581

567582
print(f"Found {len(image_files)} images in {folder}")
568583
print(f"Output directory: {output_dir}")

0 commit comments

Comments
 (0)