File size: 2,073 Bytes
8d1a9f0
aa0f607
 
8d1a9f0
285efdb
8d1a9f0
285efdb
aa0f607
285efdb
aa0f607
285efdb
8d1a9f0
285efdb
8d1a9f0
285efdb
c1988ed
285efdb
 
 
5a43a4c
285efdb
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
aa0f607
285efdb
 
 
aa0f607
285efdb
aa0f607
285efdb
 
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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
import streamlit as st
from transformers import pipeline
from textblob import TextBlob

st.title("πŸ“– AI Grammar & Spelling Correction")

# Load the grammar correction model
@st.cache_resource
def load_model():
    grammar_model = pipeline('text2text-generation', model='prithivida/grammar_error_correcter_v1')
    return grammar_model

grammar_model = load_model()

user_text = st.text_area("Enter text for correction:", height=200)

if st.button("Correct & Explain"):
    if not user_text.strip():
        st.warning("⚠️ Please enter some text.")
    else:
        # Grammar & punctuation correction
        corrected_output = grammar_model(user_text, max_length=512)
        corrected_text = corrected_output[0]['generated_text']

        # Spelling & pluralization correction using TextBlob
        blob = TextBlob(corrected_text)
        final_text = str(blob.correct())

        # Display corrected text
        st.subheader("βœ… Corrected Text:")
        st.write(final_text)

        # Explanation of corrections clearly
        st.subheader("πŸ“ Explanation of Corrections:")
        
        if user_text != corrected_text:
            st.markdown("**Grammar & Punctuation Corrections Applied:**")
            st.markdown(f"- `{corrected_text}`")
            st.markdown("---")
        
        if corrected_text != final_text:
            st.markdown("**Spelling & Pluralization Corrections Applied:**")
            st.markdown(f"- `{final_text}`")
            st.markdown("---")

        if user_text == final_text:
            st.success("No corrections needed, your text was already correct!")

        st.subheader("πŸ“š Recommendations to Improve:")
        st.markdown("""
        - Regularly practice grammar, punctuation, and spelling.
        - Review differences carefully to understand corrections.
        - Use tools like Grammarly for continuous learning.

        **Useful Links:**
        - [Grammarly Handbook](https://www.grammarly.com/blog/category/handbook/)
        - [EnglishGrammar.org](https://www.englishgrammar.org/)
        """)