Rules99 commited on
Commit
983347e
·
1 Parent(s): 138a3ab

Upload app.py

Browse files
Files changed (1) hide show
  1. app.py +104 -101
app.py CHANGED
@@ -183,113 +183,116 @@ def error(option):
183
 
184
  ### If you insert an image
185
  if uploaded_file is not None:
186
- ## Controller header
187
-
188
- st.sidebar.markdown("<h1 style='text-align: center;'>Compound's filter</h1>",unsafe_allow_html=True)
189
- ## Write the compound
190
- st.sidebar.markdown('''
191
- <h4 style='text-align: center;'>This controller sidebar is used to filter the compounds by the following features</h4>
192
-
193
- - Molecular weight : is the weight of a compound in grame per mol
194
- - LogP : it measures how hydrophilic or hydrophobic a compound is
195
- - NumDonnors : number of chemical components that are able to deliver electrons to other chemical components
196
- - NumAcceptors : number of chemical components that are able to accept electrons to other chemical components
197
- ''',unsafe_allow_html=True)
198
- weight_cutoff = st.sidebar.slider(
199
- label="Molecular weight",
200
- min_value=0,
201
- max_value=1000,
202
- value=500,
203
- step=10,
204
- help="Look for compounds that have less or equal molecular weight than the value selected"
205
- )
206
- logp_cutoff = st.sidebar.slider(
207
- label="LogP",
208
- min_value=-10,
209
- max_value=10,
210
- value=5,
211
- step=1,
212
- help="Look for compounds that have less or equal logp than the value selected"
213
- )
214
- NumHDonors_cutoff = st.sidebar.slider(
215
- label="NumHDonors",
216
- min_value=0,
217
- max_value=15,
218
- value=5,
219
- step=1,
220
- help="Look for compounds that have less or equal donors weight than the value selected"
221
- )
222
- NumHAcceptors_cutoff = st.sidebar.slider(
223
- label="NumHAcceptors",
224
- min_value=0,
225
- max_value=20,
226
- value=10,
227
- step=1,
228
- help="Look for compounds that have less or equal acceptors weight than the value selected"
229
- )
230
- max_phase = st.sidebar.multiselect("Phase of the compound",
231
- ['1','2', '3', '4'],
232
- help="""
233
- - Phase 1 : Phase I of the compound in progress
234
- - Phase 2 : Phase II of the compound in progress
235
- - Phase 3 : Phase III of the compound in progress
236
- - Phase 4 : Approved compound
237
- """
238
- )
239
-
240
  #### Read an image
241
 
242
 
243
  imgdef = read_image(uploaded_file)
244
-
245
- ### Plot the input image
246
- fig, ax = plt.subplots()
247
- ax.imshow(imgdef,cmap="gray")
248
- st.pyplot(fig=fig)
249
- # Printing the possibility of having anomalies
250
- st.markdown("<h3 style='text-align: center;'>Possibility of anomalies</h3>",unsafe_allow_html=True)
251
- model = generatemodel(xrv.models.DenseNet,"densenet121-res224-mimic_ch") ### MIMIC MODEL+
252
- model.eval()
253
- pr = outputprob2(imgdef,model)
254
-
255
- # Sort results by the descending probability order
256
- pr = dict( sorted(pr.items(), key=operator.itemgetter(1),reverse=True))
257
- # Select the treatment
258
- option = st.sidebar.selectbox('Select the treatment you believe for these illness',list(pr.keys()))
259
- col1,col2,col3 = st.columns((1,1,1))
260
- cnt = 1
261
- for (key,value) in pr.items():
262
- if cnt%3==1:
263
- col1.metric(label=key, value=str(cnt), delta=str(value))
264
- if cnt%3==2:
265
- col2.metric(label=key, value=str(cnt), delta=str(value))
266
- if cnt%3==0:
267
- col3.metric(label=key, value=str(cnt), delta=str(value))
268
- cnt+=1
269
- # temp = st.expander("Compunds to take care of {}".format(key))
270
- #### Get the compounds for the anomaly selected
271
- df = getdrugs(option,max_phase)
272
- st.markdown("<h3 style='text-align: center;'>Compounds for {}</h3>".format(option),unsafe_allow_html=True)
273
- ### If exists the compounds
274
- if df is not None:
275
 
276
- #### Filter dataframe by controllers
277
- df_result = df[df["mol_weight"] < weight_cutoff]
278
- df_result2 = df_result[df_result["Logp"] < logp_cutoff]
279
- df_result3 = df_result2[df_result2["Donnors"] < NumHDonors_cutoff]
280
- df_result4 = df_result3[df_result3["Acceptors"] < NumHAcceptors_cutoff]
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
281
 
 
 
 
 
 
 
282
 
283
-
284
- if len(df_result4)==0:
285
-
286
- error(option)
287
- else:
288
- raw_html = mols2grid.display(df_result, mapping={"smiles": "SMILES","pref_name":"Name","Acceptors":"Acceptors","Donnors":"Donnors","Logp":"Logp","mol_weight":"mol_weight"},
289
- subset=["img","Name"],tooltip=["Name","Acceptors","Donnors","Logp","mol_weight"],tooltip_placement="top",tooltip_trigger="click hover")._repr_html_()
290
 
291
- components.html(raw_html, width=900, height=900, scrolling=True)
292
- #### We do not find compounds for the anomaly
293
- else:
294
- error(option)
 
 
 
 
 
 
 
295
 
 
183
 
