Spaces:
Sleeping
Sleeping
paragon-analytics
commited on
Commit
•
ade4cec
1
Parent(s):
030a508
Update app.py
Browse files
app.py
CHANGED
@@ -1,6 +1,7 @@
|
|
1 |
# Import packages:
|
2 |
|
3 |
import numpy as np
|
|
|
4 |
import matplotlib.pyplot as plt
|
5 |
import re
|
6 |
# tensorflow imports:
|
@@ -61,6 +62,12 @@ def process_final_text(text):
|
|
61 |
scores = output[0][0].detach().numpy()
|
62 |
scores = tf.nn.softmax(scores)
|
63 |
|
|
|
|
|
|
|
|
|
|
|
|
|
64 |
# Get Keywords:
|
65 |
keywords = custom_kw_extractor.extract_keywords(X_test)
|
66 |
letter = []
|
@@ -89,7 +96,7 @@ def process_final_text(text):
|
|
89 |
+ sp_html
|
90 |
+ ""
|
91 |
)
|
92 |
-
return {"Resilience": float(scores.numpy()[1]), "Non-Resilience": float(scores.numpy()[0])},keywords,NER
|
93 |
|
94 |
def main(prob1):
|
95 |
text = str(prob1)
|
@@ -116,14 +123,15 @@ with gr.Blocks(title=title) as demo:
|
|
116 |
color_map={"+++": "royalblue","++": "cornflowerblue",
|
117 |
"+": "lightsteelblue", "NA":"white"})
|
118 |
NER = gr.HTML(label = 'NER:')
|
|
|
119 |
|
120 |
submit_btn.click(
|
121 |
main,
|
122 |
[prob1],
|
123 |
-
[label,impplot,NER], api_name="ResText"
|
124 |
)
|
125 |
|
126 |
gr.Markdown("### Click on any of the examples below to see to what extent they contain resilience messaging:")
|
127 |
-
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], main, cache_examples=True)
|
128 |
|
129 |
demo.launch()
|
|
|
1 |
# Import packages:
|
2 |
|
3 |
import numpy as np
|
4 |
+
import pandas as pd
|
5 |
import matplotlib.pyplot as plt
|
6 |
import re
|
7 |
# tensorflow imports:
|
|
|
62 |
scores = output[0][0].detach().numpy()
|
63 |
scores = tf.nn.softmax(scores)
|
64 |
|
65 |
+
# Transformer Interpret:
|
66 |
+
word_attributions = cls_explainer(X_test)
|
67 |
+
intp = pd.DataFrame(word_attributions)
|
68 |
+
intp.columns = ["Token",'Score']
|
69 |
+
intp_dict = intp.set_index('Token').T.to_dict('list')
|
70 |
+
|
71 |
# Get Keywords:
|
72 |
keywords = custom_kw_extractor.extract_keywords(X_test)
|
73 |
letter = []
|
|
|
96 |
+ sp_html
|
97 |
+ ""
|
98 |
)
|
99 |
+
return {"Resilience": float(scores.numpy()[1]), "Non-Resilience": float(scores.numpy()[0])},keywords,NER,intp_dict
|
100 |
|
101 |
def main(prob1):
|
102 |
text = str(prob1)
|
|
|
123 |
color_map={"+++": "royalblue","++": "cornflowerblue",
|
124 |
"+": "lightsteelblue", "NA":"white"})
|
125 |
NER = gr.HTML(label = 'NER:')
|
126 |
+
intp = gr.Label(label = "Word Scores:")
|
127 |
|
128 |
submit_btn.click(
|
129 |
main,
|
130 |
[prob1],
|
131 |
+
[label,impplot,NER,intp], api_name="ResText"
|
132 |
)
|
133 |
|
134 |
gr.Markdown("### Click on any of the examples below to see to what extent they contain resilience messaging:")
|
135 |
+
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)
|
136 |
|
137 |
demo.launch()
|