Spaces:
Runtime error
Runtime error
Download app.py from DevSynthesis/projectAI: direct link, hf CLI and curl.
- Browser
- Download file 1.04 kB
-
https://huggingface.co/spaces/DevSynthesis/projectAI/resolve/main/app.py
- Command line
-
hf download hf://spaces/DevSynthesis/projectAI/app.py
-
curl -L -o app.py https://huggingface.co/spaces/DevSynthesis/projectAI/resolve/main/app.py
1.04 kB
| import gradio as gr | |
| import pytesseract | |
| from PIL import Image | |
| from paddleocr import PaddleOCR | |
| # Initialize PaddleOCR | |
| ocr = PaddleOCR(use_angle_cls=True, lang='en') | |
| def extract_text(image_path): | |
| # Open the image file | |
| image = Image.open(image_path).convert('L') | |
| # Extract text using Tesseract OCR | |
| tesseract_text = pytesseract.image_to_string(image) | |
| # Extract text using PaddleOCR | |
| paddle_results = ocr.ocr(image_path, cls=True) | |
| paddle_text = "\n".join([line[1][0] for result in paddle_results for line in result]) | |
| # Return extracted text from both OCR engines | |
| return f"๐ **Tesseract OCR Output:**\n{tesseract_text}\n\n๐ **PaddleOCR Output:**\n{paddle_text}" | |
| # Create Gradio Interface | |
| demo = gr.Interface( | |
| fn=extract_text, | |
| inputs=gr.Image(type="filepath"), | |
| outputs="text", | |
| title="AI-Powered Image Text Extractor", | |
| description="Upload an image containing text, and the AI will extract and display the text using both Tesseract and PaddleOCR.", | |
| ) | |
| # Launch Gradio App | |
| demo.launch() | |