Initial commit: O2O 저작권 침해 여부 탐지 API
PDF v1.2 요구사항 반영 완료: - 10종 법령 메타 태그 + 39개 케이스 분류체계 - 3단 캐스케이딩: MinHash+LSH → 삼중 유사도 → 분류 - 자서전 특화: 공통 표현 사전 제거 + NER 마스킹 - KoSimCSE 한국어 임베딩 (자체 산출물 방어) - 보수적 임계값 0.85 - 검토 콘솔 UI (탐지 + 코퍼스 관리 탭) - Docker 배포 패키지 + 31개 테스트 통과
This commit is contained in:
commit
3b69bdf0f0
50 files changed
+4662
No files matched your search
@@ -0,0 +1,81 @@
|
||||
"""커뮤니케이션북스/바이칼 측 통합 참조용 샘플.
|
||||
|
||||
표준 라이브러리만 사용하므로 별도 의존성 설치 불필요.
|
||||
"""
|
||||
from __future__ import annotations
|
||||
|
||||
import json
|
||||
import os
|
||||
import time
|
||||
import urllib.request
|
||||
|
||||
API_HOST = os.environ.get("API_HOST", "http://localhost:8000")
|
||||
API_KEY = os.environ.get("API_KEY", "combooks-key-change-me")
|
||||
|
||||
|
||||
def _post(path: str, body: dict) -> dict:
|
||||
req = urllib.request.Request(
|
||||
f"{API_HOST}{path}",
|
||||
data=json.dumps(body).encode("utf-8"),
|
||||
headers={"Content-Type": "application/json", "X-API-Key": API_KEY},
|
||||
method="POST",
|
||||
)
|
||||
with urllib.request.urlopen(req) as resp:
|
||||
return json.loads(resp.read())
|
||||
|
||||
|
||||
def _get(path: str) -> dict:
|
||||
req = urllib.request.Request(f"{API_HOST}{path}", headers={"X-API-Key": API_KEY})
|
||||
with urllib.request.urlopen(req) as resp:
|
||||
return json.loads(resp.read())
|
||||
|
||||
|
||||
def detect_one() -> None:
|
||||
result = _post(
|
||||
"/v1/plagiarism/detect",
|
||||
{
|
||||
"doc_id": "sample-py-001",
|
||||
"text": (
|
||||
"어린왕자는 작은 별 B-612에서 온 소년이다. 그는 별을 떠나 여러 행성을 여행한다. "
|
||||
"마침내 지구에 도착해 사막에서 비행기 조종사를 만나고 여우와 친구가 된다."
|
||||
),
|
||||
"metadata": {"title": "샘플 작품", "author": "tester"},
|
||||
},
|
||||
)
|
||||
print("[detect] is_infringement:", result["is_infringement"])
|
||||
print("[detect] confidence:", result["confidence"])
|
||||
for m in result["matches"]:
|
||||
print(f" - {m['source_title']} ({m['similarity']}) :: {m['infringement_type']}")
|
||||
|
||||
|
||||
def detect_batch() -> None:
|
||||
created = _post(
|
||||
"/v1/plagiarism/batch",
|
||||
{
|
||||
"items": [
|
||||
{"doc_id": "b-001", "text": "앤 셜리는 초록 지붕 집에 입양된 상상력 풍부한 소녀다."},
|
||||
{"doc_id": "b-002", "text": "홍길동은 활빈당을 만들어 부패한 관리의 재물을 빼앗는다."},
|
||||
]
|
||||
},
|
||||
)
|
||||
job_id = created["job_id"]
|
||||
print(f"[batch] job_id={job_id}, total={created['total']}")
|
||||
for _ in range(20):
|
||||
status = _get(f"/v1/plagiarism/batch/{job_id}")
|
||||
print(f"[batch] status={status['status']} processed={status['processed']}/{status['total']}")
|
||||
if status["status"] in ("completed", "failed"):
|
||||
print("[batch] results:")
|
||||
print(json.dumps(status.get("results"), ensure_ascii=False, indent=2))
|
||||
return
|
||||
time.sleep(0.5)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
print("=== health ===")
|
||||
print(json.dumps(_get("/v1/health"), ensure_ascii=False, indent=2))
|
||||
print()
|
||||
print("=== detect (단건) ===")
|
||||
detect_one()
|
||||
print()
|
||||
print("=== batch (비동기) ===")
|
||||
detect_batch()
|
||||
Reference in new issue
Block a user