184
  ### If you insert an image
185
  if uploaded_file is not None:
186
+
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
187
  #### Read an image
188
 
189
 
190
  imgdef = read_image(uploaded_file)
191
+ else:
192
+ imgdef = read_image("example.dcm")
193
+ ## Controller header
194
+
195
+ st.sidebar.markdown("<h1 style='text-align: center;'>Compound's filter</h1>",unsafe_allow_html=True)
196
+ ## Write the compound
197
+ st.sidebar.markdown('''
198
+ <h4 style='text-align: center;'>This controller sidebar is used to filter the compounds by the following features</h4>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
199
 
200
+ - Molecular weight : is the weight of a compound in grame per mol
201
+ - LogP : it measures how hydrophilic or hydrophobic a compound is
202
+ - NumDonnors : number of chemical components that are able to deliver electrons to other chemical components
203
+ - NumAcceptors : number of chemical components that are able to accept electrons to other chemical components
204
+ ''',unsafe_allow_html=True)
205
+ weight_cutoff = st.sidebar.slider(
206
+ label="Molecular weight",
207
+ min_value=0,
208
+ max_value=1000,
209
+ value=500,
210
+ step=10,
211
+ help="Look for compounds that have less or equal molecular weight than the value selected"
212
+ )
213
+ logp_cutoff = st.sidebar.slider(
214
+ label="LogP",
215
+ min_value=-10,
216
+ max_value=10,
217
+ value=5,
218
+ step=1,
219
+ help="Look for compounds that have less or equal logp than the value selected"
220
+ )
221
+ NumHDonors_cutoff = st.sidebar.slider(
222
+ label="NumHDonors",
223
+ min_value=0,
224
+ max_value=15,
225
+ value=5,
226
+ step=1,
227
+ help="Look for compounds that have less or equal donors weight than the value selected"
228
+ )
229
+ NumHAcceptors_cutoff = st.sidebar.slider(
230
+ label="NumHAcceptors",
231
+ min_value=0,
232
+ max_value=20,
233
+ value=10,
234
+ step=1,
235
+ help="Look for compounds that have less or equal acceptors weight than the value selected"
236
+ )
237
+ max_phase = st.sidebar.multiselect("Phase of the compound",
238
+ ['1','2', '3', '4'],
239
+ help="""
240
+ - Phase 1 : Phase I of the compound in progress
241
+ - Phase 2 : Phase II of the compound in progress
242
+ - Phase 3 : Phase III of the compound in progress
243
+ - Phase 4 : Approved compound
244
+ """
245
+ )
246
+
247
+
248
+ ### Plot the input image
249
+ fig, ax = plt.subplots()
250
+ ax.imshow(imgdef,cmap="gray")
251
+ st.pyplot(fig=fig)
252
+ # Printing the possibility of having anomalies
253
+ st.markdown("<h3 style='text-align: center;'>Possibility of anomalies</h3>",unsafe_allow_html=True)
254
+ model = generatemodel(xrv.models.DenseNet,"densenet121-res224-mimic_ch") ### MIMIC MODEL+
255
+ model.eval()
256
+ pr = outputprob2(imgdef,model)
257
+
258
+ # Sort results by the descending probability order
259
+ pr = dict( sorted(pr.items(), key=operator.itemgetter(1),reverse=True))
260
+ # Select the treatment
261
+ option = st.sidebar.selectbox('Anomaly',list(pr.keys()),help='Select the illness or anomaly you want to treat')
262
+ col1,col2,col3 = st.columns((1,1,1))
263
+ cnt = 1
264
+ for (key,value) in pr.items():
265
+ if cnt%3==1:
266
+ col1.metric(label=key, value=str(cnt), delta=str(value))
267
+ if cnt%3==2:
268
+ col2.metric(label=key, value=str(cnt), delta=str(value))
269
+ if cnt%3==0:
270
+ col3.metric(label=key, value=str(cnt), delta=str(value))
271
+ cnt+=1
272
+ # temp = st.expander("Compunds to take care of {}".format(key))
273
+ #### Get the compounds for the anomaly selected
274
+ df = getdrugs(option,max_phase)
275
+ st.markdown("<h3 style='text-align: center;'>Compounds for {}</h3>".format(option),unsafe_allow_html=True)
276
+ ### If exists the compounds
277
+ if df is not None:
278
 
279
+ #### Filter dataframe by controllers
280
+ df_result = df[df["mol_weight"] < weight_cutoff]
281
+ df_result2 = df_result[df_result["Logp"] < logp_cutoff]
282
+ df_result3 = df_result2[df_result2["Donnors"] < NumHDonors_cutoff]
283
+ df_result4 = df_result3[df_result3["Acceptors"] < NumHAcceptors_cutoff]
284
+
285
 
 
 
 
 
 
 
 
286
 
287
+ if len(df_result4)==0:
288
+
289
+ error(option)
290
+ else:
291
+ raw_html = mols2grid.display(df_result, mapping={"smiles": "SMILES","pref_name":"Name","Acceptors":"Acceptors","Donnors":"Donnors","Logp":"Logp","mol_weight":"mol_weight"},
292
+ subset=["img","Name"],tooltip=["Name","Acceptors","Donnors","Logp","mol_weight"],tooltip_placement="top",tooltip_trigger="click hover")._repr_html_()
293
+
294
+ components.html(raw_html, width=900, height=900, scrolling=True)
295
+ #### We do not find compounds for the anomaly
296
+ else:
297
+ error(option)
298