sohomghosh commited on
Commit
11a27f6
1 Parent(s): 4855ea0

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +19 -11
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 lightgbm
6
- lr_clf_finbert = pickle.load(open("lr_clf_finread_new.pkl",'rb'))
7
- model_read = SentenceTransformer('ProsusAI/finbert')
 
 
 
 
 
 
 
 
 
8
 
9
  def get_readability(text):
10
- emd = model_read.encode([text])
11
- ans = 'not readable'
12
- if lr_clf_finbert.predict(emd)==1:
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 get_most_raedable_paraphrse(text):
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=get_most_raedable_paraphrse, inputs=text, outputs=output, api_name="get_most_raedable_paraphrse")
80
- example_text = gr.Dataset(components=[text], samples=[['Inflation is the rate of increase in prices over a given period of time. Inflation is typically a broad measure, such as the overall increase in prices or the increase in the cost of living in a country.'], ['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']])
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()