LLDDWW commited on
Commit
72114b8
·
1 Parent(s): 149f48c

perf: switch ocr to trocr large

Browse files
Files changed (2) hide show
  1. app.py +11 -2
  2. requirements.txt +2 -1
app.py CHANGED
@@ -3,12 +3,21 @@ import re
3
  from typing import Any, Dict, List, Optional, Sequence
4
 
5
  import gradio as gr
 
6
  from PIL import Image, ImageDraw
7
  from transformers import pipeline
8
 
9
  # --- OCR pipeline ---------------------------------------------------------
10
- # We use a light-weight printed-text OCR model that works well for receipts/labels.
11
- ocr = pipeline("image-to-text", model="microsoft/trocr-base-printed")
 
 
 
 
 
 
 
 
12
 
13
  # Korean keywords describing time slots on prescription labels.
14
  TIME_KEYWORDS = [
 
3
  from typing import Any, Dict, List, Optional, Sequence
4
 
5
  import gradio as gr
6
+ import torch
7
  from PIL import Image, ImageDraw
8
  from transformers import pipeline
9
 
10
  # --- OCR pipeline ---------------------------------------------------------
11
+ # Use a high-capacity OCR model for better accuracy on prescription labels.
12
+ MODEL_ID = "microsoft/trocr-large-printed"
13
+
14
+
15
+ def _load_ocr():
16
+ device = 0 if torch.cuda.is_available() else -1
17
+ return pipeline("image-to-text", model=MODEL_ID, device=device)
18
+
19
+
20
+ ocr = _load_ocr()
21
 
22
  # Korean keywords describing time slots on prescription labels.
23
  TIME_KEYWORDS = [
requirements.txt CHANGED
@@ -1,4 +1,5 @@
1
  transformers
 
2
  gradio
3
  Pillow
4
- torch
 
1
  transformers
2
+ torch
3
  gradio
4
  Pillow
5
+ torch