Yoshinoheart
commited on
Commit
•
ee7952e
1
Parent(s):
93cd416
Upload files
Browse files- app.py +37 -0
- requirements.txt +2 -0
app.py
ADDED
@@ -0,0 +1,37 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import streamlit as st
|
2 |
+
from transformers import pipeline
|
3 |
+
from happytransformer import HappyTextToText, TTSettings
|
4 |
+
|
5 |
+
# Initialize the spelling correction pipeline
|
6 |
+
fix_spelling = pipeline("text2text-generation", model="oliverguhr/spelling-correction-english-base")
|
7 |
+
|
8 |
+
# Initialize the grammar correction model
|
9 |
+
happy_tt = HappyTextToText("T5", "vennify/t5-base-grammar-correction")
|
10 |
+
args = TTSettings(num_beams=5, min_length=1)
|
11 |
+
|
12 |
+
# Streamlit app
|
13 |
+
def main():
|
14 |
+
st.title("Spelling and Grammar Checker")
|
15 |
+
|
16 |
+
# Input text area
|
17 |
+
text_input = st.text_area("Enter your text here:")
|
18 |
+
|
19 |
+
# Check button
|
20 |
+
if st.button("Check"):
|
21 |
+
# Spelling correction
|
22 |
+
corrected_spelling = fix_spelling(text_input)[0]['generated_text']
|
23 |
+
|
24 |
+
# Grammar correction
|
25 |
+
result = happy_tt.generate_text(f"grammar: {text_input}", args=args)
|
26 |
+
corrected_grammar = result.text
|
27 |
+
|
28 |
+
# Display corrected text
|
29 |
+
st.subheader("Corrected Text:")
|
30 |
+
st.write(corrected_grammar) # Display grammar-corrected text
|
31 |
+
|
32 |
+
# Display spelling correction if there's a difference
|
33 |
+
if corrected_spelling != corrected_grammar:
|
34 |
+
st.write(f"Spelling was also corrected to: {corrected_spelling}")
|
35 |
+
|
36 |
+
if __name__ == "__main__":
|
37 |
+
main()
|
requirements.txt
ADDED
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
1 |
+
transformers
|
2 |
+
happytransformer
|