quocanh944 commited on
Commit
a1f1cc4
β€’
1 Parent(s): 93df5a7

fix url and app

Browse files
app.py CHANGED
@@ -5,15 +5,6 @@ from PIL import Image
5
  processor = TrOCRProcessor.from_pretrained("microsoft/trocr-base-handwritten")
6
  model = VisionEncoderDecoderModel.from_pretrained("quocanh944/tr-ocr")
7
 
8
- # load image examples from the IAM database
9
- urls = ['./images/a01-000u-00.png',
10
- './images/a01-000x-04.png',
11
- './images/a01-003-10.png']
12
-
13
- for idx, url in enumerate(urls):
14
- image = Image.open(url)
15
- image.save(f"image_{idx}.png")
16
-
17
  def process_image(image):
18
  # prepare image
19
  pixel_values = processor(image, return_tensors="pt").pixel_values
@@ -29,11 +20,11 @@ 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 an image or use the example image below and click 'submit'. Results will show up in a few seconds."
31
  article = "TrOCR: Transformer-based Optical Character Recognition with Pre-trained Models | Github Repo"
32
- examples =[["image_0.png"], ["image_1.png"], ["image_2.png"]]
33
 
34
  iface = gr.Interface(fn=process_image,
35
- inputs=gr.inputs.Image(type="pil"),
36
- outputs=gr.outputs.Textbox(),
37
  title=title,
38
  description=description,
39
  article=article,
 
5
  processor = TrOCRProcessor.from_pretrained("microsoft/trocr-base-handwritten")
6
  model = VisionEncoderDecoderModel.from_pretrained("quocanh944/tr-ocr")
7
 
 
 
 
 
 
 
 
 
 
8
  def process_image(image):
9
  # prepare image
10
  pixel_values = processor(image, return_tensors="pt").pixel_values
 
20
  title = "Interactive demo: TrOCR"
21
  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 an image or use the example image below and click 'submit'. Results will show up in a few seconds."
22
  article = "TrOCR: Transformer-based Optical Character Recognition with Pre-trained Models | Github Repo"
23
+ examples =[["./images/image_0.png"], ["./images/image_1.png"], ["./images/image_2.png"], ["./images/image_3.png"]]
24
 
25
  iface = gr.Interface(fn=process_image,
26
+ inputs=gr.Image(type="pil"),
27
+ outputs=gr.Textbox(),
28
  title=title,
29
  description=description,
30
  article=article,
images/{a01-003-08.png β†’ image_0.png} RENAMED
File without changes
images/{a01-003u-01.png β†’ image_1.png} RENAMED
File without changes
images/{a01-003u-00.png β†’ image_2.png} RENAMED
File without changes
images/{a01-003-10.png β†’ image_3.png} RENAMED
File without changes