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

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +8 -8
app.py CHANGED
@@ -3,29 +3,29 @@ 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",
 
3
  import cv2
4
  import os
5
 
6
+ def process(files, lang: str = 'eng') -> str:
7
  results = []
8
+ for file in files:
9
  try:
10
+ img = cv2.imread(file)
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 {file}: {str(e)}")
17
  finally:
18
+ os.remove(file)
19
  return "\n\n".join(results)
20
 
21
+ # Get available languages for pytesseract
22
  langs = pytesseract.get_languages()
23
 
24
+ # Define the Gradio interface using gr.Files to allow multiple file uploads
25
  interface = gr.Interface(
26
  fn=process,
27
  inputs=[
28
+ gr.Files(label="Upload Images", file_count="multiple", type="filepath"),
29
  gr.Dropdown(label="Select Language", choices=langs, type="value")
30
  ],
31
  outputs="text",