Spaces:
Sleeping
Sleeping
Eduard Kharakhashyan commited on
Commit ·
9caeaea
1
Parent(s): d29428e
init
Browse files
app.py
ADDED
|
@@ -0,0 +1,87 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import streamlit as st
|
| 2 |
+
|
| 3 |
+
ss = st.session_state
|
| 4 |
+
|
| 5 |
+
GC_NAMES = ['Hydrogen sulphide',
|
| 6 |
+
'Carbone dioxide', 'Nitrogen', 'Methane', 'Ethane', 'Propane', 'N-butane', 'Iso-butane', 'N-pentane',
|
| 7 |
+
'Iso-pentane', 'N-hexane',
|
| 8 |
+
'N-heptane', 'C7+', 'Hydrogen', 'Air', 'Water', 'Oxygen']
|
| 9 |
+
|
| 10 |
+
center_html = """
|
| 11 |
+
<div style='display: flex; flex-direction: column; justify-content: center;; height: 38px;'>
|
| 12 |
+
<span style='text-align: center; word-wrap: break-word;'>{}</span>
|
| 13 |
+
</div>
|
| 14 |
+
"""
|
| 15 |
+
|
| 16 |
+
sg_k = 'sg_value'
|
| 17 |
+
pc_k = 'p_crit_value'
|
| 18 |
+
tc_k = 't_crit_value'
|
| 19 |
+
gc_state_k = 'gc_state'
|
| 20 |
+
for key in [sg_k, pc_k, tc_k]:
|
| 21 |
+
if key not in ss:
|
| 22 |
+
ss[key] = 0
|
| 23 |
+
# Display the selected options
|
| 24 |
+
|
| 25 |
+
|
| 26 |
+
if st.button("Rerun"):
|
| 27 |
+
st.rerun()
|
| 28 |
+
|
| 29 |
+
if st.button("Calculate"):
|
| 30 |
+
ss[sg_k] = 30
|
| 31 |
+
# Force a rerun to update the display
|
| 32 |
+
# st.rerun()
|
| 33 |
+
|
| 34 |
+
UD = "User defined"
|
| 35 |
+
SG_LIST = [UD,
|
| 36 |
+
"Gas components",
|
| 37 |
+
"Condensate"]
|
| 38 |
+
SG_UD, SG_GC, SG_CON = SG_LIST
|
| 39 |
+
# Dropdown 1 with options A and B
|
| 40 |
+
sg_source = st.selectbox("sg source", SG_LIST)
|
| 41 |
+
|
| 42 |
+
if sg_source == UD:
|
| 43 |
+
user_input = st.text_input("sg", value=ss[sg_k], key="input_field")
|
| 44 |
+
ss[sg_k] = user_input
|
| 45 |
+
else:
|
| 46 |
+
st.text_input("sg", value=ss[sg_k], key="input_field", disabled=True, help="Calculated")
|
| 47 |
+
|
| 48 |
+
params = []
|
| 49 |
+
ss[gc_state_k] = UD
|
| 50 |
+
if sg_source != SG_GC:
|
| 51 |
+
cur_gc = GC_NAMES[:3]
|
| 52 |
+
else:
|
| 53 |
+
cur_gc = GC_NAMES
|
| 54 |
+
with st.expander("Gas components") as gc_exp:
|
| 55 |
+
for i in range(0, len(cur_gc), 3):
|
| 56 |
+
cols = st.columns(3)
|
| 57 |
+
j = i
|
| 58 |
+
for col in cols:
|
| 59 |
+
if j >= len(cur_gc):
|
| 60 |
+
break
|
| 61 |
+
gc11, gc12 = col.columns([1, 1.5])
|
| 62 |
+
gc11.markdown(center_html.format(cur_gc[j]), unsafe_allow_html=True)
|
| 63 |
+
params.append(gc12.text_input(cur_gc[j], value=0, label_visibility='collapsed'))
|
| 64 |
+
j += 1
|
| 65 |
+
|
| 66 |
+
|
| 67 |
+
CRIT_LIST = [UD]
|
| 68 |
+
CORRS = ["Sutton", "Standing wet gas", "standing natural gas"]
|
| 69 |
+
crit_options = [UD]
|
| 70 |
+
if sg_source == SG_GC:
|
| 71 |
+
crit_options.append("From gas components")
|
| 72 |
+
else:
|
| 73 |
+
for c in CORRS:
|
| 74 |
+
crit_options.append(c)
|
| 75 |
+
|
| 76 |
+
crit_params_source = st.selectbox("Critical params", crit_options)
|
| 77 |
+
|
| 78 |
+
# Create two columns for input fields
|
| 79 |
+
col1, col2 = st.columns(2)
|
| 80 |
+
|
| 81 |
+
if crit_params_source == UD:
|
| 82 |
+
dis = False
|
| 83 |
+
else:
|
| 84 |
+
dis = True
|
| 85 |
+
# Add input fields to the columns
|
| 86 |
+
param1 = col1.text_input('Pcrit', value=ss[tc_k], disabled=dis)
|
| 87 |
+
param2 = col2.text_input('Tcrit', value=ss[pc_k], disabled=dis)
|