-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBIMReTA_app.py
More file actions
79 lines (65 loc) · 3.77 KB
/
BIMReTA_app.py
File metadata and controls
79 lines (65 loc) · 3.77 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
# -*- coding: utf-8 -*-
""" It is a Streamlit web app for users.
Input: trained model, X_test[0] (from UI), build_feature.py, predict_model.py
Output: y_test[0]"""
import joblib
import pandas as pd
import numpy as np
import streamlit as st
model = joblib.load('models/model_BIMReTA.pkl')
def rank_response_technologies(dispersion, E_ss, E_sl, E_sw, sufficient_mixing_energy,
E_ssC, seawater, E_ssI, soot_pollution, displacement):
"""Ranking oil spill response technologies in Arctic
"""
X1 = pd.DataFrame(np.array([[dispersion, E_ss, E_sl, E_sw, sufficient_mixing_energy,
E_ssC, seawater, E_ssI, soot_pollution, displacement]]))
# 99, 1, 1, 1, 'no', 0, 'Small', 1, 0, 'yes'
X1.columns = ['evaporation_and_natural_disperson', 'E_ss', 'E_sl', 'E_sw', 'sufficient_mixing_energy',
'E_ssC', 'seawater', 'E_ssI', 'soot_pollution', 'displacement']
prediction = model.predict(X1).reshape(1, -1).flatten().tolist()
return prediction
def main():
html_temp = """<div style="background-color:tomato;padding:10px;height=20px">
<h3 style="color:white;text-align:center;">Ranking spill response technology: ML App </h3>
</div>"""
st.markdown(html_temp, unsafe_allow_html=True)
input_title = """<div style="background-color:gray;padding:0px">
<h4 style="color:white;text-align:center;">Input variables </h4>
</div>"""
st.markdown(input_title, unsafe_allow_html=True)
col1, col2, col3 = st.columns(3)
with col1:
dispersion = st.number_input("Dispersion in %", min_value=10, max_value=99) # a value of 10-99 unit?"
sufficient_mixing_energy = st.selectbox("Sufficient mixing energy", ("yes", "no"), index=1)
seawater = st.selectbox("Seawater volume", ("Small", "Large"))
soot_pollution = st.selectbox("Soot pollution", ("YES soot pollution", "NO soot pollution"))
with col2:
displacement = st.selectbox("Displacement", ("yes", "no"), index=1)
E_ss = st.radio("E_ss.mcr (Effect index of seasurface)", options=[-1, 0, 1], index=0)
E_sl = st.radio('E_sl.mcr', options=[-1, 0, 1], index=0)
with col3:
E_sw = st.radio("E_sw.mcr", options=[-1, 0, 1], index=0)
E_ssC = st.radio("E_ssC.cdu", options=[-1, 0, 1], index=1)
E_ssI = st.radio("E_ssI.isb", options=[-1, 0, 1], index=1)
output_title = """<div style="background-color:grey;padding:0px">
<h4 style="color:white;text-align:center;"> Result </h4>
</div>"""
st.markdown(output_title, unsafe_allow_html=True)
result = ""
if st.button("Rank Technology"):
result = rank_response_technologies(dispersion, E_ss, E_sl, E_sw, sufficient_mixing_energy,
E_ssC, seawater, E_ssI, soot_pollution, displacement)
result_df1 = pd.DataFrame(columns=["MCR", "CDU", "ISB"])
# result_df = pd.concat([result_df1, pd.DataFrame(result)], ignore_index=True, axis=0)
result_df1.loc[len(result_df1.index)] = result
result_df1.set_index([['Ranking'] * len(result_df1)],
inplace=True) # df.set_index([['A']*len(df)], inplace=True)
st.success(st.dataframe(result_df1)) # need to tab one level up?
paper_title = """<div style="background-color:None;padding:10px">
<p style="color:None;text-align:left;"> Reference: Das, T., & Goerlandt, F. (2022). Bayesian inference modeling to rank response technologies in arctic marine oil spills. "
"Marine Pollution Bulletin, 185, 114203 <a href="https://doi.org/10.1016/j.marpolbul.2022.114203"> (link) </a> </p>
</div>"""
st.markdown(paper_title, unsafe_allow_html=True)
# Motivated from https://github.com/krishnaik06/Dockers/blob/master/app.py
if __name__ == '__main__':
main()