|
from flask import Flask, render_template, request, jsonify |
|
from transformers import pipeline |
|
|
|
|
|
spelling_correction_pipe = pipeline("text2text-generation", model="Elalimy/english_spelling_correction", |
|
max_new_tokens=100) |
|
|
|
|
|
app = Flask(__name__) |
|
|
|
|
|
|
|
@app.route('/') |
|
def index(): |
|
return render_template('index.html') |
|
|
|
|
|
|
|
@app.route('/correct', methods=['POST']) |
|
def correct_spelling(): |
|
|
|
text = request.form['text'] |
|
|
|
|
|
corrected_text = spelling_correction_pipe(text)[0]['generated_text'].strip() |
|
|
|
|
|
return jsonify({'corrected_text': corrected_text}) |
|
|
|
|
|
if __name__ == '__main__': |
|
|
|
app.run(debug=True) |
|
|