jacobmp commited on
Commit
208e4e2
·
verified ·
1 Parent(s): 9ff8035

Added progress bar

Browse files
Files changed (1) hide show
  1. app.py +4 -3
app.py CHANGED
@@ -7,7 +7,8 @@ from ultralytics import YOLO
7
  from PIL import Image
8
  import torch
9
 
10
- def process(path):
 
11
  LINE_MODEL_PATH = "Kansallisarkisto/multicentury-textline-detection"
12
  #OCR_MODEL_PATH = "Kansallisarkisto/multicentury-htr-model"
13
  OCR_MODEL_PATH = "microsoft/trocr-large-handwritten"
@@ -18,7 +19,7 @@ def process(path):
18
 
19
  # Open an image of handwritten text
20
  image = Image.open(path).convert("RGB")
21
-
22
  try:
23
  # Load the trained line detection model
24
  cached_model_path = hf_hub_download(repo_id = LINE_MODEL_PATH, filename="lines_20240827.pt")
@@ -31,7 +32,7 @@ def process(path):
31
  boxes = results.boxes.xyxy
32
  indices = boxes[:,1].sort().indices
33
  boxes = boxes[indices]
34
- for box in boxes:
35
  #box = box + torch.tensor([-10,0, 10, 0])
36
  box = [tensor.item() for tensor in box]
37
  lineImg = image.crop(tuple(list(box)))
 
7
  from PIL import Image
8
  import torch
9
 
10
+ def process(path, progress = gr.Progress()):
11
+ progress(0, desc="Starting")
12
  LINE_MODEL_PATH = "Kansallisarkisto/multicentury-textline-detection"
13
  #OCR_MODEL_PATH = "Kansallisarkisto/multicentury-htr-model"
14
  OCR_MODEL_PATH = "microsoft/trocr-large-handwritten"
 
19
 
20
  # Open an image of handwritten text
21
  image = Image.open(path).convert("RGB")
22
+ progress(0, desc="Extracting Text Lines")
23
  try:
24
  # Load the trained line detection model
25
  cached_model_path = hf_hub_download(repo_id = LINE_MODEL_PATH, filename="lines_20240827.pt")
 
32
  boxes = results.boxes.xyxy
33
  indices = boxes[:,1].sort().indices
34
  boxes = boxes[indices]
35
+ for box in progress.tqdm(boxes, desc="Text Recognition"):
36
  #box = box + torch.tensor([-10,0, 10, 0])
37
  box = [tensor.item() for tensor in box]
38
  lineImg = image.crop(tuple(list(box)))