File size: 1,330 Bytes
de9cc6a
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
import streamlit as st
from transformers import pipeline

# Load grammar correction model
corrector = pipeline("text2text-generation", model="vennify/t5-base-grammar-correction")
explainer = pipeline("text2text-generation", model="google/flan-t5-base")

st.title("🧠 English Sentence Helper")
st.write("Improve your grammar, get feedback, and learn from your mistakes.")

user_input = st.text_area("✍️ Enter a sentence you want to check:")

if st.button("Analyze"):
    if user_input:
        with st.spinner("Analyzing your sentence..."):
            corrected = corrector(user_input)[0]['generated_text']
            explanation_prompt = f"Explain the grammatical errors in this sentence: {user_input}"
            improvement_prompt = f"Suggest improvements in grammar, vocabulary, or structure: {user_input}"

            explanation = explainer(explanation_prompt)[0]['generated_text']
            improvements = explainer(improvement_prompt)[0]['generated_text']

        st.success("✅ Analysis Complete!")

        st.markdown(f"**Original Sentence:** {user_input}")
        st.markdown(f"**Corrected Sentence:** {corrected}")
        st.markdown(f"**Grammar Explanation:** {explanation}")
        st.markdown(f"**Improvement Suggestions:** {improvements}")
    else:
        st.warning("Please enter a sentence.")