'init'
Browse files- main.py +33 -0
- requirements.txt +3 -0
- templates/index.html +84 -0
main.py
ADDED
@@ -0,0 +1,33 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from flask import Flask, render_template, request, jsonify
|
2 |
+
from transformers import pipeline
|
3 |
+
|
4 |
+
# Initialize the spelling correction pipeline with max_new_tokens parameter
|
5 |
+
spelling_correction_pipe = pipeline("text2text-generation", model="Elalimy/english_spelling_correction",
|
6 |
+
max_new_tokens=100)
|
7 |
+
|
8 |
+
# Initialize Flask app
|
9 |
+
app = Flask(__name__)
|
10 |
+
|
11 |
+
|
12 |
+
# Define a route to render the form
|
13 |
+
@app.route('/')
|
14 |
+
def index():
|
15 |
+
return render_template('index.html')
|
16 |
+
|
17 |
+
|
18 |
+
# Define a route for spelling correction
|
19 |
+
@app.route('/correct', methods=['POST'])
|
20 |
+
def correct_spelling():
|
21 |
+
# Get the input text from the request
|
22 |
+
text = request.form['text']
|
23 |
+
|
24 |
+
# Perform spelling correction
|
25 |
+
corrected_text = spelling_correction_pipe(text)[0]['generated_text'].strip()
|
26 |
+
|
27 |
+
# Return the corrected text as JSON
|
28 |
+
return jsonify({'corrected_text': corrected_text})
|
29 |
+
|
30 |
+
|
31 |
+
if __name__ == '__main__':
|
32 |
+
# Run the Flask app
|
33 |
+
app.run(debug=True)
|
requirements.txt
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
Flask
|
2 |
+
transformers
|
3 |
+
gunicorn
|
templates/index.html
ADDED
@@ -0,0 +1,84 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<!DOCTYPE html>
|
2 |
+
<html lang="en">
|
3 |
+
<head>
|
4 |
+
<meta charset="UTF-8">
|
5 |
+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
6 |
+
<title>Spelling Correction</title>
|
7 |
+
<style>
|
8 |
+
body {
|
9 |
+
margin: 0;
|
10 |
+
padding: 0;
|
11 |
+
font-family: Arial, sans-serif;
|
12 |
+
background: linear-gradient(to bottom, #4e4376, #2b5876);
|
13 |
+
color: #ffffff;
|
14 |
+
}
|
15 |
+
.container {
|
16 |
+
width: 80%;
|
17 |
+
margin: 50px auto;
|
18 |
+
padding: 20px;
|
19 |
+
border-radius: 10px;
|
20 |
+
background-color: rgba(0, 0, 0, 0.5); /* Add transparency to the background */
|
21 |
+
}
|
22 |
+
h1 {
|
23 |
+
text-align: center;
|
24 |
+
}
|
25 |
+
form {
|
26 |
+
text-align: center;
|
27 |
+
}
|
28 |
+
textarea {
|
29 |
+
width: 90%;
|
30 |
+
padding: 10px;
|
31 |
+
border-radius: 5px;
|
32 |
+
border: 2px solid #fff;
|
33 |
+
margin-bottom: 10px;
|
34 |
+
background-color: rgba(255, 255, 255, 0.1);
|
35 |
+
color: white;
|
36 |
+
}
|
37 |
+
button {
|
38 |
+
background-color: #f39c12;
|
39 |
+
color: #ffffff;
|
40 |
+
padding: 10px 20px;
|
41 |
+
font-size: 16px;
|
42 |
+
border: none;
|
43 |
+
border-radius: 5px;
|
44 |
+
cursor: pointer;
|
45 |
+
}
|
46 |
+
button:hover {
|
47 |
+
background-color: #e67e22;
|
48 |
+
}
|
49 |
+
#result {
|
50 |
+
font-size: 18px;
|
51 |
+
margin: 34px auto;
|
52 |
+
color: aqua;
|
53 |
+
text-align:center;
|
54 |
+
}
|
55 |
+
</style>
|
56 |
+
</head>
|
57 |
+
<body>
|
58 |
+
<div class="container">
|
59 |
+
<h1>Spelling Correction</h1>
|
60 |
+
<form id="correctionForm" action="/correct" method="post">
|
61 |
+
<label for="textInput">Enter Text:</label><br>
|
62 |
+
<textarea id="textInput" name="text" rows="4" cols="50"></textarea><br>
|
63 |
+
<button type="submit">Correct Spelling</button>
|
64 |
+
</form>
|
65 |
+
<div id="result"></div>
|
66 |
+
</div>
|
67 |
+
|
68 |
+
<script>
|
69 |
+
document.getElementById("correctionForm").addEventListener("submit", function(event) {
|
70 |
+
event.preventDefault();
|
71 |
+
var formData = new FormData(this);
|
72 |
+
fetch('/correct', {
|
73 |
+
method: 'POST',
|
74 |
+
body: formData
|
75 |
+
})
|
76 |
+
.then(response => response.json())
|
77 |
+
.then(data => {
|
78 |
+
document.getElementById("result").innerText = "Corrected Text: " + data.corrected_text;
|
79 |
+
})
|
80 |
+
.catch(error => console.error('Error:', error));
|
81 |
+
});
|
82 |
+
</script>
|
83 |
+
</body>
|
84 |
+
</html>
|