Spaces:
Runtime error
Runtime error
business-expert commited on
Commit ·
d4f2791
1
Parent(s): 5d00597
Initial commit
Browse files- app.py +33 -0
- requirements.txt +5 -0
app.py
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
import pytesseract
|
| 3 |
+
from PIL import Image
|
| 4 |
+
from paddleocr import PaddleOCR
|
| 5 |
+
|
| 6 |
+
# Initialize PaddleOCR
|
| 7 |
+
ocr = PaddleOCR(use_angle_cls=True, lang='en')
|
| 8 |
+
|
| 9 |
+
def extract_text(image_path):
|
| 10 |
+
# Open the image file
|
| 11 |
+
image = Image.open(image_path).convert('L')
|
| 12 |
+
|
| 13 |
+
# Extract text using Tesseract OCR
|
| 14 |
+
tesseract_text = pytesseract.image_to_string(image)
|
| 15 |
+
|
| 16 |
+
# Extract text using PaddleOCR
|
| 17 |
+
paddle_results = ocr.ocr(image_path, cls=True)
|
| 18 |
+
paddle_text = "\n".join([line[1][0] for result in paddle_results for line in result])
|
| 19 |
+
|
| 20 |
+
# Return extracted text from both OCR engines
|
| 21 |
+
return f"📝 **Tesseract OCR Output:**\n{tesseract_text}\n\n🔍 **PaddleOCR Output:**\n{paddle_text}"
|
| 22 |
+
|
| 23 |
+
# Create Gradio Interface
|
| 24 |
+
demo = gr.Interface(
|
| 25 |
+
fn=extract_text,
|
| 26 |
+
inputs=gr.Image(type="filepath"),
|
| 27 |
+
outputs="text",
|
| 28 |
+
title="AI-Powered Image Text Extractor",
|
| 29 |
+
description="Upload an image containing text, and the AI will extract and display the text using both Tesseract and PaddleOCR.",
|
| 30 |
+
)
|
| 31 |
+
|
| 32 |
+
# Launch Gradio App
|
| 33 |
+
demo.launch()
|
requirements.txt
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
gradio
|
| 2 |
+
pytesseract
|
| 3 |
+
pillow
|
| 4 |
+
paddleocr
|
| 5 |
+
paddlepaddle
|