OCR / app.py
amirgame197's picture
Update app.py
9716110 verified
raw
history blame contribute delete
No virus
665 Bytes
import gradio as gr, pytesseract, cv2, os
def process(image: str, lang: str = 'eng') -> str:
try:
img = cv2.imread(image)
gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
threshold_img = cv2.threshold(gray, 0, 255, cv2.THRESH_BINARY + cv2.THRESH_OTSU)[1]
result = pytesseract.image_to_string(threshold_img, lang=lang)
os.remove(image)
return result
except Exception as e:
return str(e)
langs = pytesseract.get_languages()
interface = gr.Interface(
process,
[gr.Image(type="filepath"), gr.Dropdown(label="Select Language", choices=langs, type="value")],
outputs="text"
)
interface.launch()