@@ -16,7 +16,6 @@ AltTextGenerator is a Python script designed to automatically generate alt text
16
16
- Pillow (>=11.1.0,<12.0.0) for image handling
17
17
- Hugging Face Transformers (>=4.48.0,<5.0.0) library
18
18
- torch (>=2.5.1,<3.0.0) library
19
- - pytest 7.4.4 or above for testing
20
19
21
20
## Installation
22
21
@@ -26,7 +25,7 @@ AltTextGenerator is a Python script designed to automatically generate alt text
26
25
```
27
26
Navigate to the project directory:
28
27
``` bash
29
- cd AltTextGenerator
28
+ cd /path/to/ AltTextGenerator
30
29
```
31
30
2. Create a virtual environment with custom name ' AltTextGeneratorEnv' (recommended):
32
31
` ` ` bash
@@ -51,17 +50,49 @@ AltTextGenerator is a Python script designed to automatically generate alt text
51
50
1. Place the images in the default img folder or create your own folder.
52
51
2. Run the script:
53
52
` ` ` bash
54
- python main.py
53
+ python -m src.main
55
54
` ` `
56
55
3. When prompted, enter the path to the folder containing images or press Enter to use the default img folder:
57
56
` ` ` bash
58
- Enter the path to the folder with images (or press Enter for ' img' ):
57
+ Enter the path to the folder with images (or press Enter for ' ./data/ img' ):
59
58
` ` `
60
59
4. The script will:
61
60
- Generate alt text for each image.
62
61
- Rename the images based on the generated alt text.
63
62
5. View the renamed images in the specified folder.
64
63
64
+ # # Testing
65
+
66
+ To ensure the script is working correctly, follow these steps to run the tests:
67
+ 1. Install the pytest package:
68
+ ` ` ` bash
69
+ pip install pytest
70
+ ` ` `
71
+ 2. Run all tests:
72
+ ` ` ` bash
73
+ pytest tests/
74
+ ` ` `
75
+ 3. Test details:
76
+ - The tests include validation for:
77
+ - The BLIP2 model functionality.
78
+ - Utility functions for file and image processing.
79
+ - End-to-end integration of image processing and renaming.
80
+ 4. Check the output to conform that all tests have passed. Example:
81
+ ` ` ` bash
82
+ ============================= test session starts ==============================
83
+ platform darwin -- Python 3.12.8, pytest-7.4.4, pluggy-1.5.0
84
+ rootdir: /AltTextGenerator
85
+ plugins: cov-6.0.0
86
+ collected 24 items
87
+
88
+ tests/test_blip2.py ...... [ 25%]
89
+ tests/test_file_utils.py ...... [ 50%]
90
+ tests/test_image_utils.py ...... [ 75%]
91
+ tests/test_main.py ...... [100%]
92
+
93
+ ============================== 24 passed in 5.06s ===============================
94
+ ` ` `
95
+
65
96
# # Notes
66
97
67
98
- Images are resized to 512x512 pixels for compatibility with the BLIP2 model.
@@ -74,7 +105,7 @@ Enter the path to the folder with images (or press Enter for 'img'):
74
105
Loading BLIP2 model...
75
106
Using MPS (Apple Silicon).
76
107
------------------------------------------------------------------
77
- Image Path: img/a brick building with a sign on the side .jpg
108
+ Image Path: img/img-1 .jpg
78
109
Generated Alt Text: A brick building with a sign on the side
79
110
80
111
Renamed image to: img/A brick building with a sign on the side.jpg
0 commit comments