paragon-analytics commited on
Commit
bdbc076
·
1 Parent(s): 6fb5242

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +11 -28
app.py CHANGED
@@ -27,8 +27,8 @@ from transformers import AutoTokenizer, AutoModelForSeq2SeqLM
27
  tokenizer = AutoTokenizer.from_pretrained("paragon-analytics/bert_resil")
28
  model = AutoModelForSequenceClassification.from_pretrained("paragon-analytics/bert_resil")
29
 
30
- para_tokenizer = AutoTokenizer.from_pretrained("paragon-analytics/t5_para")
31
- para_model = AutoModelForSeq2SeqLM.from_pretrained("paragon-analytics/t5_para")
32
 
33
  kw_extractor = yake.KeywordExtractor()
34
  custom_kw_extractor = yake.KeywordExtractor(lan="en", n=2, dedupLim=0.2, top=10, features=None)
@@ -113,34 +113,17 @@ def process_final_text(text):
113
 
114
  word_attributions = [(letter[i], score[i]) for i in range(0, len(letter))]
115
 
116
- # Paraphraser:
117
- batch = para_tokenizer(X_test, return_tensors='pt')
118
- generated_ids = para_model.generate(batch['input_ids'])
119
- para_list = para_tokenizer.batch_decode(generated_ids, skip_special_tokens=True)
120
 
121
- # inp_text = "paraphrase: " + X_test + " </s>"
122
-
123
- # encoding = para_tokenizer.encode_plus(inp_text,pad_to_max_length=True, return_tensors="pt")
124
- # input_ids, attention_masks = encoding["input_ids"], encoding["attention_mask"]
125
-
126
- # outputs = para_model.generate(
127
- # input_ids=input_ids, attention_mask=attention_masks,
128
- # max_length=256,
129
- # do_sample=True,
130
- # top_k=120,
131
- # top_p=0.95,
132
- # early_stopping=True,
133
- # num_return_sequences=5
134
- # )
135
-
136
- # para_list = [tokenizer.decode(output, skip_special_tokens=True,clean_up_tokenization_spaces=True) for output in outputs]
137
-
138
- return {"Resilience": float(scores.numpy()[1]), "Non-Resilience": float(scores.numpy()[0])},keywords,NER,word_attributions,para_list
139
 
140
  def main(prob1):
141
  text = str(prob1)
142
  obj = process_final_text(text)
143
- return obj[0],obj[1],obj[2],obj[3],obj[4]
144
 
145
  title = "Welcome to **ResText** 🪐"
146
  description1 = """
@@ -166,15 +149,15 @@ with gr.Blocks(title=title) as demo:
166
  combine_adjacent=False).style(color_map={"++": "darkgreen","+": "green",
167
  "--": "darkred",
168
  "-": "red", "NA":"white"})
169
- paraph = gr.Textbox(label = "Paraphrased Sentences:")
170
 
171
  submit_btn.click(
172
  main,
173
  [prob1],
174
- [label,impplot,NER,intp,paraph], api_name="ResText"
175
  )
176
 
177
  gr.Markdown("### Click on any of the examples below to see to what extent they contain resilience messaging:")
178
- gr.Examples([["Please stay at home and avoid unnecessary trips."],["Please stay at home and avoid unnecessary trips. We will survive this."],["We will survive this."],["Watch today’s news briefing with the latest updates on COVID-19 in Connecticut."],["So let's keep doing what we know works. Let's stay strong, and let's beat this virus. I know we can, and I know we can come out stronger on the other side."],["It is really wonderful how much resilience there is in human nature. Let any obstructing cause, no matter what, be removed in any way, even by death, and we fly back to first principles of hope and enjoyment."],["Resilience is accepting your new reality, even if it’s less good than the one you had before. You can fight it, you can do nothing but scream about what you’ve lost, or you can accept that and try to put together something that’s good."],["You survived all of the days you thought you couldn't, never underestimate your resilience."],["Like tiny seeds with potent power to push through tough ground and become mighty trees, we hold innate reserves of unimaginable strength. We are resilient."]], [prob1], [label,impplot,NER,intp,paraph], main, cache_examples=True)
179
 
180
  demo.launch()
 
27
  tokenizer = AutoTokenizer.from_pretrained("paragon-analytics/bert_resil")
28
  model = AutoModelForSequenceClassification.from_pretrained("paragon-analytics/bert_resil")
29
 
30
+ # para_tokenizer = AutoTokenizer.from_pretrained("paragon-analytics/t5_para")
31
+ # para_model = AutoModelForSeq2SeqLM.from_pretrained("paragon-analytics/t5_para")
32
 
33
  kw_extractor = yake.KeywordExtractor()
34
  custom_kw_extractor = yake.KeywordExtractor(lan="en", n=2, dedupLim=0.2, top=10, features=None)
 
113
 
114
  word_attributions = [(letter[i], score[i]) for i in range(0, len(letter))]
115
 
116
+ # # Paraphraser:
117
+ # batch = para_tokenizer(X_test, return_tensors='pt')
118
+ # generated_ids = para_model.generate(batch['input_ids'])
119
+ # para_list = para_tokenizer.batch_decode(generated_ids, skip_special_tokens=True)
120
 
121
+ return {"Resilience": float(scores.numpy()[1]), "Non-Resilience": float(scores.numpy()[0])},keywords,NER,word_attributions
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
122
 
123
  def main(prob1):
124
  text = str(prob1)
125
  obj = process_final_text(text)
126
+ return obj[0],obj[1],obj[2],obj[3]
127
 
128
  title = "Welcome to **ResText** 🪐"
129
  description1 = """
 
149
  combine_adjacent=False).style(color_map={"++": "darkgreen","+": "green",
150
  "--": "darkred",
151
  "-": "red", "NA":"white"})
152
+ # paraph = gr.Textbox(label = "Paraphrased Sentences:")
153
 
154
  submit_btn.click(
155
  main,
156
  [prob1],
157
+ [label,impplot,NER,intp], api_name="ResText"
158
  )
159
 
160
  gr.Markdown("### Click on any of the examples below to see to what extent they contain resilience messaging:")
161
+ gr.Examples([["Please stay at home and avoid unnecessary trips."],["Please stay at home and avoid unnecessary trips. We will survive this."],["We will survive this."],["Watch today’s news briefing with the latest updates on COVID-19 in Connecticut."],["So let's keep doing what we know works. Let's stay strong, and let's beat this virus. I know we can, and I know we can come out stronger on the other side."],["It is really wonderful how much resilience there is in human nature. Let any obstructing cause, no matter what, be removed in any way, even by death, and we fly back to first principles of hope and enjoyment."],["Resilience is accepting your new reality, even if it’s less good than the one you had before. You can fight it, you can do nothing but scream about what you’ve lost, or you can accept that and try to put together something that’s good."],["You survived all of the days you thought you couldn't, never underestimate your resilience."],["Like tiny seeds with potent power to push through tough ground and become mighty trees, we hold innate reserves of unimaginable strength. We are resilient."]], [prob1], [label,impplot,NER,intp], main, cache_examples=True)
162
 
163
  demo.launch()