ZeeAI1 commited on
Commit
1efad02
·
verified ·
1 Parent(s): 94a85b9

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +14 -34
app.py CHANGED
@@ -1,37 +1,17 @@
1
- import streamlit as st
2
- from transformers import pipeline
3
- import re
 
 
 
 
4
 
5
- # Load grammar correction model
6
- @st.cache_resource
7
- def load_corrector():
8
- return pipeline("text2text-generation", model="vennify/t5-base-grammar-correction")
9
 
10
- # Load explanation model
11
- @st.cache_resource
12
- def load_explainer():
13
- return pipeline("text2text-generation", model="google/flan-t5-large")
14
 
15
- grammar_corrector = load_corrector()
16
- explainer = load_explainer()
17
-
18
- # App UI
19
- st.title("🧠 Advanced Grammar Correction Assistant")
20
- st.write("Enter a sentence. I’ll fix it and explain the correction in detail.")
21
-
22
- user_input = st.text_area("✍️ Enter your sentence below:", height=100)
23
-
24
- if st.button("Correct & Explain"):
25
- if user_input.strip() == "":
26
- st.warning("Please enter a sentence.")
27
- else:
28
- # Step 1: Grammar correction
29
- corrected = grammar_corrector(user_input, max_length=128, do_sample=False)[0]['generated_text']
30
-
31
- # Step 2: Explanation prompt
32
- explanation_prompt = f"Original: {user_input}\nCorrected: {corrected}\nExplain the changes simply with grammar rules and examples."
33
- explanation = explainer(explanation_prompt, max_length=200, do_sample=False)[0]['generated_text']
34
-
35
- # Output
36
- st.markdown(f"**Correction:** {corrected}")
37
- st.markdown(f"**Explanation:** {explanation}")
 
1
+ # First, ensure the 'transformers' library is installed
2
+ try:
3
+ from transformers import pipeline
4
+ except ModuleNotFoundError:
5
+ import subprocess
6
+ subprocess.check_call(["pip", "install", "transformers"])
7
+ from transformers import pipeline
8
 
9
+ # Example: Load a grammar correction pipeline (you can replace this with your preferred task/model)
10
+ corrector = pipeline("text2text-generation", model="vennify/t5-base-grammar-correction")
 
 
11
 
12
+ # Sample sentence
13
+ sentence = "She don't like going to the gym because it make her tired."
 
 
14
 
15
+ # Run correction
16
+ result = corrector(sentence, max_length=100, clean_up_tokenization_spaces=True)
17
+ print("Corrected Sentence:", result[0]['generated_text'])