ZeeAI1's picture
Create app.py
8d1a9f0 verified
raw
history blame
1.8 kB
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! πŸŽ‰")