Spaces:
Runtime error
Runtime error
sohomghosh
commited on
Commit
•
11a27f6
1
Parent(s):
4855ea0
Update app.py
Browse files
app.py
CHANGED
@@ -1,17 +1,25 @@
|
|
1 |
import pickle
|
2 |
import gradio as gr
|
3 |
from transformers import AutoTokenizer, AutoModelForSeq2SeqLM
|
|
|
4 |
from sentence_transformers import SentenceTransformer
|
5 |
-
import
|
6 |
-
|
7 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
8 |
|
9 |
def get_readability(text):
|
10 |
-
|
11 |
-
|
12 |
-
|
13 |
-
ans = 'readable'
|
14 |
-
score = round(lr_clf_finbert.predict_proba(emd)[0,1],4)
|
15 |
return score
|
16 |
|
17 |
# Reference : https://huggingface.co/humarin/chatgpt_paraphraser_on_T5_base
|
@@ -47,7 +55,7 @@ def paraphrase(
|
|
47 |
|
48 |
return res
|
49 |
|
50 |
-
def
|
51 |
li_paraphrases = paraphrase(text)
|
52 |
li_paraphrases.append(text)
|
53 |
best = li_paraphrases[0]
|
@@ -76,8 +84,8 @@ with gr.Blocks() as demo:
|
|
76 |
text = gr.Textbox(label="Enter text you want to simply (make more readable)")
|
77 |
greet_btn = gr.Button("Simplify/Make Readable")
|
78 |
output = gr.Textbox(label="Output Box")
|
79 |
-
greet_btn.click(fn=
|
80 |
-
example_text = gr.Dataset(components=[text], samples=[['
|
81 |
example_text.click(fn=set_example_text, inputs=example_text,outputs=example_text.components)
|
82 |
|
83 |
demo.launch()
|
|
|
1 |
import pickle
|
2 |
import gradio as gr
|
3 |
from transformers import AutoTokenizer, AutoModelForSeq2SeqLM
|
4 |
+
from transformers import BertTokenizer, BertForSequenceClassification, pipeline, AutoTokenizer, AutoModelForSequenceClassification, TextClassificationPipeline, AutoModelForSeq2SeqLM, AutoModel, RobertaModel, RobertaTokenizer
|
5 |
from sentence_transformers import SentenceTransformer
|
6 |
+
from fin_readability_sustainability import BERTClass, do_predict
|
7 |
+
|
8 |
+
#import lightgbm
|
9 |
+
#lr_clf_finbert = pickle.load(open("lr_clf_finread_new.pkl",'rb'))
|
10 |
+
tokenizer_read = BertTokenizer.from_pretrained('ProsusAI/finbert')
|
11 |
+
|
12 |
+
|
13 |
+
|
14 |
+
model_read = BERTClass(2, "readability")
|
15 |
+
model_read.to(device)
|
16 |
+
model_read.load_state_dict(torch.load('readability_model.bin', map_location=device)['model_state_dict'])
|
17 |
+
|
18 |
|
19 |
def get_readability(text):
|
20 |
+
df = pd.DataFrame({'sentence':text})
|
21 |
+
actual_predictions_read = do_predict(model_read, tokenizer_read, df)
|
22 |
+
score = round(actual_predictions_read[1][0], 4)
|
|
|
|
|
23 |
return score
|
24 |
|
25 |
# Reference : https://huggingface.co/humarin/chatgpt_paraphraser_on_T5_base
|
|
|
55 |
|
56 |
return res
|
57 |
|
58 |
+
def get_most_readable_paraphrse(text):
|
59 |
li_paraphrases = paraphrase(text)
|
60 |
li_paraphrases.append(text)
|
61 |
best = li_paraphrases[0]
|
|
|
84 |
text = gr.Textbox(label="Enter text you want to simply (make more readable)")
|
85 |
greet_btn = gr.Button("Simplify/Make Readable")
|
86 |
output = gr.Textbox(label="Output Box")
|
87 |
+
greet_btn.click(fn=get_most_readable_paraphrse, inputs=text, outputs=output, api_name="get_most_raedable_paraphrse")
|
88 |
+
example_text = gr.Dataset(components=[text], samples=[['Legally assured line of credit with a bank'], ['A mutual fund is a type of financial vehicle made up of a pool of money collected from many investors to invest in securities like stocks, bonds, money market instruments']])
|
89 |
example_text.click(fn=set_example_text, inputs=example_text,outputs=example_text.components)
|
90 |
|
91 |
demo.launch()
|