Gemini is an advanced Artificial Intelligence (AI) system designed to intelligently respond to diverse prompts, including pictures, text, speech, music, and code. This Python Telegram Bot script leverages the aiogram library to interact with Google's AI.
For more detailed information on the capabilities and availability of Google Gemini AI, please visit Google's official blog.
To utilize Gemini Pro, configure your environment with the necessary API key and service account credentials. Follow these steps to get started:
aiogram==2.25.1
, PIL
, io
, logging
, google-generativeai
📚GOOGLE_API_KEY
, GOOGLE_APPLICATION_CREDENTIALS
🗝️Install the required dependencies, ensuring Python 3.9 or higher:
pip install aiogram==2.25.1 Pillow google-generativeai
Note: The PIL
package is part of the Pillow
library, which is a more up-to-date fork of PIL.
Create a Google Cloud Platform (GCP) service account and download the JSON key file. Follow these steps:
Obtain a Google API key by following the link here.
Set the Google API key and the path to your service account credentials as environment variables:
export GOOGLE_API_KEY=<your-api-key>
export GOOGLE_APPLICATION_CREDENTIALS=/path/to/serviceaccount.json
Replace <your-api-key>
and /path/to/serviceaccount.json
with your actual Google API key and the path to your service account JSON file, respectively.
To set environment variables permanently on a VPS :
Open the Profile File
For a single user, edit ~/.bashrc
:
nano ~/.bashrc
Add the Environment Variables
At the bottom, add:
export GOOGLE_API_KEY="your-api-key-here"
export GOOGLE_APPLICATION_CREDENTIALS="/path/to/serviceaccount.json"
Replace "your-api-key-here"
and "/path/to/serviceaccount.json"
with your actual details.
Save and Exit
Press Ctrl + O
, then Enter
and .Press Ctrl + X
, to exit
Apply the Changes
Reload the profile:
source ~/.bashrc
git clone https://github.com/bisnuray/GeminiProBot
cd GeminiProBot
nano gemini.py [ replace with your actual bot token ]
python3 gemini.py
Execute the script to start the bot:
python gemini.py
The bot supports the following commands:
Feel free to reach out if you have any questions or feedback.