This project implements a content moderation system using a Flask API that can classify text as toxic or non-toxic. The system uses a pre-trained BERT model for local inference and integrates with a LLM API for more advanced moderation tasks. Additionally, the API provides monitoring capabilities using Prometheus and visualizes metrics in Grafana.
Before running the application, ensure you have the following installed:
Clone the repository:
git clone https://github.com/masih-ahmadi/ai-projects.git
cd content-moderation-api
Install Python dependencies:
pip install -r requirements.txt
Download and set up Prometheus:
Download Prometheus from here.
Extract the file and navigate to the directory.
Update the prometheus.yml configuration file to scrape metrics from your Flask API:
scrape_configs:
- job_name: 'flask_app'
static_configs:
- targets: ['localhost:5000'] # Adjust to match your Flask server address
Start Prometheus:
./prometheus --config.file=prometheus.yml
Download and set up Grafana:
Download Grafana from here.
Extract the file and navigate to the directory.
Start Grafana:
./bin/grafana-server
Access Grafana at http://localhost:3000 and add Prometheus as a data source.
Train the BERT model (optional):
If you want to train the BERT model on your dataset:
python train_model.py
Start the Flask server:
python app.py
Access the API:
The API will be running on http://localhost:5000. You can interact with it using cURL, Postman, or any other HTTP client.
Example request:
curl -X POST http://localhost:5000/check-text \
-H "Content-Type: application/json" \
-d '{"text": "This is a toxic message", "model": "llm"}'
Prometheus will scrape the /metrics endpoint exposed by the Flask app to collect metrics.
http://localhost:5000/metricsCreate a Dashboard:
http://localhost:3000.request_count and inference_time_seconds.POST /check-text
Checks the provided text for undesirable language.
Request:
{
"text": "Your text here",
"model": "bert" // or "llm"
}
Response:
{
"original_text": "Your text here",
"flagged": true,
"probability": 0.85,
"target": "unknown",
"deescalated_text": "Cleaned text"
}
GET /metrics
Exposes Prometheus metrics.
The Story Generator App is a web application built using Django that allows users to generate and manage personalized stories. The app includes functionalities such as user registration, authentication, profile management, and the ability to generate, view, and store stories with an audio playback feature.
Clone the Repository:
git clone https://github.com/masih-ahmadi/ai-projects.git
cd story-generator-app
Create a Virtual Environment:
python -m venv venv
source venv/bin/activate # On Windows use `venv\Scripts\activate`
Install Dependencies:
pip install -r requirements.txt
Apply Migrations:
python manage.py migrate
Create a Superuser:
python manage.py createsuperuser
Run the Development Server:
python manage.py runserver
Access the Application:
http://127.0.0.1:8000/./story_app/: Contains the main Django project settings and URLs./application/: Contains the core app logic, including models, views, and templates for story generation./templates/: Includes the HTML files for various pages like login, registration, profile, and home./static/: Contains static files like CSS, JS, and images used in the project.This Django application allows users to query university module information using a custom Large Language Model (LLM) API. The application extracts module data from a PDF, stores it in a vector store for efficient querying, and enhances responses with contextual information generated by the LLM.
git clone https://github.com/masih-ahmadi/ai-projects.git
cd yourrepository
pip install -r requirements.txt
If requirements.txt is not available, manually install the required packages:
pip install django pandas scikit-learn requests pdfplumber
Place the module catalog PDF file in the static/pdf/ or data/ directory (depending on your project structure):
mkdir -p passau_ai_assistant/static/pdf
mv /path/to/your/Module_Catalogue_M.Sc.AI-Engineering.pdf passau_ai_assistant/static/pdf/
Run the following Django management commands to extract module information from the PDF and vectorize the module descriptions:
python manage.py extract_modules
python manage.py vectorize_modules
Start the Django development server:
python manage.py runserver
Open your web browser and navigate to:
http://127.0.0.1:8000/modules/query/
You should see a search form where you can input queries related to university modules.
5 commits
CSS
49.7%
JavaScript
33.4%
Python
11.1%
HTML
5.8%
This project implements a content moderation system using a Flask API that can classify text as toxic or non-toxic. The system uses a pre-trained BERT model for local inference and integrates with a LLM API for more advanced moderation tasks. Additionally, the API provides monitoring capabilities using Prometheus and visualizes metrics in Grafana.
Before running the application, ensure you have the following installed:
Clone the repository:
git clone https://github.com/masih-ahmadi/ai-projects.git
cd content-moderation-api
Install Python dependencies:
pip install -r requirements.txt
Download and set up Prometheus:
Download Prometheus from here.
Extract the file and navigate to the directory.
Update the prometheus.yml configuration file to scrape metrics from your Flask API:
scrape_configs:
- job_name: 'flask_app'
static_configs:
- targets: ['localhost:5000'] # Adjust to match your Flask server address
Start Prometheus:
./prometheus --config.file=prometheus.yml
Download and set up Grafana:
Download Grafana from here.
Extract the file and navigate to the directory.
Start Grafana:
./bin/grafana-server
Access Grafana at http://localhost:3000 and add Prometheus as a data source.
Train the BERT model (optional):
If you want to train the BERT model on your dataset:
python train_model.py
Start the Flask server:
python app.py
Access the API:
The API will be running on http://localhost:5000. You can interact with it using cURL, Postman, or any other HTTP client.
Example request:
curl -X POST http://localhost:5000/check-text \
-H "Content-Type: application/json" \
-d '{"text": "This is a toxic message", "model": "llm"}'
Prometheus will scrape the /metrics endpoint exposed by the Flask app to collect metrics.
http://localhost:5000/metricsCreate a Dashboard:
http://localhost:3000.request_count and inference_time_seconds.POST /check-text
Checks the provided text for undesirable language.
Request:
{
"text": "Your text here",
"model": "bert" // or "llm"
}
Response:
{
"original_text": "Your text here",
"flagged": true,
"probability": 0.85,
"target": "unknown",
"deescalated_text": "Cleaned text"
}
GET /metrics
Exposes Prometheus metrics.
The Story Generator App is a web application built using Django that allows users to generate and manage personalized stories. The app includes functionalities such as user registration, authentication, profile management, and the ability to generate, view, and store stories with an audio playback feature.
Clone the Repository:
git clone https://github.com/masih-ahmadi/ai-projects.git
cd story-generator-app
Create a Virtual Environment:
python -m venv venv
source venv/bin/activate # On Windows use `venv\Scripts\activate`
Install Dependencies:
pip install -r requirements.txt
Apply Migrations:
python manage.py migrate
Create a Superuser:
python manage.py createsuperuser
Run the Development Server:
python manage.py runserver
Access the Application:
http://127.0.0.1:8000/./story_app/: Contains the main Django project settings and URLs./application/: Contains the core app logic, including models, views, and templates for story generation./templates/: Includes the HTML files for various pages like login, registration, profile, and home./static/: Contains static files like CSS, JS, and images used in the project.This Django application allows users to query university module information using a custom Large Language Model (LLM) API. The application extracts module data from a PDF, stores it in a vector store for efficient querying, and enhances responses with contextual information generated by the LLM.
git clone https://github.com/masih-ahmadi/ai-projects.git
cd yourrepository
pip install -r requirements.txt
If requirements.txt is not available, manually install the required packages:
pip install django pandas scikit-learn requests pdfplumber
Place the module catalog PDF file in the static/pdf/ or data/ directory (depending on your project structure):
mkdir -p passau_ai_assistant/static/pdf
mv /path/to/your/Module_Catalogue_M.Sc.AI-Engineering.pdf passau_ai_assistant/static/pdf/
Run the following Django management commands to extract module information from the PDF and vectorize the module descriptions:
python manage.py extract_modules
python manage.py vectorize_modules
Start the Django development server:
python manage.py runserver
Open your web browser and navigate to:
http://127.0.0.1:8000/modules/query/
You should see a search form where you can input queries related to university modules.
5 commits
CSS
49.7%
JavaScript
33.4%
Python
11.1%
HTML
5.8%