This project classifies uploaded PDF documents into business-oriented categories using a small NLP and machine learning pipeline. It combines a Streamlit frontend for file upload and preview, a FastAPI backend for inference, and a trained scikit-learn model for prediction.
- Upload and preview PDF files in the Streamlit interface
- Extract document text with
PyPDF2 - Clean and normalize text with NLTK-based preprocessing
- Transform text with TF-IDF vectorization
- Predict document categories with logistic regression
- Return a confidence score and confidence level for each classification
document_classification_system/
|-- app/
| |-- main.py
| |-- train_model.py
| |-- services/
| | `-- classifier.py
| |-- trained_models/
| | |-- model.pkl
| | `-- vectorizer.pkl
| `-- utils/
| |-- pdf_extractor.py
| `-- preprocessing.py
|-- dataset/
| `-- documents.csv
|-- screenshots/
|-- temp_uploads/
|-- test_documents/
|-- requirements.txt
`-- streamlit_app.py
- A user uploads a PDF in the Streamlit app.
- The frontend sends the file to the FastAPI classification endpoint.
- The backend stores the uploaded file temporarily.
pdf_extractor.pyreads the PDF and extracts plain text.preprocessing.pynormalizes the text and removes stopwords.classifier.pyloads the saved TF-IDF vectorizer and logistic regression model.- The backend returns the predicted category, confidence score, and confidence level.
- The Streamlit UI displays the result and a progress bar.
Training is handled by app/train_model.py. The script:
- loads
dataset/documents.csv - drops missing rows
- preprocesses the document text
- vectorizes text with
TfidfVectorizer - trains a
LogisticRegressionmodel - saves the model artifacts to
app/trained_models/
Based on the dataset and sample files in this repository, the system is currently oriented around categories such as:
invoiceShippingOrderpurchase orderstyle documentsresumesales report
The exact classes available at runtime depend on the labels present in dataset/documents.csv.
python -m venv .venv
.\.venv\Scripts\Activate.ps1pip install -r requirements.txt
pip install streamlit nltk requestspython -m app.train_modeluvicorn app.main:app --reloadstreamlit run streamlit_app.pyThe frontend and backend should be started in separate terminals. Keep your runtime-specific connection details in local configuration or code as needed, rather than publishing them in project documentation.
The classification endpoint returns a response in this format:
{
"filename": "sample.pdf",
"predicted_category": "invoice",
"confidence_score": "96.41%",
"confidence_level": "High"
}- Uploaded files are temporarily stored in
temp_uploads/. - The current implementation is focused on PDF classification.
requirements.txtdoes not currently include every imported runtime package used by the app UI and preprocessing flow, so the extra install step above is intentional.