Spaces:
Sleeping
Sleeping
Initial commit
Browse files- InferenceServer.py +1 -8
- app.py +12 -21
- requirements.txt +13 -0
InferenceServer.py
CHANGED
@@ -9,16 +9,12 @@ import glob
|
|
9 |
import transformers
|
10 |
from transformers import AutoTokenizer
|
11 |
from transformers import AutoModelForSeq2SeqLM
|
12 |
-
import lm_scorer
|
13 |
-
from lm_scorer.models.auto import AutoLMScorer as LMScorer
|
14 |
|
15 |
|
16 |
print("Loading models...")
|
17 |
app = FastAPI()
|
18 |
|
19 |
device = "cpu"
|
20 |
-
batch_size = 1
|
21 |
-
scorer = LMScorer.from_pretrained("gpt2", device=device, batch_size=batch_size)
|
22 |
correction_model_tag = "prithivida/grammar_error_correcter_v2"
|
23 |
correction_tokenizer = AutoTokenizer.from_pretrained(correction_model_tag)
|
24 |
correction_model = AutoModelForSeq2SeqLM.from_pretrained(correction_model_tag)
|
@@ -61,8 +57,5 @@ def correct(input_sentence, max_candidates=1):
|
|
61 |
corrected.add(correction_tokenizer.decode(pred, skip_special_tokens=True).strip())
|
62 |
|
63 |
corrected = list(corrected)
|
64 |
-
|
65 |
-
ranked_corrected = [(c,s) for c, s in zip(corrected, scores)]
|
66 |
-
ranked_corrected.sort(key = lambda x:x[1], reverse=True)
|
67 |
-
return ranked_corrected
|
68 |
|
|
|
9 |
import transformers
|
10 |
from transformers import AutoTokenizer
|
11 |
from transformers import AutoModelForSeq2SeqLM
|
|
|
|
|
12 |
|
13 |
|
14 |
print("Loading models...")
|
15 |
app = FastAPI()
|
16 |
|
17 |
device = "cpu"
|
|
|
|
|
18 |
correction_model_tag = "prithivida/grammar_error_correcter_v2"
|
19 |
correction_tokenizer = AutoTokenizer.from_pretrained(correction_model_tag)
|
20 |
correction_model = AutoModelForSeq2SeqLM.from_pretrained(correction_model_tag)
|
|
|
57 |
corrected.add(correction_tokenizer.decode(pred, skip_special_tokens=True).strip())
|
58 |
|
59 |
corrected = list(corrected)
|
60 |
+
return corrected[0], 0 #Corrected Sentence, Dummy score
|
|
|
|
|
|
|
61 |
|
app.py
CHANGED
@@ -1,10 +1,19 @@
|
|
1 |
import streamlit as st
|
2 |
from multiprocessing import Process
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
3 |
import time
|
4 |
import os
|
5 |
|
6 |
def start_server():
|
7 |
-
os.system("cat custom_req.txt | xargs -n 1 -L 1 pip3 install -U")
|
8 |
os.system("uvicorn InferenceServer:app --port 8080 --host 0.0.0.0 --workers 1")
|
9 |
|
10 |
def load_models():
|
@@ -29,9 +38,6 @@ if 'models_loaded' not in st.session_state:
|
|
29 |
|
30 |
|
31 |
def show_highlights(input_text, corrected_sentence):
|
32 |
-
"""
|
33 |
-
To show highlights
|
34 |
-
"""
|
35 |
try:
|
36 |
strikeout = lambda x: '\u0336'.join(x) + '\u0336'
|
37 |
highlight_text = highlight(input_text, corrected_sentence)
|
@@ -59,9 +65,6 @@ def show_highlights(input_text, corrected_sentence):
|
|
59 |
st.stop()
|
60 |
|
61 |
def show_edits(input_text, corrected_sentence):
|
62 |
-
"""
|
63 |
-
To show edits
|
64 |
-
"""
|
65 |
try:
|
66 |
edits = get_edits(input_text, corrected_sentence)
|
67 |
df = pd.DataFrame(edits, columns=['type','original word', 'original start', 'original end', 'correct word', 'correct start', 'correct end'])
|
@@ -160,19 +163,7 @@ if __name__ == "__main__":
|
|
160 |
if not st.session_state['models_loaded']:
|
161 |
load_models()
|
162 |
|
163 |
-
|
164 |
-
from bs4 import BeautifulSoup
|
165 |
-
import pandas as pd
|
166 |
-
import torch
|
167 |
-
import math
|
168 |
-
import re
|
169 |
-
import json
|
170 |
-
import requests
|
171 |
-
import spacy
|
172 |
-
import errant
|
173 |
-
|
174 |
-
|
175 |
-
|
176 |
st.title('Gramformer')
|
177 |
st.subheader('A framework for correcting english grammatical errors')
|
178 |
st.markdown("Built for fun with π by a quintessential foodie - Prithivi Da, The maker of [WhatTheFood](https://huggingface.co/spaces/prithivida/WhatTheFood), [Styleformer](https://github.com/PrithivirajDamodaran/Styleformer) and [Parrot paraphraser](https://github.com/PrithivirajDamodaran/Parrot_Paraphraser) | βοΈ [@prithivida](https://twitter.com/prithivida) |[[GitHub]](https://github.com/PrithivirajDamodaran)", unsafe_allow_html=True)
|
@@ -200,7 +191,7 @@ if __name__ == "__main__":
|
|
200 |
)
|
201 |
st.write("(or)")
|
202 |
input_text = st.text_input(
|
203 |
-
label="
|
204 |
value=input_text
|
205 |
)
|
206 |
|
|
|
1 |
import streamlit as st
|
2 |
from multiprocessing import Process
|
3 |
+
from annotated_text import annotated_text
|
4 |
+
from bs4 import BeautifulSoup
|
5 |
+
import pandas as pd
|
6 |
+
import torch
|
7 |
+
import math
|
8 |
+
import re
|
9 |
+
import json
|
10 |
+
import requests
|
11 |
+
import spacy
|
12 |
+
import errant
|
13 |
import time
|
14 |
import os
|
15 |
|
16 |
def start_server():
|
|
|
17 |
os.system("uvicorn InferenceServer:app --port 8080 --host 0.0.0.0 --workers 1")
|
18 |
|
19 |
def load_models():
|
|
|
38 |
|
39 |
|
40 |
def show_highlights(input_text, corrected_sentence):
|
|
|
|
|
|
|
41 |
try:
|
42 |
strikeout = lambda x: '\u0336'.join(x) + '\u0336'
|
43 |
highlight_text = highlight(input_text, corrected_sentence)
|
|
|
65 |
st.stop()
|
66 |
|
67 |
def show_edits(input_text, corrected_sentence):
|
|
|
|
|
|
|
68 |
try:
|
69 |
edits = get_edits(input_text, corrected_sentence)
|
70 |
df = pd.DataFrame(edits, columns=['type','original word', 'original start', 'original end', 'correct word', 'correct start', 'correct end'])
|
|
|
163 |
if not st.session_state['models_loaded']:
|
164 |
load_models()
|
165 |
|
166 |
+
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
167 |
st.title('Gramformer')
|
168 |
st.subheader('A framework for correcting english grammatical errors')
|
169 |
st.markdown("Built for fun with π by a quintessential foodie - Prithivi Da, The maker of [WhatTheFood](https://huggingface.co/spaces/prithivida/WhatTheFood), [Styleformer](https://github.com/PrithivirajDamodaran/Styleformer) and [Parrot paraphraser](https://github.com/PrithivirajDamodaran/Parrot_Paraphraser) | βοΈ [@prithivida](https://twitter.com/prithivida) |[[GitHub]](https://github.com/PrithivirajDamodaran)", unsafe_allow_html=True)
|
|
|
191 |
)
|
192 |
st.write("(or)")
|
193 |
input_text = st.text_input(
|
194 |
+
label="Bring your own sentence",
|
195 |
value=input_text
|
196 |
)
|
197 |
|
requirements.txt
ADDED
@@ -0,0 +1,13 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
st-annotated-text
|
2 |
+
bs4
|
3 |
+
torch
|
4 |
+
fastapi
|
5 |
+
uvicorn
|
6 |
+
spacy==2.3.0
|
7 |
+
python-Levenshtein==0.12.2
|
8 |
+
errant==2.2.0
|
9 |
+
fsspec==2021.5.0
|
10 |
+
tokenizers
|
11 |
+
fuzzywuzzy==0.18.0
|
12 |
+
sentencepiece==0.1.95
|
13 |
+
transformers
|