File size: 647 Bytes
dbdbddf
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
import os
os.environ['USE_TORCH'] = '1'

from doctr.io import DocumentFile
from doctr.models import ocr_predictor
import gradio as gr
from PIL import Image

predictor = ocr_predictor(pretrained=True)

def greet(img):
    img.save("out.jpg")
    doc = DocumentFile.from_images("out.jpg")
    output=predictor(doc)
    res=""
    for obj in output.pages:
      for obj1 in obj.blocks:
        for obj2 in obj1.lines:
          for obj3 in obj2.words:
            res=res + " " + obj3.value
        res=res + "\n"
      res=res + "\n"
    return res

demo = gr.Interface(fn=greet, inputs=gr.Image(type="pil"), outputs="text")

demo.launch(share=True)