ZeeAI1's picture
Update app.py
c1988ed verified
raw
history blame
1.77 kB
import streamlit as st
from transformers import pipeline
# App Title
st.title("πŸ“ AI English Writing Assistant")
# Initialize Hugging Face Grammar Correction pipeline
@st.cache_resource
def load_model():
return pipeline("text2text-generation", model="vennify/t5-base-grammar-correction")
model = load_model()
# User input
user_text = st.text_area("Enter your text to correct:", height=200)
if st.button("Correct Text"):
if user_text.strip() == "":
st.warning("Please enter text for correction.")
else:
# Perform correction
result = model(user_text, max_length=512, clean_up_tokenization_spaces=True)
corrected_text = result[0]['generated_text']
# Display corrected text
st.subheader("βœ… Corrected Text:")
st.write(corrected_text)
# Simple explanation and suggestions (basic demo)
st.subheader("πŸ’‘ Improvement Suggestions:")
if user_text != corrected_text:
st.info("Review differences carefully to learn grammar usage.")
st.markdown("- Compare your original sentence to the corrected sentence.")
st.markdown("- Note the punctuation, tense, or grammar corrections.")
st.markdown("- Practice similar sentence constructions.")
else:
st.success("No corrections needed. Great job!")
st.subheader("πŸ“š Learning Recommendations:")
st.markdown("""
- Review grammar rules related to sentence structure, verb tense consistency, and punctuation.
- Practice regularly with corrected examples.
- Utilize grammar learning resources online ([Grammarly](https://www.grammarly.com/blog/category/handbook/), [EnglishGrammar.org](https://www.englishgrammar.org/)).
""")