Handle new PaddleOCR output format
Browse files
app.py
CHANGED
|
@@ -90,15 +90,32 @@ def analyze_medication_image(image: Image.Image) -> Tuple[str, str]:
|
|
| 90 |
# Step 1: OCR - PaddleOCR로 한글 텍스트 추출
|
| 91 |
start_time = time.time()
|
| 92 |
img_array = np.array(image)
|
| 93 |
-
ocr_results = OCR_READER.ocr(img_array
|
| 94 |
ocr_time = time.time() - start_time
|
| 95 |
print(f"⏱️ OCR took {ocr_time:.2f}s")
|
| 96 |
|
| 97 |
-
if not ocr_results
|
| 98 |
return "텍스트를 찾을 수 없습니다.", ""
|
| 99 |
|
| 100 |
# 텍스트 추출
|
| 101 |
-
texts
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 102 |
ocr_text = "\n".join(texts)
|
| 103 |
|
| 104 |
# Step 2: 약 정보 분석 - MedGemma로 의료 정보 제공
|
|
|
|
| 90 |
# Step 1: OCR - PaddleOCR로 한글 텍스트 추출
|
| 91 |
start_time = time.time()
|
| 92 |
img_array = np.array(image)
|
| 93 |
+
ocr_results = OCR_READER.ocr(img_array)
|
| 94 |
ocr_time = time.time() - start_time
|
| 95 |
print(f"⏱️ OCR took {ocr_time:.2f}s")
|
| 96 |
|
| 97 |
+
if not ocr_results:
|
| 98 |
return "텍스트를 찾을 수 없습니다.", ""
|
| 99 |
|
| 100 |
# 텍스트 추출
|
| 101 |
+
texts: List[str] = []
|
| 102 |
+
first_entry = ocr_results[0]
|
| 103 |
+
|
| 104 |
+
if isinstance(first_entry, list):
|
| 105 |
+
texts = [line[1][0] for line in first_entry if len(line) > 1 and line[1]]
|
| 106 |
+
elif isinstance(first_entry, dict):
|
| 107 |
+
rec_results = first_entry.get("text_recognition") or first_entry.get("rec_results")
|
| 108 |
+
if isinstance(rec_results, list):
|
| 109 |
+
for rec in rec_results:
|
| 110 |
+
if isinstance(rec, dict) and rec.get("text"):
|
| 111 |
+
texts.append(rec["text"])
|
| 112 |
+
|
| 113 |
+
if not texts and isinstance(first_entry.get("text"), str):
|
| 114 |
+
texts.append(first_entry["text"])
|
| 115 |
+
|
| 116 |
+
if not texts:
|
| 117 |
+
return "텍스트를 찾을 수 없습니다.", ""
|
| 118 |
+
|
| 119 |
ocr_text = "\n".join(texts)
|
| 120 |
|
| 121 |
# Step 2: 약 정보 분석 - MedGemma로 의료 정보 제공
|