SmokeyBandit commited on
Commit
4dd8bbe
·
verified ·
1 Parent(s): ede6ff8

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +37 -16
app.py CHANGED
@@ -1,24 +1,45 @@
1
- import gradio as gr, pytesseract, cv2, os
 
 
 
2
 
3
- def process(image: str, lang: str = 'eng') -> str:
4
- try:
5
- img = cv2.imread(image)
6
- gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
7
- _,threshold_img = cv2.threshold(gray, 127, 255, cv2.THRESH_TOZERO)
8
- result = pytesseract.image_to_string(threshold_img, lang=lang)
9
- os.remove(image)
10
- return result
11
- except Exception as e:
12
- return str(e)
 
 
 
 
13
 
 
14
  langs = pytesseract.get_languages()
15
 
 
16
  interface = gr.Interface(
17
- process,
18
- [gr.Image(type="filepath"), gr.Dropdown(label="Select Language", choices=langs, type="value")],
 
 
 
19
  outputs="text",
20
  css="footer {visibility: hidden}",
21
- title="Optical Character Recognition | Image To Text",
22
- article = """<p style='text-align: center;'>Hello, thanks for coming, visit AI tools: <a href="https://www.genelify.com" target="_blank">Genelify</a>, visit Social Media tools: <a href="https://www.tubtic.com" target="_blank">Tubtic</a></p>"""
 
 
 
 
 
 
 
23
  )
24
- interface.launch(show_api=False)
 
 
 
1
+ import gradio as gr
2
+ import pytesseract
3
+ import cv2
4
+ import os
5
 
6
+ def process(images, lang: str = 'eng') -> str:
7
+ results = []
8
+ for image in images:
9
+ try:
10
+ img = cv2.imread(image)
11
+ gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
12
+ _, threshold_img = cv2.threshold(gray, 127, 255, cv2.THRESH_TOZERO)
13
+ result = pytesseract.image_to_string(threshold_img, lang=lang)
14
+ results.append(result)
15
+ except Exception as e:
16
+ results.append(f"Error processing {image}: {str(e)}")
17
+ finally:
18
+ os.remove(image)
19
+ return "\n\n".join(results)
20
 
21
+ # Get the available languages for pytesseract
22
  langs = pytesseract.get_languages()
23
 
24
+ # Define the Gradio interface
25
  interface = gr.Interface(
26
+ fn=process,
27
+ inputs=[
28
+ gr.Image(type="filepath", multiple=True),
29
+ gr.Dropdown(label="Select Language", choices=langs, type="value")
30
+ ],
31
  outputs="text",
32
  css="footer {visibility: hidden}",
33
+ title="Optical Character Recognition | Batch Image To Text",
34
+ article="""
35
+ <p style='text-align: center;'>
36
+ Hello, thanks for coming! Visit AI tools:
37
+ <a href="https://www.genelify.com" target="_blank">Genelify</a>,
38
+ and check out Social Media tools:
39
+ <a href="https://www.tubtic.com" target="_blank">Tubtic</a>
40
+ </p>
41
+ """
42
  )
43
+
44
+ # Launch the interface
45
+ interface.launch(show_api=False)