File size: 956 Bytes
c45128b
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
from flask import Flask, render_template, request, jsonify
from transformers import pipeline

# Initialize the spelling correction pipeline with max_new_tokens parameter
spelling_correction_pipe = pipeline("text2text-generation", model="Elalimy/english_spelling_correction",
                                    max_new_tokens=100)

# Initialize Flask app
app = Flask(__name__)


# Define a route to render the form
@app.route('/')
def index():
    return render_template('index.html')


# Define a route for spelling correction
@app.route('/correct', methods=['POST'])
def correct_spelling():
    # Get the input text from the request
    text = request.form['text']

    # Perform spelling correction
    corrected_text = spelling_correction_pipe(text)[0]['generated_text'].strip()

    # Return the corrected text as JSON
    return jsonify({'corrected_text': corrected_text})


if __name__ == '__main__':
    # Run the Flask app
    app.run(debug=True)