paragon-analytics commited on
Commit
868eab7
1 Parent(s): 4260f66

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +23 -5
app.py CHANGED
@@ -93,11 +93,26 @@ def process_final_text(text):
93
 
94
  # Transformer Interpret:
95
  word_attributions = cls_explainer(X_test)
96
- intp = pd.DataFrame(word_attributions)
97
- intp.columns = ["Token",'Score']
98
- intp_dict = intp.set_index('Token').T.to_dict('list')
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
99
 
100
- return {"Resilience": float(scores.numpy()[1]), "Non-Resilience": float(scores.numpy()[0])},keywords,NER,intp_dict
101
 
102
  def main(prob1):
103
  text = str(prob1)
@@ -124,7 +139,10 @@ with gr.Blocks(title=title) as demo:
124
  color_map={"+++": "royalblue","++": "cornflowerblue",
125
  "+": "lightsteelblue", "NA":"white"})
126
  NER = gr.HTML(label = 'NER:')
127
- intp = gr.Label(label = "Word Scores:")
 
 
 
128
 
129
  submit_btn.click(
130
  main,
 
93
 
94
  # Transformer Interpret:
95
  word_attributions = cls_explainer(X_test)
96
+ letter = []
97
+ score = []
98
+ for i in word_attributions:
99
+ if i[1]>0.5:
100
+ a = "++"
101
+ elif (i[1]<=0.5) and (i[1]>0.1):
102
+ a = "+"
103
+ elif (i[1]>=-0.5) and (i[1]<-0.1):
104
+ a = "-"
105
+ elif i[1]<-0.5:
106
+ a = "--"
107
+ else:
108
+ a = "NA"
109
+
110
+ letter.append(i[0])
111
+ score.append(a)
112
+
113
+ word_attributions = [(letter[i], score[i]) for i in range(0, len(letter))]
114
 
115
+ return {"Resilience": float(scores.numpy()[1]), "Non-Resilience": float(scores.numpy()[0])},keywords,NER,word_attributions
116
 
117
  def main(prob1):
118
  text = str(prob1)
 
139
  color_map={"+++": "royalblue","++": "cornflowerblue",
140
  "+": "lightsteelblue", "NA":"white"})
141
  NER = gr.HTML(label = 'NER:')
142
+ intp =gr.HighlightedText(label="Word Scores",
143
+ combine_adjacent=False).style(color_map={"++": "darkgreen","+": "green",
144
+ "--": "darkred",
145
+ "-": "red", "NA":"white"})
146
 
147
  submit_btn.click(
148
  main,