Spaces:
Running
Running
Commit
Β·
b38b9a9
1
Parent(s):
1691ca8
π Optimize for HuggingFace Spaces deployment
Browse files- Update requirements.txt with HF-specific optimizations
- Add HF Spaces environment detection in app.py
- Update README.md with correct GitHub URL and architecture
- Configure proper ports for HF Spaces (7860) vs local (7861)
- Add huggingface_hub dependency for better compatibility
- README.md +6 -3
- app.py +24 -8
- requirements.txt +4 -1
README.md
CHANGED
@@ -33,14 +33,17 @@ textlens-ocr/
|
|
33 |
βββ app.py # Main Gradio application
|
34 |
βββ requirements.txt # Python dependencies
|
35 |
βββ README.md # Project documentation
|
36 |
-
βββ test_ocr.py # Test suite
|
37 |
βββ models/ # OCR processing modules
|
38 |
β βββ __init__.py
|
39 |
β βββ ocr_processor.py # Advanced OCR class with fallbacks
|
40 |
βββ utils/ # Utility functions
|
41 |
β βββ __init__.py
|
42 |
β βββ image_utils.py # Image preprocessing utilities
|
43 |
-
βββ
|
|
|
|
|
|
|
|
|
44 |
```
|
45 |
|
46 |
## π Quick Start
|
@@ -50,7 +53,7 @@ textlens-ocr/
|
|
50 |
1. **Clone the repository**
|
51 |
|
52 |
```bash
|
53 |
-
git clone
|
54 |
cd textlens-ocr
|
55 |
```
|
56 |
|
|
|
33 |
βββ app.py # Main Gradio application
|
34 |
βββ requirements.txt # Python dependencies
|
35 |
βββ README.md # Project documentation
|
|
|
36 |
βββ models/ # OCR processing modules
|
37 |
β βββ __init__.py
|
38 |
β βββ ocr_processor.py # Advanced OCR class with fallbacks
|
39 |
βββ utils/ # Utility functions
|
40 |
β βββ __init__.py
|
41 |
β βββ image_utils.py # Image preprocessing utilities
|
42 |
+
βββ ui/ # User interface components
|
43 |
+
βββ __init__.py
|
44 |
+
βββ interface.py # Gradio interface
|
45 |
+
βββ handlers.py # Event handlers
|
46 |
+
βββ styles.py # CSS styling
|
47 |
```
|
48 |
|
49 |
## π Quick Start
|
|
|
53 |
1. **Clone the repository**
|
54 |
|
55 |
```bash
|
56 |
+
git clone https://github.com/KumarAmrit30/textlens-ocr.git
|
57 |
cd textlens-ocr
|
58 |
```
|
59 |
|
app.py
CHANGED
@@ -4,6 +4,7 @@ TextLens - AI-Powered OCR Application
|
|
4 |
Main entry point for the application.
|
5 |
"""
|
6 |
|
|
|
7 |
import logging
|
8 |
from ui.interface import create_interface
|
9 |
|
@@ -15,16 +16,31 @@ def main():
|
|
15 |
"""Main function to launch the application."""
|
16 |
logger.info("π Starting TextLens OCR application...")
|
17 |
|
|
|
|
|
|
|
18 |
try:
|
19 |
interface = create_interface()
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
28 |
|
29 |
except Exception as e:
|
30 |
logger.error(f"Failed to start application: {str(e)}")
|
|
|
4 |
Main entry point for the application.
|
5 |
"""
|
6 |
|
7 |
+
import os
|
8 |
import logging
|
9 |
from ui.interface import create_interface
|
10 |
|
|
|
16 |
"""Main function to launch the application."""
|
17 |
logger.info("π Starting TextLens OCR application...")
|
18 |
|
19 |
+
# Check if running on HuggingFace Spaces
|
20 |
+
is_hf_spaces = os.getenv("SPACE_ID") is not None
|
21 |
+
|
22 |
try:
|
23 |
interface = create_interface()
|
24 |
+
|
25 |
+
# Configure for HuggingFace Spaces or local deployment
|
26 |
+
if is_hf_spaces:
|
27 |
+
logger.info("π€ Running on HuggingFace Spaces")
|
28 |
+
interface.launch(
|
29 |
+
share=False,
|
30 |
+
server_name="0.0.0.0",
|
31 |
+
server_port=7860, # HF Spaces default port
|
32 |
+
show_error=True
|
33 |
+
)
|
34 |
+
else:
|
35 |
+
logger.info("π» Running locally")
|
36 |
+
interface.launch(
|
37 |
+
share=False,
|
38 |
+
server_name="0.0.0.0",
|
39 |
+
server_port=7861,
|
40 |
+
show_error=True,
|
41 |
+
favicon_path=None,
|
42 |
+
ssl_verify=False
|
43 |
+
)
|
44 |
|
45 |
except Exception as e:
|
46 |
logger.error(f"Failed to start application: {str(e)}")
|
requirements.txt
CHANGED
@@ -26,4 +26,7 @@ urllib3>=1.26.0
|
|
26 |
numpy>=1.21.0
|
27 |
requests>=2.25.0
|
28 |
einops>=0.6.0
|
29 |
-
timm>=0.9.0
|
|
|
|
|
|
|
|
26 |
numpy>=1.21.0
|
27 |
requests>=2.25.0
|
28 |
einops>=0.6.0
|
29 |
+
timm>=0.9.0
|
30 |
+
|
31 |
+
# HuggingFace Spaces optimizations
|
32 |
+
huggingface_hub>=0.16.0
|