Aktualizovat telegram_bot/README.md

This commit is contained in:
Tetiana Mohorian 2025-06-04 10:44:55 +00:00
parent 173e819191
commit 902b7c8d7c

View File

@ -1,122 +1,121 @@
# Hate Speech Bot Documentation # Hate Speech Bot Dokumentácia
## 🧠 Application Overview ## 🧠 Opis aplikácie
The Hate Speech Bot is a complete system for the automated detection of hate speech within **Telegram**. It functions as a monitoring and analysis tool that enables: Hate Speech Bot je kompletný systém na automatickú detekciu nenávistnej reči v prostredí **Telegramu**. Aplikácia slúži ako monitorovací a analytický nástroj, ktorý umožňuje:
- Automatic **interception and analysis of user messages** in group chats - Automaticky **zachytiť a analyzovať správy** používateľov v skupinových chatoch.
- When hate speech is detected, it records information about the **user and the message into a database** - V prípade detekcie nenávistného prejavu zaznamená informáciu o **používateľovi a správe do databázy**.
- Displays violators through a **real-time web interface** - Vizualizuje porušovateľov cez **webové rozhranie** v reálnom čase.
### System Components: ### Komponenty systému:
1. **Telegram Bot**: Intercepts messages and uses a fine-tuned LLM model to classify whether the message contains hate speech. 1. **Telegram Bot**: Interceptuje správy v skupine a pomocou trénovaného LLM modelu klasifikuje, či ide o nenávistnú reč.
2. **MySQL Database**: Stores user information, messages, and incident timestamps. 2. **MySQL databáza**: Ukladá údaje o používateľoch, správach a čase incidentu.
3. **Web Application (Flask)**: Displays a real-time table of violations, updated every 5 seconds. 3. **Webová aplikácia (Flask)**: Zobrazuje tabuľku s porušeniami, automaticky aktualizovanú každých 5 sekúnd.
--- ---
## 🧱 List of Used Docker Containers ## 🧱 Zoznam použitých Docker kontajnerov
| Container | Description | | Kontajner | Popis |
|-------------------------------------|-------------| |--------------------------------------|-------|
| `tetianamohorian/hate-speech-bot` | Contains the Telegram bot, classification model (e.g. fine-tuned BERT), and Flask frontend | | tetianamohorian/hate-speech-bot | Obsahuje Telegram bota, klasifikačný model (napr. fine-tuned BERT), a Flask frontend. |
| `mysql:8` | Relational database for storing violator records | | mysql:8 | Relačný databázový systém pre ukladanie záznamov o porušovateľoch. |
--- ---
## ☸️ List of Kubernetes Objects ## ☸️ Zoznam Kubernetes objektov
| Object | Description | | Objekt | Popis |
|---------------------------|-------------| |----------------------------|-------|
| `Namespace: botspace` | Isolated space for all app-related objects | | Namespace: botspace | Izolovaný priestor pre všetky objekty súvisiace s aplikáciou. |
| `Deployment: bot-deployment` | Deploys the container with the bot | | Deployment: bot-deployment | Nasadzuje kontajner s botom. |
| `Deployment: flask-web` | Deploys the Flask web server | | Deployment: flask-web | Nasadzuje Flask webserver. |
| `StatefulSet: mysql` | Ensures persistent and consistent MySQL operation | | StatefulSet: mysql | Zabezpečuje perzistentný a konzistentný chod MySQL databázy. |
| `PersistentVolume` | Stores database data outside the pod | | PersistentVolume | Uchováva fyzické dáta databázy mimo podu. |
| `PersistentVolumeClaim` | Requests disk space for the database | | PersistentVolumeClaim | Žiadosť o diskový priestor pre databázu. |
| `Service: mysql` | Internal service for accessing the database | | Service: mysql | Vnútorná služba pre prístup k databáze. |
| `Service: flask-service` | Port-forward service for accessing the web | | Service: flask-service | Port-forward pre sprístupnenie webu. |
| `ConfigMap: init-sql` | Contains initial SQL schema scripts | | ConfigMap: init-sql | Obsahuje SQL skripty na prvotnú inicializáciu schémy. |
| `Secret: bot-secret` | Secure storage of sensitive data like the Telegram token | | Secret: bot-secret | Bezpečné uloženie citlivých údajov ako je Telegram token. |
--- ---
## 🌐 Virtual Networks and Storage ## 🌐 Virtuálne siete a úložiská
- All pods communicate over an internal network in `botspace`, minimizing data leakage risks - Všetky pody komunikujú cez internú sieť v botspace, čím sa znižuje riziko únikov údajov.
- `PersistentVolume` attached to MySQL ensures data preservation even after pod restarts - PersistentVolume pripojený k MySQL zaručuje zachovanie dát aj po reštarte podu.
--- ---
## ⚙️ Container Configuration ## ⚙️ Konfigurácia kontajnerov
- **Flask Web**: Runs on port `5000`, accessible via `flask-service`. Automatically updates via JavaScript (AJAX `fetch`) every 5 seconds - **Flask Web**: Beží na porte 5000, ktorý je dostupný cez flask-service. Obnovuje sa každých 5 sekúnd pomocou JavaScriptu (AJAX fetch).
- **Telegram Bot**: Runs in a separate thread, classifies messages using a PyTorch model or HuggingFace Transformers, and logs results into the database - **Telegram Bot**: Spustený v samostatnom threade, číta správy, klasifikuje ich pomocou PyTorch modelu (alebo HuggingFace Transformers), a zapisuje výsledok do databázy.
- **MySQL**: Initialized with an `initContainer` that runs a script from the `ConfigMap` - **MySQL**: Inicializovaná pomocou initContainer, ktorý spustí skript uložený v ConfigMap.
--- ---
## 🚀 Usage Guide ## 🚀 Návod na použitie
### 1. Prepare the Application: ### 1. Príprava aplikácie:
```bash bash
./prepare-app.sh ./prepare-app.sh
```
- Builds the Docker image
- Pushes it to Docker Hub - Zostaví Docker image s aplikáciou.
- Pushne ho do Docker Hub repozitára.
--- ---
### 2. Start the Application: ### 2. Spustenie aplikácie:
```bash bash
./start-app.sh ./start-app.sh
```
- Creates Kubernetes objects
- Starts port-forwarding for Flask web on `localhost:8888` - Vytvorí Kubernetes objekty.
- Spustí port-forwarding pre Flask web na localhost:8888.
--- ---
### 3. Stop Port-Forwarding: ### 3. Pozastavenie (port-forward):
```bash bash
pkill -f "kubectl port-forward" pkill -f "kubectl port-forward"
```
- Terminates temporary access via port-forward
- Zastaví dočasný prístup cez port-forward.
--- ---
### 4. Remove the Application: ### 4. Odstránenie aplikácie:
```bash bash
./stop-app.sh ./stop-app.sh
```
- Deletes the entire `botspace`, including database and services
- Zmaže celý botspace, vrátane databázy a všetkých služieb.
--- ---
## 🌍 Accessing the Web Interface ## 🌍 Prístup k webovej aplikácii
After launching the app, open a browser: Po úspešnom spustení aplikácie otvorte webový prehliadač:
```
http://localhost:8888 http://localhost:8888
```
- A table of violators will be displayed
- Data updates automatically every 5 seconds - Zobrazí sa tabuľka s informáciami o porušovateľoch.
- Dáta sa aktualizujú automaticky každých 5 sekúnd bez potreby obnoviť stránku.
--- ---
## 📦 Technologies Used ## 📦 Použité technológie
- **Python, Flask, PyTorch / Transformers** text analysis and classification - **Python, Flask, PyTorch / Transformers** analýza a klasifikácia textov
- **Docker, Docker Hub** containerization - **Docker, Docker Hub** kontajnerizácia
- **Kubernetes** orchestration, scaling, and network isolation - **Kubernetes** orchestrácia, škálovanie a sieťová izolácia
- **MySQL** relational data storage - **MySQL** relačné databázové úložisko
- **JavaScript (AJAX)** real-time frontend updates - **JavaScript (AJAX)** aktualizácia frontendu v reálnom čase тоже самое сделай