Spaces:
Sleeping
Sleeping
Update app_blocks.py
Browse files- app_blocks.py +15 -3
app_blocks.py
CHANGED
@@ -5,10 +5,22 @@ from PIL import Image
|
|
5 |
|
6 |
import gradio as gr
|
7 |
|
8 |
-
def tesseract_ocr(filepath: str, languages: List[str]=None, psm: int = 7):
|
9 |
-
image = Image.open(filepath)
|
10 |
# return pytesseract.image_to_string(image=image, lang=', '.join(languages) if languages else None, config='--psm 7')
|
11 |
-
return pytesseract.image_to_string(image=image, lang=', '.join(languages) if languages else None, config='--psm ' + str(psm))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
12 |
|
13 |
title = "Tesseract OCR"
|
14 |
description = "Gradio demo for Tesseract. Tesseract is an open source text recognition (OCR) Engine."
|
|
|
5 |
|
6 |
import gradio as gr
|
7 |
|
8 |
+
# def tesseract_ocr(filepath: str, languages: List[str]=None, psm: int = 7):
|
9 |
+
# image = Image.open(filepath)
|
10 |
# return pytesseract.image_to_string(image=image, lang=', '.join(languages) if languages else None, config='--psm 7')
|
11 |
+
# return pytesseract.image_to_string(image=image, lang=', '.join(languages) if languages else None, config='--psm ' + str(psm))
|
12 |
+
|
13 |
+
def tesseract_ocr(filepath: str, languages: List[str] = None, psm: int = 7):
|
14 |
+
if not os.path.exists(filepath):
|
15 |
+
return "Error: File not found."
|
16 |
+
|
17 |
+
try:
|
18 |
+
image = Image.open(filepath)
|
19 |
+
lang = ','.join(languages) if languages else None
|
20 |
+
config = f'--psm {psm}'
|
21 |
+
return pytesseract.image_to_string(image, lang=lang, config=config)
|
22 |
+
except Exception as e:
|
23 |
+
return f"Error: {str(e)}"
|
24 |
|
25 |
title = "Tesseract OCR"
|
26 |
description = "Gradio demo for Tesseract. Tesseract is an open source text recognition (OCR) Engine."
|