File size: 1,801 Bytes
8d1a9f0
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import language_tool_python

# App title
st.title("English Writing Correction Assistant ✍️")

# Initialize LanguageTool for English
tool = language_tool_python.LanguageTool('en-US')

# Text input from user
user_text = st.text_area("Enter your text here:", height=200)

# Analyze button
if st.button("Correct and Analyze"):
    if user_text.strip() == "":
        st.warning("Please enter some text to analyze.")
    else:
        # Get grammar corrections
        matches = tool.check(user_text)
        corrected_text = language_tool_python.utils.correct(user_text, matches)

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

        # Detailed feedback on issues
        st.subheader("πŸ“ Improvement Suggestions:")
        if matches:
            for idx, match in enumerate(matches, start=1):
                st.markdown(f"**{idx}. Issue:** {match.ruleDescription}")
                st.markdown(f"**Context:** ...{match.context}...")
                if match.replacements:
                    st.markdown(f"**Suggested Corrections:** {', '.join(match.replacements)}")
                else:
                    st.markdown("**Suggested Corrections:** None provided.")
                st.markdown("---")
        else:
            st.success("No grammatical or stylistic issues found!")

        # Learning suggestions
        st.subheader("πŸ“š Learning Recommendations:")
        if matches:
            st.info("Consider reviewing:")
            suggestions = set(match.ruleIssueType for match in matches if match.ruleIssueType)
            for s in suggestions:
                st.markdown(f"- {s.replace('_', ' ').title()}")
        else:
            st.write("Your writing looks great! Keep it up! πŸŽ‰")