A sophisticated AI-powered Telegram bot that analyzes memes for offensive content and generates alternative versions when needed. The system uses advanced machine learning models for OCR, text classification, and image generation.
This project consists of two main components:
src/bot/src/server/git clone https://github.com/Roy-Ayalon/telegram_bot.git
cd telegram_bot
# Create virtual environment
python -m venv venv
# Activate virtual environment
# On Linux/Mac:
source venv/bin/activate
# On Windows:
venv\Scripts\activate
# Install dependencies
pip install -r requirements.txt
# Copy the template
cp config/.env.template .env
# Edit .env with your actual values
nano .env
Required environment variables:
TELEGRAM_BOT_TOKEN: Your bot token from @BotFatherFLASK_SERVER_URL: URL of your AI processing serverHUGGINGFACE_TOKEN: Token for Hugging Face model access# Navigate to server directory
cd src/server
# Start the Flask server
python app.py
The server will start on http://0.0.0.0:5002 by default.
# Navigate to bot directory
cd src/bot
# Start the Telegram bot
python main.py
/start to the botsrc/bot/config.py)src/server/app.py)ucaslcl/GOT-OCR2_0ibm-granite/granite-guardian-hap-125mstabilityai/stable-diffusion-3-medium-diffuserstelegram_bot/
โโโ src/
โ โโโ bot/ # Telegram bot components
โ โ โโโ __init__.py
โ โ โโโ main.py # Bot entry point
โ โ โโโ config.py # Configuration settings
โ โ โโโ handlers.py # Message and callback handlers
โ โโโ server/ # AI processing server
โ โโโ __init__.py
โ โโโ app.py # Flask server with AI models
โโโ notebooks/ # Development notebooks
โ โโโ classification.ipynb # Classification model testing
โ โโโ meme_generation.ipynb # Generation model testing
โ โโโ main.ipynb # Main application notebook
โ โโโ meme_manipulation.ipynb
โโโ assets/ # Demo content and examples
โ โโโ demo_video.mov # Demonstration video
โ โโโ Arab_harmful.png # Example: Harmful content detection
โ โโโ harmful_black.png # Example: Offensive meme sample
โ โโโ hate_america.png # Example: Hate speech detection
โ โโโ jews.png # Example: Anti-Semitic content detection
โ โโโ not offensive example.png # Example: Safe meme sample
โ โโโ racist_muslim.png # Example: Racist content detection
โ โโโ skin_color.png # Example: Color-based discrimination detection
โโโ config/
โ โโโ .env.template # Environment variables template
โโโ docs/ # Additional documentation
โโโ requirements.txt # Python dependencies
โโโ README.md # This file
๐ฅ Bot in Action
https://github.com/user-attachments/assets/1df2b1dd-0875-4bd0-8f69-bcf716c38e6c
See how the Telegram Meme Classifier Bot processes different types of content in real-time.
The bot has been tested on various types of content to ensure accurate detection:
Non-offensive meme - Shows how the bot correctly identifies harmless content:

Note: These examples are used solely for testing and improving the bot's detection capabilities. The bot helps identify and transform such content into more positive alternatives.
Anti-Arab content detection:

Racial targeting detection:

Anti-American sentiment detection:

Anti-Semitic content detection:

Anti-Muslim racism detection:

Skin color discrimination detection:

