Spaces:
Running
Running
change name for streamlit_app.py
Browse files- app.py +34 -17
- app_flask.py +25 -0
- streamlit_app.py +0 -42
app.py
CHANGED
@@ -1,25 +1,42 @@
|
|
1 |
-
import
|
2 |
-
from
|
3 |
-
import pickle
|
4 |
|
5 |
-
|
6 |
|
7 |
-
|
8 |
|
9 |
-
@
|
10 |
-
def
|
11 |
-
return
|
12 |
|
13 |
-
|
14 |
-
|
15 |
|
16 |
-
|
17 |
-
|
|
|
|
|
|
|
18 |
|
19 |
-
|
20 |
-
output = model.generate_text(int_features, args=beam_settings)
|
21 |
|
22 |
-
|
|
|
|
|
|
|
|
|
|
|
23 |
|
24 |
-
|
25 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import streamlit as st
|
2 |
+
from happytransformer import HappyTextToText, TTSettings
|
|
|
3 |
|
4 |
+
st.set_page_config(page_title="Grammar Correction Tool", layout="centered")
|
5 |
|
6 |
+
checkpoint = "team-writing-assistant/t5-base-c4jfleg"
|
7 |
|
8 |
+
@st.cache_resource
|
9 |
+
def get_happy_text(model_name):
|
10 |
+
return HappyTextToText("T5", model_name)
|
11 |
|
12 |
+
happy_tt = get_happy_text(checkpoint)
|
13 |
+
args = TTSettings(num_beams=5, min_length=1)
|
14 |
|
15 |
+
st.title(" NLP - Grammar Correction Tool")
|
16 |
+
st.subheader("Software - Group 2")
|
17 |
+
st.markdown("""
|
18 |
+
Simply enter your text below or use one of the example sentences to get started!
|
19 |
+
""")
|
20 |
|
21 |
+
col1, col2 = st.columns(2)
|
|
|
22 |
|
23 |
+
with col1:
|
24 |
+
if st.button("Example 1: Incorrect Grammar"):
|
25 |
+
st.session_state.input_text = "Speed of light is fastest then speed of sound"
|
26 |
+
with col2:
|
27 |
+
if st.button("Example 2: Common Mistake"):
|
28 |
+
st.session_state.input_text = "Who are the president?"
|
29 |
|
30 |
+
input_text = st.text_area("Enter your text here:", st.session_state.get("input_text", ""))
|
31 |
+
|
32 |
+
if st.button("Correct Grammar"):
|
33 |
+
if input_text.strip():
|
34 |
+
with st.spinner("Correcting grammar..."):
|
35 |
+
formatted_input = "grammar: " + input_text
|
36 |
+
result = happy_tt.generate_text(formatted_input, args=args)
|
37 |
+
st.markdown("### Corrected Text:")
|
38 |
+
st.write(result.text.strip())
|
39 |
+
else:
|
40 |
+
st.warning("Please enter text to correct.")
|
41 |
+
|
42 |
+
st.markdown("---")
|
app_flask.py
ADDED
@@ -0,0 +1,25 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import numpy as np
|
2 |
+
from flask import Flask, request, jsonify, render_template
|
3 |
+
import pickle
|
4 |
+
|
5 |
+
from happytransformer import TTSettings
|
6 |
+
|
7 |
+
app = Flask(__name__)
|
8 |
+
|
9 |
+
@app.route('/')
|
10 |
+
def home():
|
11 |
+
return render_template('index.html')
|
12 |
+
|
13 |
+
@app.route('/predict',methods=['POST'])
|
14 |
+
def predict():
|
15 |
+
|
16 |
+
int_features = str(request.form['Input_text'])
|
17 |
+
beam_settings = TTSettings(num_beams=5, min_length=1, max_length=20)
|
18 |
+
|
19 |
+
model = pickle.load(open('model.pkl', 'rb'))
|
20 |
+
output = model.generate_text(int_features, args=beam_settings)
|
21 |
+
|
22 |
+
return render_template('index.html', prediction_text='{}'.format(output.text))
|
23 |
+
|
24 |
+
if __name__ == "__main__":
|
25 |
+
app.run(host='0.0.0.0', debug=True)
|
streamlit_app.py
DELETED
@@ -1,42 +0,0 @@
|
|
1 |
-
import streamlit as st
|
2 |
-
from happytransformer import HappyTextToText, TTSettings
|
3 |
-
|
4 |
-
st.set_page_config(page_title="Grammar Correction Tool", layout="centered")
|
5 |
-
|
6 |
-
checkpoint = "team-writing-assistant/t5-base-c4jfleg"
|
7 |
-
|
8 |
-
@st.cache_resource
|
9 |
-
def get_happy_text(model_name):
|
10 |
-
return HappyTextToText("T5", model_name)
|
11 |
-
|
12 |
-
happy_tt = get_happy_text(checkpoint)
|
13 |
-
args = TTSettings(num_beams=5, min_length=1)
|
14 |
-
|
15 |
-
st.title(" NLP - Grammar Correction Tool")
|
16 |
-
st.subheader("Software - Group 2")
|
17 |
-
st.markdown("""
|
18 |
-
Simply enter your text below or use one of the example sentences to get started!
|
19 |
-
""")
|
20 |
-
|
21 |
-
col1, col2 = st.columns(2)
|
22 |
-
|
23 |
-
with col1:
|
24 |
-
if st.button("Example 1: Incorrect Grammar"):
|
25 |
-
st.session_state.input_text = "Speed of light is fastest then speed of sound"
|
26 |
-
with col2:
|
27 |
-
if st.button("Example 2: Common Mistake"):
|
28 |
-
st.session_state.input_text = "Who are the president?"
|
29 |
-
|
30 |
-
input_text = st.text_area("Enter your text here:", st.session_state.get("input_text", ""))
|
31 |
-
|
32 |
-
if st.button("Correct Grammar"):
|
33 |
-
if input_text.strip():
|
34 |
-
with st.spinner("Correcting grammar..."):
|
35 |
-
formatted_input = "grammar: " + input_text
|
36 |
-
result = happy_tt.generate_text(formatted_input, args=args)
|
37 |
-
st.markdown("### Corrected Text:")
|
38 |
-
st.write(result.text.strip())
|
39 |
-
else:
|
40 |
-
st.warning("Please enter text to correct.")
|
41 |
-
|
42 |
-
st.markdown("---")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|