Spaces:
Sleeping
Sleeping
| import streamlit as st | |
| from transformers import pipeline | |
| from textblob import TextBlob | |
| st.title("π AI Grammar & Spelling Correction") | |
| # Load the grammar correction model | |
| 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/) | |
| """) | |