dla9944 commited on
Commit
78b7f01
1 Parent(s): 2750a0e

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +48 -0
app.py ADDED
@@ -0,0 +1,48 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ import transformers
3
+ import tensorflow
4
+ import PIL
5
+ from PIL import Image
6
+ import time
7
+ from transformers import pipeline
8
+
9
+ model_checkpoint = "Modfiededition/t5-base-fine-tuned-on-jfleg"
10
+
11
+
12
+ @st.cache(allow_output_mutation=True, suppress_st_warning=True)
13
+ def load_model():
14
+ return pipeline("text2text-generation", model=model_checkpoint)
15
+ model = load_model()
16
+
17
+
18
+ #prompts
19
+ st.title("Writing Assistant for you 🤖")
20
+ st.markdown("This writing assistant detects and corrects grammatical mistakes for you! This assitant uses **T5-base model ✍️** fine-tuned on jfleg dataset.")
21
+ #image = Image.open('new_grammar.jpg')
22
+ #st.image(image, caption='Image Credit: https://abrc.org.au/wp-content/uploads/2020/12/Grammar-checker.jpg')
23
+ st.subheader("Some examples: ")
24
+ example_1 = st.button("I am write on AI")
25
+ example_2 = st.button("This sentence has, bads grammar mistake!")
26
+
27
+ textbox = st.text_area('Write your text in this box:', '',height=100, max_chars=500 )
28
+
29
+ button = st.button('Detect grammar mistakes:')
30
+
31
+ # output
32
+ st.subheader("Correct sentence: ")
33
+ if example_1:
34
+ with st.spinner('In progress.......'):
35
+ output_text = model("I am write on AI")[0]["generated_text"]
36
+ st.markdown("## "+output_text)
37
+
38
+ if example_2:
39
+ with st.spinner('In progress.......'):
40
+ output_text = model("This sentence has, bads grammar mistake!")[0]["generated_text"]
41
+ st.markdown("## "+output_text)
42
+ if button:
43
+ with st.spinner('In progress.......'):
44
+ if textbox:
45
+ output_text = model(textbox)[0]["generated_text"]
46
+ else:
47
+ output_text = " "
48
+ st.markdown("## "+output_text)