rmayormartins commited on
Commit
4f90a60
1 Parent(s): 8eb1691

Subindo arquivos3

Browse files
Files changed (1) hide show
  1. app.py +28 -10
app.py CHANGED
@@ -1,22 +1,40 @@
 
1
  import pytesseract
2
  from PIL import Image
3
- import gradio as gr
 
 
 
4
 
5
- # Definindo a função de OCR
6
- def extract_text_from_image(image):
7
- text = pytesseract.image_to_string(image)
8
- return text
9
 
10
- # Criando a interface do Gradio
 
 
 
 
 
 
 
 
 
 
 
 
 
11
  iface = gr.Interface(
12
  fn=extract_text_from_image,
13
- inputs="image",
14
  outputs="text",
15
- title="OCR-img2txt",
16
- description="This application uses Optical Character Recognition (OCR) technology to extract text from images. It employs the Tesseract OCR engine to process images containing printed text, converting it into editable and searchable text. Ideal for digitizing documents, extracting text from photos, and converting scanned images into text formats."
 
17
  )
18
 
19
- # Executando a interface
20
  iface.launch(debug=True)
21
 
22
 
 
 
1
+ import gradio as gr
2
  import pytesseract
3
  from PIL import Image
4
+ import easyocr
5
+
6
+ #
7
+ easyocr_reader = easyocr.Reader(['en', 'pt', 'es'], gpu=False) #
8
 
9
+ #Tesseract
10
+ def tesseract_ocr(image):
11
+ return pytesseract.image_to_string(image)
 
12
 
13
+ #EasyOCR
14
+ def easyocr_ocr(image):
15
+ return ' '.join(easyocr_reader.readtext(image, detail=0))
16
+
17
+ #
18
+ def extract_text_from_image(ocr_engine, image):
19
+ if ocr_engine == "Tesseract":
20
+ return tesseract_ocr(image)
21
+ elif ocr_engine == "EasyOCR":
22
+ return easyocr_ocr(image)
23
+ else:
24
+ return "Invalid OCR selection."
25
+
26
+ #Gradio
27
  iface = gr.Interface(
28
  fn=extract_text_from_image,
29
+ inputs=[gr.Dropdown(["Tesseract", "EasyOCR"], label="Select the OCR Engine"), "image"],
30
  outputs="text",
31
+ title="OCR Img2txt",
32
+ description="This application uses Optical Character Recognition (OCR) technology to extract text from images. Choose between Tesseract OCR and EasyOCR engine to process images containing printed text, converting it into editable and searchable text."
33
+ examples=[["confusionmatrix.jpg"]]
34
  )
35
 
36
+ #
37
  iface.launch(debug=True)
38
 
39
 
40
+