Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -1,48 +1,45 @@
|
|
1 |
import streamlit as st
|
2 |
-
import
|
3 |
|
4 |
-
# App
|
5 |
-
st.title("English Writing
|
6 |
|
7 |
-
# Initialize
|
8 |
-
|
|
|
|
|
9 |
|
10 |
-
|
11 |
-
user_text = st.text_area("Enter your text here:", height=200)
|
12 |
|
13 |
-
#
|
14 |
-
|
|
|
|
|
15 |
if user_text.strip() == "":
|
16 |
-
st.warning("Please enter
|
17 |
else:
|
18 |
-
#
|
19 |
-
|
20 |
-
corrected_text =
|
21 |
|
22 |
-
# Display
|
23 |
st.subheader("β
Corrected Text:")
|
24 |
st.write(corrected_text)
|
25 |
|
26 |
-
#
|
27 |
-
st.subheader("
|
28 |
-
if
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
st.markdown(f"**Suggested Corrections:** {', '.join(match.replacements)}")
|
34 |
-
else:
|
35 |
-
st.markdown("**Suggested Corrections:** None provided.")
|
36 |
-
st.markdown("---")
|
37 |
else:
|
38 |
-
st.success("No
|
39 |
|
40 |
-
# Learning suggestions
|
41 |
st.subheader("π Learning Recommendations:")
|
42 |
-
|
43 |
-
|
44 |
-
|
45 |
-
|
46 |
-
|
47 |
-
|
48 |
-
st.write("Your writing looks great! Keep it up! π")
|
|
|
1 |
import streamlit as st
|
2 |
+
from transformers import pipeline
|
3 |
|
4 |
+
# App Title
|
5 |
+
st.title("π AI English Writing Assistant")
|
6 |
|
7 |
+
# Initialize Hugging Face Grammar Correction pipeline
|
8 |
+
@st.cache_resource
|
9 |
+
def load_model():
|
10 |
+
return pipeline("text2text-generation", model="vennify/t5-base-grammar-correction")
|
11 |
|
12 |
+
model = load_model()
|
|
|
13 |
|
14 |
+
# User input
|
15 |
+
user_text = st.text_area("Enter your text to correct:", height=200)
|
16 |
+
|
17 |
+
if st.button("Correct Text"):
|
18 |
if user_text.strip() == "":
|
19 |
+
st.warning("Please enter text for correction.")
|
20 |
else:
|
21 |
+
# Perform correction
|
22 |
+
result = model(user_text, max_length=512, clean_up_tokenization_spaces=True)
|
23 |
+
corrected_text = result[0]['generated_text']
|
24 |
|
25 |
+
# Display corrected text
|
26 |
st.subheader("β
Corrected Text:")
|
27 |
st.write(corrected_text)
|
28 |
|
29 |
+
# Simple explanation and suggestions (basic demo)
|
30 |
+
st.subheader("π‘ Improvement Suggestions:")
|
31 |
+
if user_text != corrected_text:
|
32 |
+
st.info("Review differences carefully to learn grammar usage.")
|
33 |
+
st.markdown("- Compare your original sentence to the corrected sentence.")
|
34 |
+
st.markdown("- Note the punctuation, tense, or grammar corrections.")
|
35 |
+
st.markdown("- Practice similar sentence constructions.")
|
|
|
|
|
|
|
|
|
36 |
else:
|
37 |
+
st.success("No corrections needed. Great job!")
|
38 |
|
|
|
39 |
st.subheader("π Learning Recommendations:")
|
40 |
+
st.markdown("""
|
41 |
+
- Review grammar rules related to sentence structure, verb tense consistency, and punctuation.
|
42 |
+
- Practice regularly with corrected examples.
|
43 |
+
- Utilize grammar learning resources online ([Grammarly](https://www.grammarly.com/blog/category/handbook/), [EnglishGrammar.org](https://www.englishgrammar.org/)).
|
44 |
+
""")
|
45 |
+
|
|