Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -3,17 +3,32 @@ import easyocr
|
|
| 3 |
import numpy as np
|
| 4 |
from PIL import Image
|
| 5 |
|
|
|
|
| 6 |
reader = easyocr.Reader(['en'])
|
| 7 |
|
| 8 |
-
def
|
| 9 |
-
image
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 13 |
|
| 14 |
-
|
| 15 |
-
|
|
|
|
| 16 |
inputs=gr.Image(type="pil", label="Upload Receipt"),
|
| 17 |
-
outputs=gr.
|
| 18 |
-
title="Receipt Reader
|
| 19 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 3 |
import numpy as np
|
| 4 |
from PIL import Image
|
| 5 |
|
| 6 |
+
# Load EasyOCR reader
|
| 7 |
reader = easyocr.Reader(['en'])
|
| 8 |
|
| 9 |
+
def extract_receipt_details(image):
|
| 10 |
+
# Convert PIL image to numpy array
|
| 11 |
+
img = np.array(image)
|
| 12 |
+
|
| 13 |
+
# OCR Processing
|
| 14 |
+
results = reader.readtext(img)
|
| 15 |
+
|
| 16 |
+
# Format results
|
| 17 |
+
extracted_text = [text for _, text, _ in results]
|
| 18 |
+
full_text = "\n".join(extracted_text)
|
| 19 |
+
|
| 20 |
+
return {
|
| 21 |
+
"Extracted Text": full_text
|
| 22 |
+
}
|
| 23 |
|
| 24 |
+
# Gradio UI
|
| 25 |
+
demo = gr.Interface(
|
| 26 |
+
fn=extract_receipt_details,
|
| 27 |
inputs=gr.Image(type="pil", label="Upload Receipt"),
|
| 28 |
+
outputs=gr.JSON(label="Extracted Receipt Text"),
|
| 29 |
+
title="🧾 Receipt Reader AI",
|
| 30 |
+
description="Upload any printed or handwritten receipt and get extracted text using OCR."
|
| 31 |
+
)
|
| 32 |
+
|
| 33 |
+
if __name__ == "__main__":
|
| 34 |
+
demo.launch()
|