Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -2,44 +2,47 @@ import streamlit as st
|
|
2 |
from transformers import pipeline
|
3 |
|
4 |
# App Title
|
5 |
-
st.title("
|
6 |
|
7 |
-
#
|
8 |
@st.cache_resource
|
9 |
-
def
|
10 |
-
return pipeline("text2text-generation", model="
|
11 |
|
12 |
-
|
13 |
|
14 |
# User input
|
15 |
-
user_text = st.text_area("Enter your text
|
16 |
|
17 |
-
|
18 |
-
|
19 |
-
|
|
|
20 |
else:
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
st.
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
st.markdown("-
|
34 |
-
st.markdown("-
|
35 |
-
st.markdown("-
|
|
|
36 |
else:
|
37 |
-
st.success("No
|
38 |
|
39 |
-
|
|
|
40 |
st.markdown("""
|
41 |
-
- Review
|
42 |
-
- Practice
|
43 |
-
-
|
44 |
""")
|
45 |
|
|
|
2 |
from transformers import pipeline
|
3 |
|
4 |
# App Title
|
5 |
+
st.title("π§βπ Advanced AI English Correction & Improvement")
|
6 |
|
7 |
+
# Load Google's FLAN-T5-LARGE model (cached)
|
8 |
@st.cache_resource
|
9 |
+
def load_correction_model():
|
10 |
+
return pipeline("text2text-generation", model="google/flan-t5-large")
|
11 |
|
12 |
+
correction_model = load_correction_model()
|
13 |
|
14 |
# User input
|
15 |
+
user_text = st.text_area("Enter your sentence, paragraph, or text here:", height=200)
|
16 |
|
17 |
+
# Correction and analysis logic
|
18 |
+
if st.button("Correct & Improve"):
|
19 |
+
if not user_text.strip():
|
20 |
+
st.warning("β οΈ Please enter text to analyze!")
|
21 |
else:
|
22 |
+
prompt = f"Correct the grammar, punctuation, and improve readability: {user_text}"
|
23 |
+
corrected_output = correction_model(prompt, max_length=512, clean_up_tokenization_spaces=True)
|
24 |
+
|
25 |
+
improved_text = corrected_output[0]['generated_text']
|
26 |
+
|
27 |
+
# Display Results
|
28 |
+
st.subheader("β
Corrected & Improved Text:")
|
29 |
+
st.write(improved_text)
|
30 |
+
|
31 |
+
# Provide detailed explanation (AI-based)
|
32 |
+
st.subheader("π What's improved:")
|
33 |
+
if user_text != improved_text:
|
34 |
+
st.markdown("- Improved sentence structure & readability.")
|
35 |
+
st.markdown("- Corrected grammar & punctuation.")
|
36 |
+
st.markdown("- Enhanced clarity & coherence.")
|
37 |
+
st.info("Review the corrected text carefully to better understand punctuation, grammar rules, and style improvements.")
|
38 |
else:
|
39 |
+
st.success("No issues found. Excellent writing!")
|
40 |
|
41 |
+
# Learning recommendations
|
42 |
+
st.subheader("π Tips to Learn & Improve:")
|
43 |
st.markdown("""
|
44 |
+
- Review punctuation usage (commas, question marks, exclamation points).
|
45 |
+
- Practice sentence structuring for clarity and readability.
|
46 |
+
- Use resources like [Grammarly](https://www.grammarly.com/blog/category/handbook/) and [Purdue OWL](https://owl.purdue.edu/owl/purdue_owl.html) to enhance your writing skills.
|
47 |
""")
|
48 |
|