Chan Lee commited on
Commit
f56bb9a
1 Parent(s): fb5aa1c
Files changed (1) hide show
  1. app.py +158 -35
app.py CHANGED
@@ -56,29 +56,152 @@ other_examples = [
56
  other_title = "Other Health Related Task"
57
  other_desc = "Enter drug-related tweets to generate labels from 3 models (BERT, MentalBERT, PHS-BERT). Label 0='no adverse drug reaction', 1='adverse drug reaction'. The three provided examples have true labels 0,0,1 respectively. For more details, please refer to the SMM4H T1 dataset description in our paper (link provided in the corresponding Hugging Face repository)."
58
 
59
- def make_interfaces(folder):
60
- predictor_bert = ktrain.load_predictor(folder + "bert")
61
- predictor_mental = ktrain.load_predictor(folder + "mentalbert")
62
- predictor_phs = ktrain.load_predictor(folder + "phsbert")
63
-
64
- def BERT(text):
65
- results = predictor_bert.predict(str(text))
66
- return "BERT:" + str(results)
67
 
68
- def MentalBERT(text):
69
- results = predictor_mental.predict(str(text))
70
- return "MentalBERT:" + str(results)
71
 
72
- def PHSBERT(text):
73
- results = predictor_phs.predict(str(text))
74
- return "PHS-BERT:" + str(results)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
75
 
76
- bert_io = Interface(fn=BERT, inputs="text", outputs="text")
77
- mental_io = Interface(fn=MentalBERT, inputs="text", outputs="text")
78
- phs_io = Interface(fn=PHSBERT, inputs="text", outputs="text")
 
79
 
80
- return bert_io, mental_io, phs_io
 
 
81
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
82
  # vs_bert_io, vs_mental_io, vs_phs_io = make_interfaces("vs/")
83
  # vs = Parallel(vs_bert_io, vs_mental_io, vs_phs_io,
84
  # examples=vs_examples,
@@ -97,11 +220,11 @@ def make_interfaces(folder):
97
  # title=dep_title,
98
  # description=dep_desc)
99
 
100
- covid_bert_io, covid_mental_io, covid_phs_io = make_interfaces("cv/")
101
- covid = Parallel(covid_bert_io, covid_mental_io, covid_phs_io,
102
- examples=covid_examples,
103
- title=covid_title,
104
- description=covid_desc)
105
 
106
  # suicide_bert_io, suicide_mental_io, suicide_phs_io = make_interfaces("sc/")
107
  # suicide = Parallel(suicide_bert_io, suicide_mental_io, suicide_phs_io,
@@ -109,11 +232,11 @@ covid = Parallel(covid_bert_io, covid_mental_io, covid_phs_io,
109
  # title=suicide_title,
110
  # description=suicide_desc)
111
 
112
- stress_bert_io, stress_mental_io, stress_phs_io = make_interfaces("st/")
113
- stress = Parallel(stress_bert_io, stress_mental_io, stress_phs_io,
114
- examples=stress_examples,
115
- title=stress_title,
116
- description=stress_desc)
117
 
118
  # other_bert_io, other_mental_io, other_phs_io = make_interfaces("ot/")
119
  # other = Parallel(other_bert_io, other_mental_io, other_phs_io,
@@ -121,10 +244,10 @@ stress = Parallel(stress_bert_io, stress_mental_io, stress_phs_io,
121
  # title=other_title,
122
  # description=other_desc)
123
 
124
- desc = "Task is currently unavailable."
125
 
126
- def model(text):
127
- return "Predictions are currently unavailable."
128
 
129
  # dep = Interface(fn=model, inputs="text", outputs="text", title=dep_title, description=desc)
130
  # covid = Interface(fn=model, inputs="text", outputs="text", title=covid_title, description=desc)
@@ -135,10 +258,10 @@ def model(text):
135
  # interfaces = [vs, hm, dep, covid, suicide, stress, other]
136
  # interface_names = [vs_title, hm_title, dep_title, covid_title, suicide_title, stress_title, other_title]
137
 
138
- # interfaces = [vs, hm, covid, stress, other]
139
- # interface_names = [vs_title, hm_title, covid_title, stress_title, other_title]
140
 
141
- interfaces = [covid, stress]
142
- interface_names = [covid_title, stress_title]
143
 
144
  TabbedInterface(interfaces, interface_names).launch()
 
56
  other_title = "Other Health Related Task"
57
  other_desc = "Enter drug-related tweets to generate labels from 3 models (BERT, MentalBERT, PHS-BERT). Label 0='no adverse drug reaction', 1='adverse drug reaction'. The three provided examples have true labels 0,0,1 respectively. For more details, please refer to the SMM4H T1 dataset description in our paper (link provided in the corresponding Hugging Face repository)."
58
 
59
+ # def make_interfaces(folder):
60
+ # predictor_bert = ktrain.load_predictor(folder + "bert")
61
+ # predictor_mental = ktrain.load_predictor(folder + "mentalbert")
62
+ # predictor_phs = ktrain.load_predictor(folder + "phsbert")
63
+
64
+ # def BERT(text):
65
+ # results = predictor_bert.predict(str(text))
66
+ # return "BERT:" + str(results)
67
 
68
+ # def MentalBERT(text):
69
+ # results = predictor_mental.predict(str(text))
70
+ # return "MentalBERT:" + str(results)
71
 
72
+ # def PHSBERT(text):
73
+ # results = predictor_phs.predict(str(text))
74
+ # return "PHS-BERT:" + str(results)
75
+
76
+ # bert_io = Interface(fn=BERT, inputs="text", outputs="text")
77
+ # mental_io = Interface(fn=MentalBERT, inputs="text", outputs="text")
78
+ # phs_io = Interface(fn=PHSBERT, inputs="text", outputs="text")
79
+
80
+ # return bert_io, mental_io, phs_io
81
+ folder = "vs/"
82
+ vs_predictor_bert = ktrain.load_predictor(folder + "bert")
83
+ vs_predictor_mental = ktrain.load_predictor(folder + "mentalbert")
84
+ vs_predictor_phs = ktrain.load_predictor(folder + "phsbert")
85
+
86
+ def vs_BERT(text):
87
+ results = vs_predictor_bert.predict(str(text))
88
+ return "BERT:" + str(results)
89
+
90
+ def vs_MentalBERT(text):
91
+ results = vs_predictor_mental.predict(str(text))
92
+ return "MentalBERT:" + str(results)
93
+
94
+ def vs_PHSBERT(text):
95
+ results = vs_predictor_phs.predict(str(text))
96
+ return "PHS-BERT:" + str(results)
97
+
98
+ vs_bert_io = Interface(fn=vs_BERT, inputs="text", outputs="text")
99
+ vs_mental_io = Interface(fn=vs_MentalBERT, inputs="text", outputs="text")
100
+ vs_phs_io = Interface(fn=vs_PHSBERT, inputs="text", outputs="text")
101
+ vs = Parallel(vs_bert_io, vs_mental_io, vs_phs_io,
102
+ examples=vs_examples,
103
+ title=vs_title,
104
+ description=vs_desc)
105
+
106
+ folder = "hm/"
107
+ hm_predictor_bert = ktrain.load_predictor(folder + "bert")
108
+ hm_predictor_mental = ktrain.load_predictor(folder + "mentalbert")
109
+ hm_predictor_phs = ktrain.load_predictor(folder + "phsbert")
110
+
111
+ def hm_BERT(text):
112
+ results = hm_predictor_bert.predict(str(text))
113
+ return "BERT:" + str(results)
114
+
115
+ def hm_MentalBERT(text):
116
+ results = hm_predictor_mental.predict(str(text))
117
+ return "MentalBERT:" + str(results)
118
+
119
+ def hm_PHSBERT(text):
120
+ results = hm_predictor_phs.predict(str(text))
121
+ return "PHS-BERT:" + str(results)
122
+
123
+ hm_bert_io = Interface(fn=hm_BERT, inputs="text", outputs="text")
124
+ hm_mental_io = Interface(fn=hm_MentalBERT, inputs="text", outputs="text")
125
+ hm_phs_io = Interface(fn=hm_PHSBERT, inputs="text", outputs="text")
126
+ hm = Parallel(hm_bert_io, hm_mental_io, hm_phs_io,
127
+ examples=hm_examples,
128
+ title=hm_title,
129
+ description=hm_desc)
130
+
131
+ folder = "cv/"
132
+ covid_predictor_bert = ktrain.load_predictor(folder + "bert")
133
+ covid_predictor_mental = ktrain.load_predictor(folder + "mentalbert")
134
+ covid_predictor_phs = ktrain.load_predictor(folder + "phsbert")
135
+
136
+ def covid_BERT(text):
137
+ results = covid_predictor_bert.predict(str(text))
138
+ return "BERT:" + str(results)
139
+
140
+ def covid_MentalBERT(text):
141
+ results = covid_predictor_mental.predict(str(text))
142
+ return "MentalBERT:" + str(results)
143
+
144
+ def covid_PHSBERT(text):
145
+ results = covid_predictor_phs.predict(str(text))
146
+ return "PHS-BERT:" + str(results)
147
+
148
+ covid_bert_io = Interface(fn=covid_BERT, inputs="text", outputs="text")
149
+ covid_mental_io = Interface(fn=covid_MentalBERT, inputs="text", outputs="text")
150
+ covid_phs_io = Interface(fn=covid_PHSBERT, inputs="text", outputs="text")
151
+ covid = Parallel(covid_bert_io, covid_mental_io, covid_phs_io,
152
+ examples=covid_examples,
153
+ title=covid_title,
154
+ description=covid_desc)
155
+
156
+ folder = "st/"
157
+ stress_predictor_bert = ktrain.load_predictor(folder + "bert")
158
+ stress_predictor_mental = ktrain.load_predictor(folder + "mentalbert")
159
+ stress_predictor_phs = ktrain.load_predictor(folder + "phsbert")
160
+
161
+ def stress_BERT(text):
162
+ results = stress_predictor_bert.predict(str(text))
163
+ return "BERT:" + str(results)
164
+
165
+ def stress_MentalBERT(text):
166
+ results = stress_predictor_mental.predict(str(text))
167
+ return "MentalBERT:" + str(results)
168
+
169
+ def stress_PHSBERT(text):
170
+ results = stress_predictor_phs.predict(str(text))
171
+ return "PHS-BERT:" + str(results)
172
+
173
+ stress_bert_io = Interface(fn=stress_BERT, inputs="text", outputs="text")
174
+ stress_mental_io = Interface(fn=stress_MentalBERT, inputs="text", outputs="text")
175
+ stress_phs_io = Interface(fn=stress_PHSBERT, inputs="text", outputs="text")
176
+ stress = Parallel(stress_bert_io, stress_mental_io, stress_phs_io,
177
+ examples=stress_examples,
178
+ title=stress_title,
179
+ description=stress_desc)
180
 
181
+ folder = "ot/"
182
+ other_predictor_bert = ktrain.load_predictor(folder + "bert")
183
+ other_predictor_mental = ktrain.load_predictor(folder + "mentalbert")
184
+ other_predictor_phs = ktrain.load_predictor(folder + "phsbert")
185
 
186
+ def other_BERT(text):
187
+ results = other_predictor_bert.predict(str(text))
188
+ return "BERT:" + str(results)
189
 
190
+ def other_MentalBERT(text):
191
+ results = other_predictor_mental.predict(str(text))
192
+ return "MentalBERT:" + str(results)
193
+
194
+ def other_PHSBERT(text):
195
+ results = other_predictor_phs.predict(str(text))
196
+ return "PHS-BERT:" + str(results)
197
+
198
+ other_bert_io = Interface(fn=other_BERT, inputs="text", outputs="text")
199
+ other_mental_io = Interface(fn=other_MentalBERT, inputs="text", outputs="text")
200
+ other_phs_io = Interface(fn=other_PHSBERT, inputs="text", outputs="text")
201
+ other = Parallel(other_bert_io, other_mental_io, other_phs_io,
202
+ examples=other_examples,
203
+ title=other_title,
204
+ description=other_desc)
205
  # vs_bert_io, vs_mental_io, vs_phs_io = make_interfaces("vs/")
206
  # vs = Parallel(vs_bert_io, vs_mental_io, vs_phs_io,
207
  # examples=vs_examples,
 
220
  # title=dep_title,
221
  # description=dep_desc)
222
 
223
+ # covid_bert_io, covid_mental_io, covid_phs_io = make_interfaces("cv/")
224
+ # covid = Parallel(covid_bert_io, covid_mental_io, covid_phs_io,
225
+ # examples=covid_examples,
226
+ # title=covid_title,
227
+ # description=covid_desc)
228
 
229
  # suicide_bert_io, suicide_mental_io, suicide_phs_io = make_interfaces("sc/")
230
  # suicide = Parallel(suicide_bert_io, suicide_mental_io, suicide_phs_io,
 
232
  # title=suicide_title,
233
  # description=suicide_desc)
234
 
235
+ # stress_bert_io, stress_mental_io, stress_phs_io = make_interfaces("st/")
236
+ # stress = Parallel(stress_bert_io, stress_mental_io, stress_phs_io,
237
+ # examples=stress_examples,
238
+ # title=stress_title,
239
+ # description=stress_desc)
240
 
241
  # other_bert_io, other_mental_io, other_phs_io = make_interfaces("ot/")
242
  # other = Parallel(other_bert_io, other_mental_io, other_phs_io,
 
244
  # title=other_title,
245
  # description=other_desc)
246
 
247
+ # desc = "Task is currently unavailable."
248
 
249
+ # def model(text):
250
+ # return "Predictions are currently unavailable."
251
 
252
  # dep = Interface(fn=model, inputs="text", outputs="text", title=dep_title, description=desc)
253
  # covid = Interface(fn=model, inputs="text", outputs="text", title=covid_title, description=desc)
 
258
  # interfaces = [vs, hm, dep, covid, suicide, stress, other]
259
  # interface_names = [vs_title, hm_title, dep_title, covid_title, suicide_title, stress_title, other_title]
260
 
261
+ interfaces = [vs, hm, covid, stress, other]
262
+ interface_names = [vs_title, hm_title, covid_title, stress_title, other_title]
263
 
264
+ # interfaces = [covid, stress]
265
+ # interface_names = [covid_title, stress_title]
266
 
267
  TabbedInterface(interfaces, interface_names).launch()