File size: 2,918 Bytes
8d1a9f0
aa0f607
 
8d1a9f0
aa0f607
8d1a9f0
aa0f607
 
 
 
 
 
8d1a9f0
aa0f607
8d1a9f0
aa0f607
c1988ed
aa0f607
5a43a4c
aa0f607
5a43a4c
aa0f607
 
5a43a4c
aa0f607
 
5a43a4c
aa0f607
 
 
5a43a4c
aa0f607
 
 
5a43a4c
aa0f607
 
5a43a4c
aa0f607
 
 
 
 
5a43a4c
aa0f607
 
 
 
5a43a4c
aa0f607
 
 
 
5a43a4c
aa0f607
5a43a4c
aa0f607
 
 
 
 
 
 
 
 
 
 
 
 
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
60
61
62
63
64
65
66
67
68
69
import streamlit as st
from transformers import pipeline
from textblob import TextBlob

st.title("πŸ“– English Grammar, Spelling & Punctuation Assistant")

# Load models once (cached for efficiency)
@st.cache_resource
def load_models():
    grammar_model = pipeline('text2text-generation', model='prithivida/grammar_error_correcter_v1')
    punctuation_model = pipeline('text2text-generation', model='oliverguhr/fullstop-punctuation-multilang-large')
    return grammar_model, punctuation_model

grammar_model, punctuation_model = load_models()

user_text = st.text_area("Enter text to correct:", height=200)

if st.button("Correct and Explain"):
    if user_text.strip() == "":
        st.warning("⚠️ Please enter text first.")
    else:
        # Step 1: Grammar correction
        grammar_corrected = grammar_model(user_text, max_length=512)[0]['generated_text']

        # Step 2: Punctuation correction
        punctuation_corrected = punctuation_model(grammar_corrected, max_length=512)[0]['generated_text']

        # Step 3: Spelling and pluralization correction using TextBlob
        blob = TextBlob(punctuation_corrected)
        spelling_corrected = str(blob.correct())

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

        # Provide clear explanations of corrections
        st.subheader("πŸ“ Detailed Explanations:")

        if user_text != spelling_corrected:
            if user_text != grammar_corrected:
                st.markdown("**πŸ“Œ Grammar Corrections Applied:**")
                st.write(grammar_corrected)
                st.markdown("---")

            if grammar_corrected != punctuation_corrected:
                st.markdown("**πŸ“Œ Punctuation Corrections Applied:**")
                st.write(punctuation_corrected)
                st.markdown("---")

            if punctuation_corrected != spelling_corrected:
                st.markdown("**πŸ“Œ Spelling & Pluralization Corrections Applied:**")
                st.write(spelling_corrected)
                st.markdown("---")

            st.info("Review each step carefully to understand the corrections made.")
        else:
            st.success("πŸŽ‰ Your text had no detectable errors!")

        # Learning Recommendations
        st.subheader("πŸ“š Recommendations to Improve Your Writing:")
        st.markdown("""
        - **Grammar**: Review rules related to verb tenses, articles, and sentence structures.
        - **Punctuation**: Focus on correct usage of commas, periods, question marks, and exclamation points.
        - **Spelling & Pluralization**: Regularly check spelling and plural forms, especially for irregular words.

        **Recommended resources:**
        - [Grammarly Handbook](https://www.grammarly.com/blog/category/handbook/)
        - [English Grammar Lessons](https://www.englishgrammar.org/)
        """)