Spaces:
Build error
Build error
ankush-003
commited on
Commit
·
8d7cd2b
1
Parent(s):
048051b
init
Browse files- .gitignore +1 -0
- app.py +29 -0
- requirements.txt +0 -0
.gitignore
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
ocr
|
app.py
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from doctr.io import DocumentFile
|
| 2 |
+
from doctr.models import ocr_predictor
|
| 3 |
+
from PIL import Image
|
| 4 |
+
import gradio as gr
|
| 5 |
+
|
| 6 |
+
# Load the model
|
| 7 |
+
predictor = ocr_predictor(pretrained=True)
|
| 8 |
+
|
| 9 |
+
def read_img(image):
|
| 10 |
+
# save image
|
| 11 |
+
image = image.fromarray(image)
|
| 12 |
+
image.save('image.jpg')
|
| 13 |
+
# Read the image
|
| 14 |
+
doc = DocumentFile.from_images(image)
|
| 15 |
+
# Run the model
|
| 16 |
+
result = predictor(doc)
|
| 17 |
+
# Return the result
|
| 18 |
+
return result
|
| 19 |
+
|
| 20 |
+
app = gr.Interface(
|
| 21 |
+
title="Image OCR",
|
| 22 |
+
description="Extract text from images",
|
| 23 |
+
inputs=gr.inputs.Image(type="pil"),
|
| 24 |
+
outputs=gr.outputs.Textbox(),
|
| 25 |
+
fn=read_img
|
| 26 |
+
)
|
| 27 |
+
|
| 28 |
+
|
| 29 |
+
app.launch(debug=True)
|
requirements.txt
ADDED
|
Binary file (1.88 kB). View file
|
|
|