mikegerber commited on
Commit
6104a90
1 Parent(s): d9ddda8

Use our examples

Browse files
Files changed (1) hide show
  1. app.py +7 -5
app.py CHANGED
@@ -11,10 +11,10 @@ model = VisionEncoderDecoderModel.from_pretrained("microsoft/trocr-base-printed"
11
  model.config.eos_token_id = 2
12
 
13
  # load image examples
14
- urls = ['https://layoutlm.blob.core.windows.net/trocr/dataset/SROIE2019Task2Crop/train/X00016469612_1.jpg', 'https://layoutlm.blob.core.windows.net/trocr/dataset/SROIE2019Task2Crop/train/X51005255805_7.jpg', 'https://layoutlm.blob.core.windows.net/trocr/dataset/SROIE2019Task2Crop/train/X51005745214_6.jpg']
15
- for idx, url in enumerate(urls):
16
- image = Image.open(requests.get(url, stream=True).raw)
17
- image.save(f"image_{idx}.png")
18
 
19
  def process_image(image):
20
  # prepare image
@@ -31,7 +31,9 @@ def process_image(image):
31
  title = "Interactive demo: TrOCR"
32
  description = "Demo for Microsoft's TrOCR, an encoder-decoder model consisting of an image Transformer encoder and a text Transformer decoder for state-of-the-art optical character recognition (OCR) on single-text line images. This particular model is fine-tuned on SROIE Task 2, a dataset of annotated printed images. To use it, simply upload a (single-text line) image or use one of the example images below and click 'submit'. Results will show up in a few seconds."
33
  article = "<p style='text-align: center'><a href='https://arxiv.org/abs/2109.10282'>TrOCR: Transformer-based Optical Character Recognition with Pre-trained Models</a> | <a href='https://github.com/microsoft/unilm/tree/master/trocr'>Github Repo</a></p>"
34
- examples =[["image_0.png"], ["image_1.png"], ["image_2.png"]]
 
 
35
 
36
  #css = """.output_image, .input_image {height: 600px !important}"""
37
 
 
11
  model.config.eos_token_id = 2
12
 
13
  # load image examples
14
+ #urls = ['https://layoutlm.blob.core.windows.net/trocr/dataset/SROIE2019Task2Crop/train/X00016469612_1.jpg', 'https://layoutlm.blob.core.windows.net/trocr/dataset/SROIE2019Task2Crop/train/X51005255805_7.jpg', 'https://layoutlm.blob.core.windows.net/trocr/dataset/SROIE2019Task2Crop/train/X51005745214_6.jpg']
15
+ #for idx, url in enumerate(urls):
16
+ # image = Image.open(requests.get(url, stream=True).raw)
17
+ # image.save(f"image_{idx}.png")
18
 
19
  def process_image(image):
20
  # prepare image
 
31
  title = "Interactive demo: TrOCR"
32
  description = "Demo for Microsoft's TrOCR, an encoder-decoder model consisting of an image Transformer encoder and a text Transformer decoder for state-of-the-art optical character recognition (OCR) on single-text line images. This particular model is fine-tuned on SROIE Task 2, a dataset of annotated printed images. To use it, simply upload a (single-text line) image or use one of the example images below and click 'submit'. Results will show up in a few seconds."
33
  article = "<p style='text-align: center'><a href='https://arxiv.org/abs/2109.10282'>TrOCR: Transformer-based Optical Character Recognition with Pre-trained Models</a> | <a href='https://github.com/microsoft/unilm/tree/master/trocr'>Github Repo</a></p>"
34
+ #examples =[["image_0.png"], ["image_1.png"], ["image_2.png"]]
35
+ examples = [["example-line-0.png"], ["example-line-1.png"],["example-line-2.png"]]
36
+
37
 
38
  #css = """.output_image, .input_image {height: 600px !important}"""
39