ZeeAI1's picture
Update app.py
aa0f607 verified
raw
history blame
2.92 kB
import streamlit as st
from transformers import pipeline
from textblob import TextBlob
st.title("πŸ“– English Grammar, Spelling & Punctuation Assistant")
# Load models once (cached for efficiency)
@st.cache_resource
def load_models():
grammar_model = pipeline('text2text-generation', model='prithivida/grammar_error_correcter_v1')
punctuation_model = pipeline('text2text-generation', model='oliverguhr/fullstop-punctuation-multilang-large')
return grammar_model, punctuation_model
grammar_model, punctuation_model = load_models()
user_text = st.text_area("Enter text to correct:", height=200)
if st.button("Correct and Explain"):
if user_text.strip() == "":
st.warning("⚠️ Please enter text first.")
else:
# Step 1: Grammar correction
grammar_corrected = grammar_model(user_text, max_length=512)[0]['generated_text']
# Step 2: Punctuation correction
punctuation_corrected = punctuation_model(grammar_corrected, max_length=512)[0]['generated_text']
# Step 3: Spelling and pluralization correction using TextBlob
blob = TextBlob(punctuation_corrected)
spelling_corrected = str(blob.correct())
# Display final corrected text
st.subheader("βœ… Fully Corrected Text:")
st.write(spelling_corrected)
# Provide clear explanations of corrections
st.subheader("πŸ“ Detailed Explanations:")
if user_text != spelling_corrected:
if user_text != grammar_corrected:
st.markdown("**πŸ“Œ Grammar Corrections Applied:**")
st.write(grammar_corrected)
st.markdown("---")
if grammar_corrected != punctuation_corrected:
st.markdown("**πŸ“Œ Punctuation Corrections Applied:**")
st.write(punctuation_corrected)
st.markdown("---")
if punctuation_corrected != spelling_corrected:
st.markdown("**πŸ“Œ Spelling & Pluralization Corrections Applied:**")
st.write(spelling_corrected)
st.markdown("---")
st.info("Review each step carefully to understand the corrections made.")
else:
st.success("πŸŽ‰ Your text had no detectable errors!")
# Learning Recommendations
st.subheader("πŸ“š Recommendations to Improve Your Writing:")
st.markdown("""
- **Grammar**: Review rules related to verb tenses, articles, and sentence structures.
- **Punctuation**: Focus on correct usage of commas, periods, question marks, and exclamation points.
- **Spelling & Pluralization**: Regularly check spelling and plural forms, especially for irregular words.
**Recommended resources:**
- [Grammarly Handbook](https://www.grammarly.com/blog/category/handbook/)
- [English Grammar Lessons](https://www.englishgrammar.org/)
""")