Skip to content

Commit 25e8e06

Browse files
committed
Updated the project
1 parent 6250724 commit 25e8e06

26 files changed

+615
-439
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
# .gitignore
2+
13
### Python template
24
# Byte-compiled / optimized / DLL files
35
__pycache__/

README.md

Lines changed: 36 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ AltTextGenerator is a Python script designed to automatically generate alt text
1616
- Pillow (>=11.1.0,<12.0.0) for image handling
1717
- Hugging Face Transformers (>=4.48.0,<5.0.0) library
1818
- torch (>=2.5.1,<3.0.0) library
19-
- pytest 7.4.4 or above for testing
2019

2120
## Installation
2221

@@ -26,7 +25,7 @@ AltTextGenerator is a Python script designed to automatically generate alt text
2625
```
2726
Navigate to the project directory:
2827
```bash
29-
cd AltTextGenerator
28+
cd /path/to/AltTextGenerator
3029
```
3130
2. Create a virtual environment with custom name 'AltTextGeneratorEnv' (recommended):
3231
```bash
@@ -51,17 +50,49 @@ AltTextGenerator is a Python script designed to automatically generate alt text
5150
1. Place the images in the default img folder or create your own folder.
5251
2. Run the script:
5352
```bash
54-
python main.py
53+
python -m src.main
5554
```
5655
3. When prompted, enter the path to the folder containing images or press Enter to use the default img folder:
5756
```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'):
5958
```
6059
4. The script will:
6160
- Generate alt text for each image.
6261
- Rename the images based on the generated alt text.
6362
5. View the renamed images in the specified folder.
6463

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+
6596
## Notes
6697

6798
- 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'):
74105
Loading BLIP2 model...
75106
Using MPS (Apple Silicon).
76107
------------------------------------------------------------------
77-
Image Path: img/a brick building with a sign on the side.jpg
108+
Image Path: img/img-1.jpg
78109
Generated Alt Text: A brick building with a sign on the side
79110

80111
Renamed image to: img/A brick building with a sign on the side.jpg
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

0 commit comments

Comments
 (0)