ZeeAI1 commited on
Commit
6243b99
Β·
verified Β·
1 Parent(s): c1988ed

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +32 -29
app.py CHANGED
@@ -2,44 +2,47 @@ 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
 
 
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