Spaces:
Runtime error
Runtime error
Add aplication file
Browse files- ImaText.py +26 -0
- requirements.txt +1 -0
ImaText.py
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import cv2
|
| 2 |
+
import pytesseract
|
| 3 |
+
import gradio as gr
|
| 4 |
+
|
| 5 |
+
# ------------------------- Function to extract text from an image -------------------------
|
| 6 |
+
def extract_text_from_image(image):
|
| 7 |
+
pytesseract.pytesseract.tesseract_cmd = r'C:\Program Files\Tesseract-OCR\tesseract.exe'
|
| 8 |
+
gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY) # Convert the image from BGR to grayscale
|
| 9 |
+
text = pytesseract.image_to_string(gray) # Extract text from the grayscale image
|
| 10 |
+
return text
|
| 11 |
+
|
| 12 |
+
|
| 13 |
+
#------------------------------- Graphic interface --------------------------------
|
| 14 |
+
# Define Gradio interface
|
| 15 |
+
iface = gr.Interface(
|
| 16 |
+
fn=extract_text_from_image,
|
| 17 |
+
inputs=gr.Image(numpy="file", label="Upload Image"),
|
| 18 |
+
outputs="text",
|
| 19 |
+
title="OCR APP ",
|
| 20 |
+
description="Upload an image and we'll extract the text for you.",
|
| 21 |
+
layout="unaligned",
|
| 22 |
+
)
|
| 23 |
+
|
| 24 |
+
# Launch Gradio Interface
|
| 25 |
+
iface.launch(share=True)
|
| 26 |
+
|
requirements.txt
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
|