Spaces:
Running
Running
File size: 1,120 Bytes
2fe4a06 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
#
# Genelify.com
# Deep Learning, Machine Learning engine source code
#
# Converting image to text
# Using pytesseract and opencv
#
# Copyright Genelify, under Faisal Mochamad & Teams (2021-2024)
#
# Tool URL: https://www.genelify.com/tools/image-to-text
# Version Batch: 1.2
# ------------
import gradio as gr
import pytesseract
import cv2
def process(image, lang):
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]
return pytesseract.image_to_string(threshold_img, lang=lang)
except Exception as e:
return str(e)
choices = pytesseract.get_languages()
interface = gr.Interface(
process,
[gr.Image(type="filepath"), gr.Dropdown(label="Select Language", choices=choices, type="value")],
outputs="text",
title="Optical Character Recognition | Image To Text",
article = """<p style='text-align: center;'>Hello, thanks for coming, visit our tools: <a href="https://www.genelify.com" target="_blank">Genelify</a></p>"""
)
interface.launch() |