GoConqurer commited on
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

Files changed (3) hide show
  1. README.md +6 -3
  2. app.py +24 -8
  3. 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
- └── textlens_env/ # Virtual environment
 
 
 
 
44
  ```
45
 
46
  ## πŸš€ Quick Start
@@ -50,7 +53,7 @@ textlens-ocr/
50
  1. **Clone the repository**
51
 
52
  ```bash
53
- git clone <repository-url>
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
- interface.launch(
21
- share=False,
22
- server_name="0.0.0.0",
23
- server_port=7861,
24
- show_error=True,
25
- favicon_path=None,
26
- ssl_verify=False
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