### Contributing
1. Fork the repository
2. Create a feature branch
3. Make your changes
4. Add tests
5. Submit a pull request
### Scaling
- Use load balancers for multiple server instances
- Implement Redis for caching processed results
- Set up monitoring with Prometheus/Grafana
## ๐ก๏ธ Security
- Bot token should be kept secret
- Server should run behind firewall
- File uploads are validated and sanitized
- Temporary files are cleaned up automatically
- Rate limiting implemented for API endpoints
## ๐ Troubleshooting
### Common Issues
#### "CUDA out of memory"
- Reduce batch size in model loading
- Use smaller model variants
- Clear GPU cache between requests
#### "Bot not responding"
- Check bot token validity
- Verify server connectivity
- Check firewall settings
#### "Models not loading"
- Verify Hugging Face token
- Check internet connection
- Ensure sufficient disk space
### Logs
```bash
# Bot logs
tail -f logs/bot.log
# Server logs
tail -f logs/server.log
For support and questions:
โญ Like this project? Give it a star on GitHub! โญ
13 commits
Jupyter Notebook
98.1%
Python
1.9%
A sophisticated AI-powered Telegram bot that analyzes memes for offensive content and generates alternative versions when needed. The system uses advanced machine learning models for OCR, text classification, and image generation.
This project consists of two main components:
src/bot/src/server/git clone https://github.com/Roy-Ayalon/telegram_bot.git
cd telegram_bot
# Create virtual environment
python -m venv venv
# Activate virtual environment
# On Linux/Mac:
source venv/bin/activate
# On Windows:
venv\Scripts\activate
# Install dependencies
pip install -r requirements.txt
# Copy the template
cp config/.env.template .env
# Edit .env with your actual values
nano .env
Required environment variables:
TELEGRAM_BOT_TOKEN: Your bot token from @BotFatherFLASK_SERVER_URL: URL of your AI processing serverHUGGINGFACE_TOKEN: Token for Hugging Face model access# Navigate to server directory
cd src/server
# Start the Flask server
python app.py
The server will start on http://0.0.0.0:5002 by default.
# Navigate to bot directory
cd src/bot
# Start the Telegram bot
python main.py
/start to the botsrc/bot/config.py)src/server/app.py)ucaslcl/GOT-OCR2_0ibm-granite/granite-guardian-hap-125mstabilityai/stable-diffusion-3-medium-diffuserstelegram_bot/
โโโ src/
โ โโโ bot/ # Telegram bot components
โ โ โโโ __init__.py
โ โ โโโ main.py # Bot entry point
โ โ โโโ config.py # Configuration settings
โ โ โโโ handlers.py # Message and callback handlers
โ โโโ server/ # AI processing server
โ โโโ __init__.py
โ โโโ app.py # Flask server with AI models
โโโ notebooks/ # Development notebooks
โ โโโ classification.ipynb # Classification model testing
โ โโโ meme_generation.ipynb # Generation model testing
โ โโโ main.ipynb # Main application notebook
โ โโโ meme_manipulation.ipynb
โโโ assets/ # Demo content and examples
โ โโโ demo_video.mov # Demonstration video
โ โโโ Arab_harmful.png # Example: Harmful content detection
โ โโโ harmful_black.png # Example: Offensive meme sample
โ โโโ hate_america.png # Example: Hate speech detection
โ โโโ jews.png # Example: Anti-Semitic content detection
โ โโโ not offensive example.png # Example: Safe meme sample
โ โโโ racist_muslim.png # Example: Racist content detection
โ โโโ skin_color.png # Example: Color-based discrimination detection
โโโ config/
โ โโโ .env.template # Environment variables template
โโโ docs/ # Additional documentation
โโโ requirements.txt # Python dependencies
โโโ README.md # This file
๐ฅ Bot in Action
https://github.com/user-attachments/assets/1df2b1dd-0875-4bd0-8f69-bcf716c38e6c
See how the Telegram Meme Classifier Bot processes different types of content in real-time.
The bot has been tested on various types of content to ensure accurate detection:
Non-offensive meme - Shows how the bot correctly identifies harmless content:

Note: These examples are used solely for testing and improving the bot's detection capabilities. The bot helps identify and transform such content into more positive alternatives.
Anti-Arab content detection:

Racial targeting detection:

Anti-American sentiment detection:

Anti-Semitic content detection:

Anti-Muslim racism detection:

Skin color discrimination detection:

### Contributing
1. Fork the repository
2. Create a feature branch
3. Make your changes
4. Add tests
5. Submit a pull request
### Scaling
- Use load balancers for multiple server instances
- Implement Redis for caching processed results
- Set up monitoring with Prometheus/Grafana
## ๐ก๏ธ Security
- Bot token should be kept secret
- Server should run behind firewall
- File uploads are validated and sanitized
- Temporary files are cleaned up automatically
- Rate limiting implemented for API endpoints
## ๐ Troubleshooting
### Common Issues
#### "CUDA out of memory"
- Reduce batch size in model loading
- Use smaller model variants
- Clear GPU cache between requests
#### "Bot not responding"
- Check bot token validity
- Verify server connectivity
- Check firewall settings
#### "Models not loading"
- Verify Hugging Face token
- Check internet connection
- Ensure sufficient disk space
### Logs
```bash
# Bot logs
tail -f logs/bot.log
# Server logs
tail -f logs/server.log
For support and questions:
โญ Like this project? Give it a star on GitHub! โญ
13 commits
Jupyter Notebook
98.1%
Python
1.9%