Spaces:
Sleeping
Sleeping
Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import streamlit as st
|
| 2 |
+
from transformers import pipeline
|
| 3 |
+
|
| 4 |
+
# Load grammar correction model
|
| 5 |
+
corrector = pipeline("text2text-generation", model="vennify/t5-base-grammar-correction")
|
| 6 |
+
explainer = pipeline("text2text-generation", model="google/flan-t5-base")
|
| 7 |
+
|
| 8 |
+
st.title("🧠 English Sentence Helper")
|
| 9 |
+
st.write("Improve your grammar, get feedback, and learn from your mistakes.")
|
| 10 |
+
|
| 11 |
+
user_input = st.text_area("✍️ Enter a sentence you want to check:")
|
| 12 |
+
|
| 13 |
+
if st.button("Analyze"):
|
| 14 |
+
if user_input:
|
| 15 |
+
with st.spinner("Analyzing your sentence..."):
|
| 16 |
+
corrected = corrector(user_input)[0]['generated_text']
|
| 17 |
+
explanation_prompt = f"Explain the grammatical errors in this sentence: {user_input}"
|
| 18 |
+
improvement_prompt = f"Suggest improvements in grammar, vocabulary, or structure: {user_input}"
|
| 19 |
+
|
| 20 |
+
explanation = explainer(explanation_prompt)[0]['generated_text']
|
| 21 |
+
improvements = explainer(improvement_prompt)[0]['generated_text']
|
| 22 |
+
|
| 23 |
+
st.success("✅ Analysis Complete!")
|
| 24 |
+
|
| 25 |
+
st.markdown(f"**Original Sentence:** {user_input}")
|
| 26 |
+
st.markdown(f"**Corrected Sentence:** {corrected}")
|
| 27 |
+
st.markdown(f"**Grammar Explanation:** {explanation}")
|
| 28 |
+
st.markdown(f"**Improvement Suggestions:** {improvements}")
|
| 29 |
+
else:
|
| 30 |
+
st.warning("Please enter a sentence.")
|