Aktualizovat telegram_bot/README.md
This commit is contained in:
parent
173e819191
commit
902b7c8d7c
@ -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
|
||||
- When hate speech is detected, it records information about the **user and the message into a database**
|
||||
- Displays violators through a **real-time web interface**
|
||||
- Automaticky **zachytiť a analyzovať správy** používateľov v skupinových chatoch.
|
||||
- V prípade detekcie nenávistného prejavu zaznamená informáciu o **používateľovi a správe do databázy**.
|
||||
- Vizualizuje porušovateľov cez **webové rozhranie** v reálnom čase.
|
||||
|
||||
### System Components:
|
||||
1. **Telegram Bot**: Intercepts messages and uses a fine-tuned LLM model to classify whether the message contains hate speech.
|
||||
2. **MySQL Database**: Stores user information, messages, and incident timestamps.
|
||||
3. **Web Application (Flask)**: Displays a real-time table of violations, updated every 5 seconds.
|
||||
### Komponenty systému:
|
||||
1. **Telegram Bot**: Interceptuje správy v skupine a pomocou trénovaného LLM modelu klasifikuje, či ide o nenávistnú reč.
|
||||
2. **MySQL databáza**: Ukladá údaje o používateľoch, správach a čase incidentu.
|
||||
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 |
|
||||
|-------------------------------------|-------------|
|
||||
| `tetianamohorian/hate-speech-bot` | Contains the Telegram bot, classification model (e.g. fine-tuned BERT), and Flask frontend |
|
||||
| `mysql:8` | Relational database for storing violator records |
|
||||
| Kontajner | Popis |
|
||||
|--------------------------------------|-------|
|
||||
| tetianamohorian/hate-speech-bot | Obsahuje Telegram bota, klasifikačný model (napr. fine-tuned BERT), a Flask frontend. |
|
||||
| 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 |
|
||||
|---------------------------|-------------|
|
||||
| `Namespace: botspace` | Isolated space for all app-related objects |
|
||||
| `Deployment: bot-deployment` | Deploys the container with the bot |
|
||||
| `Deployment: flask-web` | Deploys the Flask web server |
|
||||
| `StatefulSet: mysql` | Ensures persistent and consistent MySQL operation |
|
||||
| `PersistentVolume` | Stores database data outside the pod |
|
||||
| `PersistentVolumeClaim` | Requests disk space for the database |
|
||||
| `Service: mysql` | Internal service for accessing the database |
|
||||
| `Service: flask-service` | Port-forward service for accessing the web |
|
||||
| `ConfigMap: init-sql` | Contains initial SQL schema scripts |
|
||||
| `Secret: bot-secret` | Secure storage of sensitive data like the Telegram token |
|
||||
| Objekt | Popis |
|
||||
|----------------------------|-------|
|
||||
| Namespace: botspace | Izolovaný priestor pre všetky objekty súvisiace s aplikáciou. |
|
||||
| Deployment: bot-deployment | Nasadzuje kontajner s botom. |
|
||||
| Deployment: flask-web | Nasadzuje Flask webserver. |
|
||||
| StatefulSet: mysql | Zabezpečuje perzistentný a konzistentný chod MySQL databázy. |
|
||||
| PersistentVolume | Uchováva fyzické dáta databázy mimo podu. |
|
||||
| PersistentVolumeClaim | Žiadosť o diskový priestor pre databázu. |
|
||||
| Service: mysql | Vnútorná služba pre prístup k databáze. |
|
||||
| Service: flask-service | Port-forward pre sprístupnenie webu. |
|
||||
| ConfigMap: init-sql | Obsahuje SQL skripty na prvotnú inicializáciu schémy. |
|
||||
| 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
|
||||
- `PersistentVolume` attached to MySQL ensures data preservation even after pod restarts
|
||||
- Všetky pody komunikujú cez internú sieť v botspace, čím sa znižuje riziko únikov údajov.
|
||||
- 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
|
||||
- **Telegram Bot**: Runs in a separate thread, classifies messages using a PyTorch model or HuggingFace Transformers, and logs results into the database
|
||||
- **MySQL**: Initialized with an `initContainer` that runs a script from the `ConfigMap`
|
||||
- **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**: Spustený v samostatnom threade, číta správy, klasifikuje ich pomocou PyTorch modelu (alebo HuggingFace Transformers), a zapisuje výsledok do databázy.
|
||||
- **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
|
||||
```
|
||||
|
||||
- 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
|
||||
```
|
||||
|
||||
- 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"
|
||||
```
|
||||
|
||||
- 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
|
||||
```
|
||||
|
||||
- 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
|
||||
```
|
||||
|
||||
- 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
|
||||
- **Docker, Docker Hub** – containerization
|
||||
- **Kubernetes** – orchestration, scaling, and network isolation
|
||||
- **MySQL** – relational data storage
|
||||
- **JavaScript (AJAX)** – real-time frontend updates
|
||||
- **Python, Flask, PyTorch / Transformers** – analýza a klasifikácia textov
|
||||
- **Docker, Docker Hub** – kontajnerizácia
|
||||
- **Kubernetes** – orchestrácia, škálovanie a sieťová izolácia
|
||||
- **MySQL** – relačné databázové úložisko
|
||||
- **JavaScript (AJAX)** – aktualizácia frontendu v reálnom čase тоже самое сделай
|
Loading…
Reference in New Issue
Block a user