KeyarSrini commited on
Commit
8ea123e
·
verified ·
1 Parent(s): 9fe1a74

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +25 -10
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 extract_text(image):
9
- image = np.array(image.convert("RGB"))
10
- results = reader.readtext(image)
11
- texts = [text for _, text, _ in results]
12
- return "\n".join(texts)
 
 
 
 
 
 
 
 
 
13
 
14
- gr.Interface(
15
- fn=extract_text,
 
16
  inputs=gr.Image(type="pil", label="Upload Receipt"),
17
- outputs=gr.Textbox(label="Extracted Text"),
18
- title="Receipt Reader Test",
19
- ).launch()
 
 
 
 
 
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()