cahya commited on
Commit
634e006
β€’
1 Parent(s): d1cc6ee

Add model caching and bit code clean up

Browse files
Files changed (1) hide show
  1. app.py +22 -12
app.py CHANGED
@@ -2,35 +2,45 @@ import streamlit as st
2
  from happytransformer import HappyTextToText, TTSettings
3
 
4
  checkpoint = "team-writing-assistant/t5-base-c4jfleg"
5
- happy_tt = HappyTextToText("T5", checkpoint)
 
 
 
 
 
 
 
 
6
  args = TTSettings(num_beams=5, min_length=1)
7
 
8
  st.title("Check & Improve English Grammar")
9
  st.markdown("This writing assistant detects πŸ” and corrects ✍️ grammatical mistakes for you!")
10
 
11
  st.subheader("Example text: ")
12
- col1, col2 = st.columns([1,1])
13
  with col1:
14
- example_1 = st.button("Speed of light is fastest then speed of sound")
15
  with col2:
16
- example_2 = st.button("Who are the president?")
17
 
18
  input_text = st.text_area('Enter your text here')
19
  button = st.button('Submit')
20
 
 
21
  def output(input_text):
22
- with st.spinner('Detecting πŸ”..'):
23
- input_text = "grammar: " + input_text
24
- result = happy_tt.generate_text(input_text, args=args)
25
- st.markdown("## " + result.text)
 
26
 
27
  if example_1:
28
- output("Speed of light is fastest then speed of sound")
29
  if example_2:
30
- output("Who are the president?")
31
  if input_text:
32
- output(input_text)
33
 
34
  st.subheader("")
35
 
36
- st.text("Built by Team Writing Assistant ❀️")
 
2
  from happytransformer import HappyTextToText, TTSettings
3
 
4
  checkpoint = "team-writing-assistant/t5-base-c4jfleg"
5
+
6
+
7
+ @st.cache(suppress_st_warning=True, allow_output_mutation=True)
8
+ def get_happy_text(model_name):
9
+ st.write(f"Loading the HappyTextToText model {model_name}, please wait...")
10
+ return HappyTextToText("T5", model_name)
11
+
12
+
13
+ happy_tt = get_happy_text(checkpoint)
14
  args = TTSettings(num_beams=5, min_length=1)
15
 
16
  st.title("Check & Improve English Grammar")
17
  st.markdown("This writing assistant detects πŸ” and corrects ✍️ grammatical mistakes for you!")
18
 
19
  st.subheader("Example text: ")
20
+ col1, col2 = st.columns([1, 1])
21
  with col1:
22
+ example_1 = st.button("Speed of light is fastest then speed of sound")
23
  with col2:
24
+ example_2 = st.button("Who are the president?")
25
 
26
  input_text = st.text_area('Enter your text here')
27
  button = st.button('Submit')
28
 
29
+
30
  def output(input_text):
31
+ with st.spinner('Detecting πŸ”..'):
32
+ input_text = "grammar: " + input_text
33
+ result = happy_tt.generate_text(input_text, args=args)
34
+ st.markdown("## " + result.text)
35
+
36
 
37
  if example_1:
38
+ output("Speed of light is fastest then speed of sound")
39
  if example_2:
40
+ output("Who are the president?")
41
  if input_text:
42
+ output(input_text)
43
 
44
  st.subheader("")
45
 
46
+ st.text("Built by Team Writing Assistant ❀️")