# config.py
import os
class Config:
SECRET_KEY = os.environ.get('SECRET_KEY') or 'hard-to-guess-string'
class DevelopmentConfig(Config):
DEBUG = True
class ProductionConfig(Config):
DEBUG = False
# app/__init__.py
from flask import Flask
from config import DevelopmentConfig, ProductionConfig
def create_app(config_class=DevelopmentConfig):
app = Flask(__name__)
app.config.from_object(config_class)
from app.routes import bp as main_bp
app.register_blueprint(main_bp)
return app
# app/routes.py
from flask import Blueprint, render_template, request, redirect, url_for
from app.forms import CheckPlagiarismForm
from app.utils import check_plagiarism
bp = Blueprint('main', __name__)
@bp.route('/', methods=['GET', 'POST'])
def index():
form = CheckPlagiarismForm()
if form.validate_on_submit():
text1 = form.text1.data
text2 = form.text2.data
result = check_plagiarism(text1, text2)
return redirect(url_for('main.results', result=result))
return render_template('index.html', form=form)
@bp.route('/results/
')
def results(result):
return render_template('results.html', result=result)
# app/forms.py
from flask_wtf import FlaskForm
from wtforms import TextAreaField, SubmitField
from wtforms.validators import DataRequired, Length
class CheckPlagiarismForm(FlaskForm):
text1 = TextAreaField('Text 1', validators=[DataRequired(), Length(min=10)])
text2 = TextAreaField('Text 2', validators=[DataRequired(), Length(min=10)])
submit = SubmitField('Check')
# app/utils.py
from difflib import SequenceMatcher
def check_plagiarism(text1, text2):
"""
Check plagiarism between two texts using the SequenceMatcher class from difflib library
"""
s = SequenceMatcher(None, text1, text2)
ratio = s.ratio()
return round(ratio * 100, 2)
Plagiarism Checker
Plagiarism Checker
{% block content %}{% endblock %}
{% extends 'base.html' %}
{% block content %}
Check Plagiarism
{% endblock %}
{% extends 'base.html' %}
{% block content %}
Results
The plagiarism score is {{ result }}%
Check another plagiarism
{% endblock %}
// static/js/script.js
console.log('Hello World!');
{% extends 'base.html' %}
{% block content %}
Results
The plagiarism score is {{ result }}%
Check another plagiarism
{% endblock %}
// static/js/script.js
console.log('Hello World!');
Flask==2.1.1
Flask-WTF==0.15.1