JustinLin610 commited on
Commit
fb33609
1 Parent(s): 752f7ec
Files changed (2) hide show
  1. app.py +3 -3
  2. ezocr/easyocrlite/reader.py +2 -2
app.py CHANGED
@@ -66,7 +66,7 @@ def four_point_transform(image: np.ndarray, rect: FourPoint) -> np.ndarray:
66
  return warped
67
 
68
 
69
- def get_images(img, reader: ReaderLite, **kwargs):
70
  results = reader.process(img, **kwargs)
71
  return results
72
 
@@ -164,7 +164,7 @@ def apply_half(t):
164
 
165
 
166
  def ocr(img):
167
- out_img = img
168
  results = get_images(img, reader)
169
  box_list, image_list = zip(*results)
170
  draw_boxes(out_img, box_list)
@@ -191,7 +191,7 @@ description = "Gradio Demo for OFA-OCR. Upload your own image or click any one o
191
  article = "<p style='text-align: center'><a href='https://github.com/OFA-Sys/OFA' target='_blank'>OFA Github " \
192
  "Repo</a></p> "
193
  examples = [['lihe.png']]
194
- io = gr.Interface(fn=ocr, inputs=gr.inputs.Image(type='pil'),
195
  outputs=[gr.outputs.Image(type='pil'), gr.outputs.Textbox(label="OCR result")],
196
  title=title, description=description, article=article, examples=examples,
197
  allow_flagging=False, allow_screenshot=False)
 
66
  return warped
67
 
68
 
69
+ def get_images(img: str, reader: ReaderLite, **kwargs):
70
  results = reader.process(img, **kwargs)
71
  return results
72
 
 
164
 
165
 
166
  def ocr(img):
167
+ out_img = Image.open(img)
168
  results = get_images(img, reader)
169
  box_list, image_list = zip(*results)
170
  draw_boxes(out_img, box_list)
 
191
  article = "<p style='text-align: center'><a href='https://github.com/OFA-Sys/OFA' target='_blank'>OFA Github " \
192
  "Repo</a></p> "
193
  examples = [['lihe.png']]
194
+ io = gr.Interface(fn=ocr, inputs=gr.inputs.Image(type='filepath'),
195
  outputs=[gr.outputs.Image(type='pil'), gr.outputs.Textbox(label="OCR result")],
196
  title=title, description=description, article=article, examples=examples,
197
  allow_flagging=False, allow_screenshot=False)
ezocr/easyocrlite/reader.py CHANGED
@@ -104,7 +104,7 @@ class ReaderLite(object):
104
 
105
  def process(
106
  self,
107
- img,
108
  max_size: int = 960,
109
  expand_ratio: float = 1.0,
110
  sharp: float = 1.0,
@@ -121,7 +121,7 @@ class ReaderLite(object):
121
  min_size: float = 0.01,
122
  ) -> Tuple[BoxTuple, list[np.ndarray]]:
123
 
124
- image = img.convert('RGB')
125
  tensor, inverse_ratio = self.preprocess(
126
  image, max_size, expand_ratio, sharp, contrast
127
  )
 
104
 
105
  def process(
106
  self,
107
+ image_path: str,
108
  max_size: int = 960,
109
  expand_ratio: float = 1.0,
110
  sharp: float = 1.0,
 
121
  min_size: float = 0.01,
122
  ) -> Tuple[BoxTuple, list[np.ndarray]]:
123
 
124
+ image = Image.open(image_path).convert('RGB')
125
  tensor, inverse_ratio = self.preprocess(
126
  image, max_size, expand_ratio, sharp, contrast
127
  )