Skip to content

codingburgas/2425-11-b-pp-student-practices-assignment-IVBadalov21

Repository files navigation

Language Detector - Project #12

A Flask web application that uses a custom Perceptron algorithm to detect languages in text samples. Supports 5 languages: English, Spanish, French, Bulgarian, and German.

Quick Start

Option 1: Simple SQLite Setup (Recommended for testing)

  1. Extract the project to a folder on your computer

  2. Install Python dependencies:

pip install flask flask-sqlalchemy flask-login flask-wtf flask-mail flask-migrate flask-bootstrap wtforms werkzeug itsdangerous email-validator numpy requests

If you plan to use PostgreSQL, also install:

pip install psycopg2-binary
  1. Set environment variable (Windows):
set SESSION_SECRET=language-detector-secret-key
set DATABASE_URL=sqlite:///instance/app.db

Or (Mac/Linux):

export SESSION_SECRET=language-detector-secret-key
export DATABASE_URL=sqlite:///instance/app.db
  1. Run the application:
python run_local.py
  1. Open your browser and go to: http://localhost:5000

Option 2: PostgreSQL Setup (Production)

  1. Install PostgreSQL and create a database named language_detector

  2. Set environment variables:

export DATABASE_URL=postgresql://username:password@localhost/language_detector
export SESSION_SECRET=your-secret-key-here
  1. Run the application:
python run_local.py

Features

  • Language Detection: Detect text in English, Spanish, French, Bulgarian, German
  • User Authentication: Register and login system
  • Survey Collection: Help train the model by submitting text samples
  • Admin Dashboard: Manage users and view model performance
  • API Endpoints: Programmatic access to language detection

Usage

  1. Register a new account or login
  2. Use the "Predict Language" page to test text samples
  3. Submit training data via the "Survey" page
  4. View your prediction history in "Results"

Files Overview

  • wsgi.py - WSGI entry point for deployment
  • run_local.py - Application runner for local development
  • app/core/perceptron.py - Custom Perceptron algorithm
  • app/core/language_features.py - Feature extraction for text analysis
  • app/models.py - Database models
  • app/auth/ - Authentication routes
  • app/main/ - Main application routes
  • app/admin/ - Admin panel routes
  • app/templates/ - HTML templates
  • app/static/ - CSS and JavaScript files

Troubleshooting

If you get database errors, make sure:

  1. PostgreSQL is running (if using PostgreSQL)
  2. Database exists and credentials are correct
  3. Environment variables are set properly

For SQLite (easier option), the database file will be created automatically in the instance/ folder.

Database Schema

Here's a visual representation of the application's database schema, generated using Mermaid.io:

erDiagram
    users {
        int id PK
        string username
        string email
        string password_hash
        string first_name
        string last_name
        boolean is_admin
        boolean is_confirmed
        datetime confirmed_on
        datetime registered_on
        datetime last_seen
    }

    surveys {
        int id PK
        int user_id FK
        text text_sample
        string language
        float confidence
        datetime created_at
        boolean is_approved
    }

    predictions {
        int id PK
        int user_id FK
        text input_text
        string predicted_language
        text confidence_scores
        float accuracy_score
        float processing_time
        datetime created_at
        boolean is_public
        string actual_language
    }

    model_training {
        int id PK
        datetime training_date
        int samples_count
        float accuracy
        float error_rate
        float loss
        int epochs
        float learning_rate
        int feature_count
        float training_time
        text notes
    }

    users ||--o{ surveys : "has"
    users ||--o{ predictions : "makes"
Loading

About

2425-11-b-pp-student-practices-assignment-IVBadalov21 created by GitHub Classroom

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published