File size: 4,682 Bytes
a216b49
 
 
 
 
 
 
 
 
7f48d7f
a216b49
 
7f48d7f
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
---
title: OCR TextVision
emoji: πŸ‘
colorFrom: indigo
colorTo: red
sdk: gradio
sdk_version: 4.44.0
app_file: app.py
pinned: false
short_description: A web-based Optical Character Recognition (OCR) application
---

# TextVision OCR Project

## Overview

TextVision is a web-based Optical Character Recognition (OCR) application that extracts text from images containing both Hindi and English text. The application also supports keyword search functionality to highlight specific words within the extracted text. It is built with a simple, intuitive interface and supports five languages: Hindi, English, Spanish, French, and Punjabi.

This project was developed as part of an assignment for a job application.

Live Demo: [TextVision on Hugging Face Spaces](https://huggingface.co/spaces/Prabhjotschugh/OCR-TextVision)

## Features

- **Image Upload**: Upload an image and extract text using OCR.
- **Multi-language Support**: Supports Hindi, English, Spanish, French, and Punjabi.
- **Keyword Search**: Search for specific keywords in the extracted text, with results highlighted if the keyword is found.
- **User-friendly Interface**: Built using Gradio, offering an intuitive and simple user experience.

## Technology Stack

- **Python 3.9+**
- **Gradio 3.50.2** for the web interface
- **PyTesseract 0.3.10** for OCR functionality
- **Pillow 10.0.1** for image processing
- **Tesseract OCR 5.3.1** as the OCR engine

## Setup and Installation (Windows)

### Installation Steps

1. **Clone or Download the Repository**:
   - Using Git:
     ```bash
     git clone https://huggingface.co/spaces/Prabhjotschugh/OCR-TextVision
     cd OCR-TextVision
     ```
   - Alternatively, download the ZIP from Hugging Face and extract it.

2. **Set up a Virtual Environment** (recommended):
   ```bash
   python -m venv venv
   venv\Scripts\activate
   ```

3. **Install Required Python Packages**:
   ```bash
   pip install -r requirements.txt
   ```

4. **Install Tesseract OCR**:
   - Download the Tesseract installer from [UB Mannheim](https://github.com/UB-Mannheim/tesseract/wiki).
   - Install it and note the installation path (default: `C:\Program Files\Tesseract-OCR`).
   - Add Tesseract to your system PATH:
     - Search for "Environment Variables" in the Start menu.
     - Under "System variables", find "Path", click "Edit", and add the Tesseract installation path.

5. **Install Language Data for Tesseract**:
   - Download language data files for Hindi (hin), Spanish (spa), French (fra), and Punjabi (pan) from [Tesseract GitHub](https://github.com/tesseract-ocr/tessdata).
   - Place them in the `tessdata` folder of your Tesseract installation directory.

6. **Configure the Application**:
   - Open `app.py` in a text editor.
   - Find the line:
     ```python
     pytesseract.pytesseract.tesseract_cmd = '/usr/bin/tesseract'
     ```
   - Replace it with:
     ```python
     pytesseract.pytesseract.tesseract_cmd = r'C:\Program Files\Tesseract-OCR\tesseract.exe'
     ```

## Running the Application

1. Open a command prompt in the project directory.

2. Activate the virtual environment (if using one):
   ```bash
   venv\Scripts\activate
   ```

3. Start the application:
   ```bash
   python app.py
   ```

4. Open a web browser and navigate to `http://localhost:7860` to access the web interface.

## Usage Instructions

1. **Upload an Image**:
   - Click on the image upload area or drag and drop an image file.
   - Supported formats: JPEG, PNG, and other common image formats.

2. **Extract Text**:
   - After uploading the image, click "Extract Text."
   - The extracted text will be displayed in the output area.

3. **Keyword Search**:
   - Check the "Do you want to search for a keyword?" box.
   - Enter a keyword, then click "Search Keyword."
   - The keyword, if found, will be highlighted in the extracted text.

4. **Clear Results**:
   - Click "Clear" to reset the interface and upload a new image.


## Example Outputs


![image/png](https://cdn-uploads.huggingface.co/production/uploads/6522888cb903b175b0db01e7/wJMcAeD6uvExq874H8RdC.png)


![image/png](https://cdn-uploads.huggingface.co/production/uploads/6522888cb903b175b0db01e7/krnEemdDfYI8XbBC1hZxJ.png)


![image/png](https://cdn-uploads.huggingface.co/production/uploads/6522888cb903b175b0db01e7/r7VuUWysnreYGeju7P4aP.png)


![image/png](https://cdn-uploads.huggingface.co/production/uploads/6522888cb903b175b0db01e7/2O4jH3iL5zAi-XPJBKuQB.png)


![image/png](https://cdn-uploads.huggingface.co/production/uploads/6522888cb903b175b0db01e7/3Y256ZpWkT4jqMPO9tiMP.png)


![image/png](https://cdn-uploads.huggingface.co/production/uploads/6522888cb903b175b0db01e7/7bz16oGtOdfAIs_hj5e3V.png)