Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -2,68 +2,57 @@ import streamlit as st
|
|
2 |
from transformers import pipeline
|
3 |
from textblob import TextBlob
|
4 |
|
5 |
-
st.title("π
|
6 |
|
7 |
-
# Load
|
8 |
@st.cache_resource
|
9 |
-
def
|
10 |
grammar_model = pipeline('text2text-generation', model='prithivida/grammar_error_correcter_v1')
|
11 |
-
|
12 |
-
return grammar_model, punctuation_model
|
13 |
|
14 |
-
grammar_model
|
15 |
|
16 |
-
user_text = st.text_area("Enter text
|
17 |
|
18 |
-
if st.button("Correct
|
19 |
-
if user_text.strip()
|
20 |
-
st.warning("β οΈ Please enter text
|
21 |
else:
|
22 |
-
#
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
-
|
40 |
-
|
41 |
-
|
42 |
-
|
43 |
-
|
44 |
-
|
45 |
-
|
46 |
-
|
47 |
-
|
48 |
-
|
49 |
-
|
50 |
-
|
51 |
-
st.markdown("**π Spelling & Pluralization Corrections Applied:**")
|
52 |
-
st.write(spelling_corrected)
|
53 |
-
st.markdown("---")
|
54 |
-
|
55 |
-
st.info("Review each step carefully to understand the corrections made.")
|
56 |
-
else:
|
57 |
-
st.success("π Your text had no detectable errors!")
|
58 |
-
|
59 |
-
# Learning Recommendations
|
60 |
-
st.subheader("π Recommendations to Improve Your Writing:")
|
61 |
st.markdown("""
|
62 |
-
-
|
63 |
-
-
|
64 |
-
-
|
65 |
|
66 |
-
**
|
67 |
- [Grammarly Handbook](https://www.grammarly.com/blog/category/handbook/)
|
68 |
-
- [
|
69 |
-
""")
|
|
|
2 |
from transformers import pipeline
|
3 |
from textblob import TextBlob
|
4 |
|
5 |
+
st.title("π AI Grammar & Spelling Correction")
|
6 |
|
7 |
+
# Load the grammar correction model
|
8 |
@st.cache_resource
|
9 |
+
def load_model():
|
10 |
grammar_model = pipeline('text2text-generation', model='prithivida/grammar_error_correcter_v1')
|
11 |
+
return grammar_model
|
|
|
12 |
|
13 |
+
grammar_model = load_model()
|
14 |
|
15 |
+
user_text = st.text_area("Enter text for correction:", height=200)
|
16 |
|
17 |
+
if st.button("Correct & Explain"):
|
18 |
+
if not user_text.strip():
|
19 |
+
st.warning("β οΈ Please enter some text.")
|
20 |
else:
|
21 |
+
# Grammar & punctuation correction
|
22 |
+
corrected_output = grammar_model(user_text, max_length=512)
|
23 |
+
corrected_text = corrected_output[0]['generated_text']
|
24 |
+
|
25 |
+
# Spelling & pluralization correction using TextBlob
|
26 |
+
blob = TextBlob(corrected_text)
|
27 |
+
final_text = str(blob.correct())
|
28 |
+
|
29 |
+
# Display corrected text
|
30 |
+
st.subheader("β
Corrected Text:")
|
31 |
+
st.write(final_text)
|
32 |
+
|
33 |
+
# Explanation of corrections clearly
|
34 |
+
st.subheader("π Explanation of Corrections:")
|
35 |
+
|
36 |
+
if user_text != corrected_text:
|
37 |
+
st.markdown("**Grammar & Punctuation Corrections Applied:**")
|
38 |
+
st.markdown(f"- `{corrected_text}`")
|
39 |
+
st.markdown("---")
|
40 |
+
|
41 |
+
if corrected_text != final_text:
|
42 |
+
st.markdown("**Spelling & Pluralization Corrections Applied:**")
|
43 |
+
st.markdown(f"- `{final_text}`")
|
44 |
+
st.markdown("---")
|
45 |
+
|
46 |
+
if user_text == final_text:
|
47 |
+
st.success("No corrections needed, your text was already correct!")
|
48 |
+
|
49 |
+
st.subheader("π Recommendations to Improve:")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
50 |
st.markdown("""
|
51 |
+
- Regularly practice grammar, punctuation, and spelling.
|
52 |
+
- Review differences carefully to understand corrections.
|
53 |
+
- Use tools like Grammarly for continuous learning.
|
54 |
|
55 |
+
**Useful Links:**
|
56 |
- [Grammarly Handbook](https://www.grammarly.com/blog/category/handbook/)
|
57 |
+
- [EnglishGrammar.org](https://www.englishgrammar.org/)
|
58 |
+
""")
|