Spaces:
Sleeping
Sleeping
Upload 3 files
Browse files- ai_image_to_text.py +36 -0
- packages.txt +1 -0
- requirements.txt +3 -0
ai_image_to_text.py
ADDED
@@ -0,0 +1,36 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
#
|
2 |
+
# Genelify.com
|
3 |
+
# Deep Learning, Machine Learning engine source code
|
4 |
+
#
|
5 |
+
# Converting image to text
|
6 |
+
# Using pytesseract and opencv
|
7 |
+
#
|
8 |
+
# Copyright Genelify, under Faisal Mochamad & Teams (2021-2024)
|
9 |
+
#
|
10 |
+
# Tool URL: https://www.genelify.com/tools/image-to-text
|
11 |
+
# Version Batch: 1.2
|
12 |
+
# ------------
|
13 |
+
|
14 |
+
import gradio as gr
|
15 |
+
import pytesseract
|
16 |
+
import cv2
|
17 |
+
|
18 |
+
def process(image, lang):
|
19 |
+
try:
|
20 |
+
img = cv2.imread(image)
|
21 |
+
gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
|
22 |
+
threshold_img = cv2.threshold(gray, 0, 255, cv2.THRESH_BINARY + cv2.THRESH_OTSU)[1]
|
23 |
+
return pytesseract.image_to_string(threshold_img, lang=lang)
|
24 |
+
except Exception as e:
|
25 |
+
return str(e)
|
26 |
+
|
27 |
+
choices = pytesseract.get_languages()
|
28 |
+
|
29 |
+
interface = gr.Interface(
|
30 |
+
process,
|
31 |
+
[gr.Image(type="filepath"), gr.Dropdown(label="Select Language", choices=choices, type="value")],
|
32 |
+
outputs="text",
|
33 |
+
title="Optical Character Recognition | Image To Text",
|
34 |
+
article = """<p style='text-align: center;'>Hello, thanks for coming, visit our tools: <a href="https://www.genelify.com" target="_blank">Genelify</a></p>"""
|
35 |
+
)
|
36 |
+
interface.launch()
|
packages.txt
ADDED
@@ -0,0 +1 @@
|
|
|
|
|
1 |
+
tesseract-ocr-all
|
requirements.txt
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
pytesseract
|
2 |
+
opencv-python
|
3 |
+
gradio
|