Documentation

This documentation explains how the original Streamlit app was translated into a portfolio-compatible Flask architecture and a fast browser sandbox.

Architecture Overview

  1. Data upload: users upload labelled or unlabelled CSV/Excel text data.
  2. Training: TF-IDF converts text into numerical features; Logistic Regression learns sentiment classes.
  3. Prediction: new rows are scored locally and returned with class probabilities.
  4. Analysis: local analytics calculate distribution, confidence, low-confidence records, and category breakdowns.
  5. Export: labelled outputs are downloaded as CSV for dashboards and reporting pipelines.

Technology Stack

FlaskPandasScikit-learnTF-IDFLogistic RegressionJavaScript SandboxCSV Export

Flask Conversion Notes

The Streamlit version was converted into a standard Flask pattern with reusable ML functions, file upload routes, API endpoints, and templates. This avoids the Streamlit-specific runtime experience and makes the project easier to deploy as a lightweight web service on Render, Railway, Fly.io, or a private server.

flask_app/
├── app.py                  # Flask routes and API endpoints
├── requirements.txt        # Flask + ML dependencies
├── models/                 # Model/vectorizer metadata copied from source project
├── sample_training_data.csv
├── sample_unlabelled_data.csv
├── templates/index.html
└── static/app.js

Run the Flask App Locally

cd pages/ai-lab/sentiment-automation/flask_app
python -m venv .venv
.venv\Scripts\activate   # Windows
pip install -r requirements.txt
python app.py

Then open http://127.0.0.1:5000. The portfolio sandbox remains available without starting Flask, while the Flask folder provides the backend-ready version of the converted application.

Security note: routine sentiment prediction uses the local model. No external AI API is required for bulk scoring. If a production chatbot or LLM explanation layer is later added, it should use explicit consent, redaction, and controlled prompts.