ZeeAI1 commited on
Commit
c1988ed
Β·
verified Β·
1 Parent(s): 34dc063

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +31 -34
app.py CHANGED
@@ -1,48 +1,45 @@
1
  import streamlit as st
2
- import language_tool_python
3
 
4
- # App title
5
- st.title("English Writing Correction Assistant ✍️")
6
 
7
- # Initialize LanguageTool for English
8
- tool = language_tool_python.LanguageTool('en-US')
 
 
9
 
10
- # Text input from user
11
- user_text = st.text_area("Enter your text here:", height=200)
12
 
13
- # Analyze button
14
- if st.button("Correct and Analyze"):
 
 
15
  if user_text.strip() == "":
16
- st.warning("Please enter some text to analyze.")
17
  else:
18
- # Get grammar corrections
19
- matches = tool.check(user_text)
20
- corrected_text = language_tool_python.utils.correct(user_text, matches)
21
 
22
- # Display Corrected Text
23
  st.subheader("βœ… Corrected Text:")
24
  st.write(corrected_text)
25
 
26
- # Detailed feedback on issues
27
- st.subheader("πŸ“ Improvement Suggestions:")
28
- if matches:
29
- for idx, match in enumerate(matches, start=1):
30
- st.markdown(f"**{idx}. Issue:** {match.ruleDescription}")
31
- st.markdown(f"**Context:** ...{match.context}...")
32
- if match.replacements:
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 grammatical or stylistic issues found!")
39
 
40
- # Learning suggestions
41
  st.subheader("πŸ“š Learning Recommendations:")
42
- if matches:
43
- st.info("Consider reviewing:")
44
- suggestions = set(match.ruleIssueType for match in matches if match.ruleIssueType)
45
- for s in suggestions:
46
- st.markdown(f"- {s.replace('_', ' ').title()}")
47
- else:
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
+