vteam27
commited on
Commit
•
dbdbddf
1
Parent(s):
32d1a1b
added initial files
Browse files- app.py +27 -0
- packages.txt +3 -0
- requirements.txt +3 -0
app.py
ADDED
@@ -0,0 +1,27 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import os
|
2 |
+
os.environ['USE_TORCH'] = '1'
|
3 |
+
|
4 |
+
from doctr.io import DocumentFile
|
5 |
+
from doctr.models import ocr_predictor
|
6 |
+
import gradio as gr
|
7 |
+
from PIL import Image
|
8 |
+
|
9 |
+
predictor = ocr_predictor(pretrained=True)
|
10 |
+
|
11 |
+
def greet(img):
|
12 |
+
img.save("out.jpg")
|
13 |
+
doc = DocumentFile.from_images("out.jpg")
|
14 |
+
output=predictor(doc)
|
15 |
+
res=""
|
16 |
+
for obj in output.pages:
|
17 |
+
for obj1 in obj.blocks:
|
18 |
+
for obj2 in obj1.lines:
|
19 |
+
for obj3 in obj2.words:
|
20 |
+
res=res + " " + obj3.value
|
21 |
+
res=res + "\n"
|
22 |
+
res=res + "\n"
|
23 |
+
return res
|
24 |
+
|
25 |
+
demo = gr.Interface(fn=greet, inputs=gr.Image(type="pil"), outputs="text")
|
26 |
+
|
27 |
+
demo.launch(share=True)
|
packages.txt
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
libcairo2-dev
|
2 |
+
pkg-config
|
3 |
+
fonts-freefont-ttf -y
|
requirements.txt
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
pycairo
|
2 |
+
python-doctr[torch]@git+https://github.com/mindee/doctr.git
|
3 |
+
gradio
|