Spaces:
Sleeping
Sleeping
import streamlit as st | |
from transformers import pipeline | |
# App Title | |
st.title("π AI English Writing Assistant") | |
# Initialize Hugging Face Grammar Correction pipeline | |
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/)). | |
""") | |