PyQt GUI example of image to text using image-to-text model
The model i'm using is nlpconnect/vit-gpt2-image-captioning from huggingface.
This is for saving image files' name based on its image.
- PyQt5 >= 5.14
- transformers
- git clone ~
- cd pyqt-image-to-text
- python setup.py install
- pip install -r requirements.txt
- cd pyqt_image_to_text
- python main.py
See "How to Use" below 🙂
If you want to use this as CLI version only, see scripts.py and use saveImage(src, dst)
function.
src can be list of files or one directory. dst is directory you want to save images.
Press "Set Directory" to add image files in list (only one directory per image to text process).
Support png, jpg, jpeg, bmp.
After you've done it, press "Save" button to save files to your desired directory
You can see the result of it.
For example:
![](https://private-user-images.githubusercontent.com/55078043/241531613-83c3e721-ea80-430e-ae8d-54021b5886a4.jpg?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MTkxMDE0NzIsIm5iZiI6MTcxOTEwMTE3MiwicGF0aCI6Ii81NTA3ODA0My8yNDE1MzE2MTMtODNjM2U3MjEtZWE4MC00MzBlLWFlOGQtNTQwMjFiNTg4NmE0LmpwZz9YLUFtei1BbGdvcml0aG09QVdTNC1ITUFDLVNIQTI1NiZYLUFtei1DcmVkZW50aWFsPUFLSUFWQ09EWUxTQTUzUFFLNFpBJTJGMjAyNDA2MjMlMkZ1cy1lYXN0LTElMkZzMyUyRmF3czRfcmVxdWVzdCZYLUFtei1EYXRlPTIwMjQwNjIzVDAwMDYxMlomWC1BbXotRXhwaXJlcz0zMDAmWC1BbXotU2lnbmF0dXJlPTRkZDU3ZGRhOWRkMDM3M2JhYTY2N2ZiMDBiZDJkNGM1NWJlNDQwMDM5MDRjNWM2YWE4OWYyMWZiMWIxNmFjNTQmWC1BbXotU2lnbmVkSGVhZGVycz1ob3N0JmFjdG9yX2lkPTAma2V5X2lkPTAmcmVwb19pZD0wIn0.6Lf7TxH6ULixjU_0mwA3LkJfyN9j4YJn0Tw7Ye6m3KY)
This image is converted into text as:
a tv sitting on top of a stand in a room
Based on the text, file will be saved to dst folder named "a_tv_sitting_on_top_of_a_stand_in_a_room".
Example image files which i was using to test are inside each src and dst, you can compare with each other :)
If you encounter any error, check this out:
- transformers is not recent version
- required modules to transformers are not recent version or not be installed (such as sentencepiece, safetensors)
- if it is related to scikit-learn, try reinstall sckit-learn. make sure previous versions of it are all deleted
I'm working on a lot of AI-related project.
- pyqt-openai - pyqt implementation of chatgpt
- pyqt-dreamstudio - using stable diffusion in pyqt desktop app