nielsr HF staff commited on
Commit
c3b1890
1 Parent(s): 76ccb7b

Add more image examples

Browse files
Files changed (1) hide show
  1. app.py +7 -5
app.py CHANGED
@@ -9,10 +9,12 @@ from PIL import Image
9
  processor = TrOCRProcessor.from_pretrained("microsoft/trocr-base-handwritten")
10
  model = VisionEncoderDecoderModel.from_pretrained("microsoft/trocr-base-handwritten")
11
 
12
- # load image example from the IAM database
13
- url = 'https://fki.tic.heia-fr.ch/static/img/a01-122-02.jpg'
14
- image = Image.open(requests.get(url, stream=True).raw)
15
- image.save("image.png")
 
 
16
 
17
  def process_image(image):
18
  # prepare image
@@ -29,7 +31,7 @@ def process_image(image):
29
  title = "Interactive demo: TrOCR"
30
  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 IAM, a dataset of annotated handwritten images. To use it, simply upload a (single-text line) image or use the example image below and click 'submit'. Results will show up in a few seconds."
31
  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>"
32
- examples =[["image.png"]]
33
 
34
  #css = """.output_image, .input_image {height: 600px !important}"""
35
 
 
9
  processor = TrOCRProcessor.from_pretrained("microsoft/trocr-base-handwritten")
10
  model = VisionEncoderDecoderModel.from_pretrained("microsoft/trocr-base-handwritten")
11
 
12
+ # load image examples
13
+ urls = ['https://fki.tic.heia-fr.ch/static/img/a01-122-02.jpg', 'https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcSoolxi9yWGAT5SLZShv8vVd0bz47UWRzQC19fDTeE8GmGv_Rn-PCF1pP1rrUx8kOjA4gg&usqp=CAU',
14
+ 'https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcRNYtTuSBpZPV_nkBYPMFwVVD9asZOPgHww4epu9EqWgDmXW--sE2o8og40ZfDGo87j5w&usqp=CAU']
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 IAM, a dataset of annotated handwritten images. To use it, simply upload a (single-text line) image or use the example image 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