File size: 1,989 Bytes
8d1a9f0
c1988ed
8d1a9f0
c1988ed
6243b99
8d1a9f0
6243b99
c1988ed
6243b99
 
8d1a9f0
6243b99
8d1a9f0
c1988ed
6243b99
c1988ed
6243b99
 
 
 
8d1a9f0
6243b99
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
8d1a9f0
6243b99
8d1a9f0
6243b99
 
c1988ed
6243b99
 
 
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
47
48
49
import streamlit as st
from transformers import pipeline

# App Title
st.title("πŸ§‘β€πŸŽ“ Advanced AI English Correction & Improvement")

# Load Google's FLAN-T5-LARGE model (cached)
@st.cache_resource
def load_correction_model():
    return pipeline("text2text-generation", model="google/flan-t5-large")

correction_model = load_correction_model()

# User input
user_text = st.text_area("Enter your sentence, paragraph, or text here:", height=200)

# Correction and analysis logic
if st.button("Correct & Improve"):
    if not user_text.strip():
        st.warning("⚠️ Please enter text to analyze!")
    else:
        prompt = f"Correct the grammar, punctuation, and improve readability: {user_text}"
        corrected_output = correction_model(prompt, max_length=512, clean_up_tokenization_spaces=True)

        improved_text = corrected_output[0]['generated_text']

        # Display Results
        st.subheader("βœ… Corrected & Improved Text:")
        st.write(improved_text)

        # Provide detailed explanation (AI-based)
        st.subheader("πŸ“ What's improved:")
        if user_text != improved_text:
            st.markdown("- Improved sentence structure & readability.")
            st.markdown("- Corrected grammar & punctuation.")
            st.markdown("- Enhanced clarity & coherence.")
            st.info("Review the corrected text carefully to better understand punctuation, grammar rules, and style improvements.")
        else:
            st.success("No issues found. Excellent writing!")

        # Learning recommendations
        st.subheader("πŸ“š Tips to Learn & Improve:")
        st.markdown("""
        - Review punctuation usage (commas, question marks, exclamation points).
        - Practice sentence structuring for clarity and readability.
        - Use resources like [Grammarly](https://www.grammarly.com/blog/category/handbook/) and [Purdue OWL](https://owl.purdue.edu/owl/purdue_owl.html) to enhance your writing skills.
        """)