ZeeAI1's picture
Update app.py
285efdb verified
import streamlit as st
from transformers import pipeline
from textblob import TextBlob
st.title("πŸ“– AI Grammar & Spelling Correction")
# Load the grammar correction model
@st.cache_resource
def load_model():
grammar_model = pipeline('text2text-generation', model='prithivida/grammar_error_correcter_v1')
return grammar_model
grammar_model = load_model()
user_text = st.text_area("Enter text for correction:", height=200)
if st.button("Correct & Explain"):
if not user_text.strip():
st.warning("⚠️ Please enter some text.")
else:
# Grammar & punctuation correction
corrected_output = grammar_model(user_text, max_length=512)
corrected_text = corrected_output[0]['generated_text']
# Spelling & pluralization correction using TextBlob
blob = TextBlob(corrected_text)
final_text = str(blob.correct())
# Display corrected text
st.subheader("βœ… Corrected Text:")
st.write(final_text)
# Explanation of corrections clearly
st.subheader("πŸ“ Explanation of Corrections:")
if user_text != corrected_text:
st.markdown("**Grammar & Punctuation Corrections Applied:**")
st.markdown(f"- `{corrected_text}`")
st.markdown("---")
if corrected_text != final_text:
st.markdown("**Spelling & Pluralization Corrections Applied:**")
st.markdown(f"- `{final_text}`")
st.markdown("---")
if user_text == final_text:
st.success("No corrections needed, your text was already correct!")
st.subheader("πŸ“š Recommendations to Improve:")
st.markdown("""
- Regularly practice grammar, punctuation, and spelling.
- Review differences carefully to understand corrections.
- Use tools like Grammarly for continuous learning.
**Useful Links:**
- [Grammarly Handbook](https://www.grammarly.com/blog/category/handbook/)
- [EnglishGrammar.org](https://www.englishgrammar.org/)
""")