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

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +17 -14
app.py CHANGED
@@ -1,17 +1,20 @@
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'])
 
 
 
 
 
 
 
 
1
+ from transformers import pipeline
2
+ import streamlit as st
 
 
 
 
 
3
 
4
+ # Load grammar correction pipeline
5
+ @st.cache_resource
6
+ def load_model():
7
+ return pipeline("text2text-generation", model="vennify/t5-base-grammar-correction")
8
 
9
+ corrector = load_model()
 
10
 
11
+ # Streamlit UI
12
+ st.title("Grammar Correction Assistant")
13
+
14
+ user_input = st.text_area("Enter a sentence to correct:", "She don't like going to the gym because it make her tired.")
15
+
16
+ if st.button("Correct Sentence"):
17
+ with st.spinner("Correcting..."):
18
+ result = corrector(user_input, max_length=100, clean_up_tokenization_spaces=True)
19
+ corrected_sentence = result[0]['generated_text']
20
+ st.markdown(f"**Corrected Sentence:** {corrected_sentence}")