Python telegram bot for style transfer between two photos. It can be found here.
At the time of publication of this text the bot is running on VK Cloud service, and will probably runs for the next month with interruptions for technical issues, then access to the bot via the link is not guaranteed.
For transferring style I chose MSG-Net implemented by zhanghang1989. It is already pre-trained and small enough to work out in a few seconds per image. A little bit corrected for my purposes code is placed in model.py. Photo examples can be found in the examples folder. The pre-trained weights of the model are placed in 21styles.model.
I used pyTelegramBotApi framework for the bot. It was chosen because it is quite simple and flexible, and also allows to write asynchronous code, which is very useful for Telegram bots. The intuitive interface of the bot is implemented using buttons, there is also detailed instruction for the user how to work with bot. While working with bot, users photos are stored in the chats folder in subfolders with chat_id names. The bots code is in main.py.
To launch the bot, you should get a unique token here. Next, put it in the main.py in line number 9 instead of token = get_token()
write token = <YOUR TOKEN>
.
Easy way:
- Download the repository.
- Go to the root directory.
- Install the required packages from requirements.txt. This can be done by:
$ pip install -r requirements.txt
If you have troubles with installation, then try installing without the cache directory:
$ pip install -r --no-cache-dir requirements.txt
- Run the bot using the:
$ python3 main.py
By file setup.py it is possible to build a package wheel, for this you should use:
$ python3 setup.py sdist bdist_wheel
Next, the assembled package will appear in the dist folder.
it is also possible to build a docker container using the Dockerfile:
$ docker build -t python-docker-app .
To deploy the Telegram bot, I used VK Cloud service. Tested on a virtual machine with Ubuntu 22.04, 2 CPU cores and 4GB RAM. You can upload the application code there directly from github or from a local system using the scp utility, install and run according to the instructions above.
For questions related to the bot, you can contact me in my telegram.