mohammad2928git commited on
Commit
d93602b
·
verified ·
1 Parent(s): aa6b90d

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +5 -3
app.py CHANGED
@@ -10,7 +10,8 @@ os.environ['USE_TORCH'] = '1'
10
  import matplotlib.pyplot as plt
11
  from doctr.io import DocumentFile
12
  from doctr.models import ocr_predictor
13
-
 
14
  # util functions
15
 
16
  def prepreocess(text):
@@ -64,8 +65,9 @@ predictor = ocr_predictor(pretrained=True)
64
 
65
  def proceed(image):
66
  print("image: ", image)
67
-
68
- doc = DocumentFile.from_images(image) #reading input image
 
69
  result = predictor(doc) # extract words
70
  json_export = result.export() # convert to json
71
  out_words = [[prepreocess(w['value']) for w in line['words'] ] for line in json_export['pages'][0]['blocks'][0]['lines']] # extracting words
 
10
  import matplotlib.pyplot as plt
11
  from doctr.io import DocumentFile
12
  from doctr.models import ocr_predictor
13
+ from PIL import Image
14
+ import numpy as np
15
  # util functions
16
 
17
  def prepreocess(text):
 
65
 
66
  def proceed(image):
67
  print("image: ", image)
68
+ im = Image.fromarray(np.array(image))
69
+ im.save("temp.jpg")
70
+ doc = DocumentFile.from_images("temp.jpg") #reading input image
71
  result = predictor(doc) # extract words
72
  json_export = result.export() # convert to json
73
  out_words = [[prepreocess(w['value']) for w in line['words'] ] for line in json_export['pages'][0]['blocks'][0]['lines']] # extracting words