File size: 1,773 Bytes
8d1a9f0
c1988ed
8d1a9f0
c1988ed
 
8d1a9f0
c1988ed
 
 
 
8d1a9f0
c1988ed
8d1a9f0
c1988ed
 
 
 
8d1a9f0
c1988ed
8d1a9f0
c1988ed
 
 
8d1a9f0
c1988ed
8d1a9f0
 
 
c1988ed
 
 
 
 
 
 
8d1a9f0
c1988ed
8d1a9f0
 
c1988ed
 
 
 
 
 
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
import streamlit as st
from transformers import pipeline

# App Title
st.title("πŸ“ AI English Writing Assistant")

# Initialize Hugging Face Grammar Correction pipeline
@st.cache_resource
def load_model():
    return pipeline("text2text-generation", model="vennify/t5-base-grammar-correction")

model = load_model()

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

if st.button("Correct Text"):
    if user_text.strip() == "":
        st.warning("Please enter text for correction.")
    else:
        # Perform correction
        result = model(user_text, max_length=512, clean_up_tokenization_spaces=True)
        corrected_text = result[0]['generated_text']

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

        # Simple explanation and suggestions (basic demo)
        st.subheader("πŸ’‘ Improvement Suggestions:")
        if user_text != corrected_text:
            st.info("Review differences carefully to learn grammar usage.")
            st.markdown("- Compare your original sentence to the corrected sentence.")
            st.markdown("- Note the punctuation, tense, or grammar corrections.")
            st.markdown("- Practice similar sentence constructions.")
        else:
            st.success("No corrections needed. Great job!")

        st.subheader("πŸ“š Learning Recommendations:")
        st.markdown("""
        - Review grammar rules related to sentence structure, verb tense consistency, and punctuation.
        - Practice regularly with corrected examples.
        - Utilize grammar learning resources online ([Grammarly](https://www.grammarly.com/blog/category/handbook/), [EnglishGrammar.org](https://www.englishgrammar.org/)).
        """)