Skip to content

FootballOnlooker/Local-AI-Assistant

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

19 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

Python PyTorch Transformers License

πŸ€– Local AI Assistant

A local AI assistant developed in Python that combines a local Large Language Model (LLM) with a fine-tuned transformer model for text classification.

The project consists of two connected parts:

  • Part 1: Local AI Chat Assistant using Ollama and Tkinter.
  • Part 2: German customer message classification using DistilBERT.

The classifier is integrated into the GUI and automatically predicts the category of every user message before the AI generates its response.


πŸ“‚ Project Structure

Local-AI-Assistant/
β”‚
β”œβ”€β”€ teil1/
β”‚   β”œβ”€β”€ chat.py
β”‚   β”œβ”€β”€ gui.py
β”‚   └── main.py
β”‚
β”œβ”€β”€ teil2/
β”‚   β”œβ”€β”€ data/
β”‚   β”‚   └── dataset_teil2.csv
β”‚   β”œβ”€β”€ model/
β”‚   β”‚   └── final_model/
β”‚   β”œβ”€β”€ check_dataset.py
β”‚   β”œβ”€β”€ classifier.py
β”‚   β”œβ”€β”€ predict.py
β”‚   └── train.py
β”‚
β”œβ”€β”€ images/
β”‚   β”œβ”€β”€ teil1_chat.png
β”‚   └── training_model_teil2.png
β”‚
β”œβ”€β”€ README.md
β”œβ”€β”€ requirements.txt
└── .gitignore

πŸš€ Part 1 – Local AI Chat Assistant

Goal

Develop a desktop AI assistant that communicates with a locally running Large Language Model using Ollama.

Technologies

  • Python
  • Tkinter
  • Ollama
  • Llama 3.2:3b

Features

  • Local AI chatbot
  • Graphical User Interface (GUI)
  • Conversation history
  • Communication with Ollama
  • Automatic text classification
  • Category prediction
  • Confidence score display

🧠 Part 2 – Text Classification with DistilBERT

Goal

Fine-tune a transformer model to classify German customer messages into predefined categories.

Categories

  • Anfrage
  • Reklamation
  • Rechnung
  • Sonstiges

Dataset

The dataset was manually created.

It contains:

  • 200 text examples
  • 4 categories
  • 50 examples per category

The dataset is stored as a CSV file.


Technologies

  • Python
  • Pandas
  • PyTorch
  • Hugging Face Transformers
  • Hugging Face Datasets
  • Scikit-Learn

βš™οΈ Training Pipeline

The training process consists of the following steps:

  1. Load the dataset.
  2. Encode category labels into numerical IDs.
  3. Split the dataset into training and test sets.
  4. Convert the data into Hugging Face Dataset format.
  5. Tokenize the text.
  6. Fine-tune DistilBERT.
  7. Evaluate the model.
  8. Save the trained model.
  9. Save the tokenizer.

πŸ“Š Training Results

Parameter Value
Model distilbert-base-german-cased
Dataset size 200
Classes 4
Training samples 160
Test samples 40
Epochs 3
Batch size 8
Learning rate 2e-5
Training time ~0.82 min
Evaluation Loss 0.8794
Test Accuracy 87.50 %

πŸ” Prediction Example

Input

Ich habe meine Rechnung nicht erhalten.

Output

Kategorie: Rechnung

Confidence: 87.50 %

πŸ–₯ GUI Example

Every user message is automatically classified before the AI generates a response.

Example

Sie:
Ich habe meine Rechnung nicht erhalten.

Kategorie:
Rechnung (87.50 %)

KI:
NatΓΌrlich helfe ich Ihnen.
Bitte senden Sie mir Ihre Bestellnummer oder Rechnungsnummer,
damit ich Ihnen weiterhelfen kann.

πŸ’» Requirements

  • Python 3.10+
  • Ollama installed
  • Llama 3.2:3b downloaded locally

πŸ›  Installation

Clone the repository

git clone https://github.com/FootballOnlooker/Local-AI-Assistant.git

Create a virtual environment

python -m venv .venv

Activate it

Windows

.venv\Scripts\activate

Install dependencies

pip install -r requirements.txt

▢️ Running the Project

1. Download the Ollama model

ollama pull llama3.2:3b

2. Train the classifier

python teil2/train.py

The training process creates

teil2/model/final_model/

3. Run the GUI

python teil1/main.py

4. Optional standalone prediction

python teil2/predict.py

πŸ“š Main Libraries

  • transformers
  • datasets
  • torch
  • pandas
  • numpy
  • scikit-learn
  • ollama
  • tkinter

πŸ“Έ Screenshots

Local AI Chat Assistant

Local AI Chat Assistant


DistilBERT Training

DistilBERT Training


πŸ“Œ Notes

This project was created for educational purposes.

It demonstrates:

  • Local LLM integration using Ollama
  • Transformer fine-tuning with Hugging Face
  • Text classification using DistilBERT
  • Desktop GUI development with Tkinter
  • Integration of a classifier into a local AI assistant

The classifier is trained on a manually created dataset containing 200 German customer messages.

Although the achieved accuracy is 87.50%, the model may still produce incorrect predictions for previously unseen or ambiguous messages.

The displayed confidence score is the highest Softmax probability produced by the classifier. A high confidence value indicates that the model strongly prefers one category over the others, but it does not guarantee that the prediction is correct.


πŸ“„ Usage

This project was created for educational and demonstration purposes.

About

Local AI Chat Assistant using Ollama and Python

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages