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.
-
Extract the project to a folder on your computer
-
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
- 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
- Run the application:
python run_local.py
- Open your browser and go to:
http://localhost:5000
-
Install PostgreSQL and create a database named
language_detector
-
Set environment variables:
export DATABASE_URL=postgresql://username:password@localhost/language_detector
export SESSION_SECRET=your-secret-key-here
- Run the application:
python run_local.py
- 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
- Register a new account or login
- Use the "Predict Language" page to test text samples
- Submit training data via the "Survey" page
- View your prediction history in "Results"
wsgi.py
- WSGI entry point for deploymentrun_local.py
- Application runner for local developmentapp/core/perceptron.py
- Custom Perceptron algorithmapp/core/language_features.py
- Feature extraction for text analysisapp/models.py
- Database modelsapp/auth/
- Authentication routesapp/main/
- Main application routesapp/admin/
- Admin panel routesapp/templates/
- HTML templatesapp/static/
- CSS and JavaScript files
If you get database errors, make sure:
- PostgreSQL is running (if using PostgreSQL)
- Database exists and credentials are correct
- Environment variables are set properly
For SQLite (easier option), the database file will be created automatically in the instance/
folder.
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"