playground / app.py
BulatF's picture
Update app.py
df39da2
raw
history blame
No virus
3.1 kB
import streamlit as st
# Set Streamlit configuration to use the dark theme
def set_theme():
# Create a custom dark theme using Streamlit's theming API
# Adjust the color values according to your preference
primaryColor = "#E694FF"
backgroundColor = "#00172B"
secondaryBackgroundColor = "#0083B8"
textColor = "#FFFFFF"
font = "sans serif"
# Apply the theme settings
st.set_page_config(
theme={
'primaryColor': primaryColor,
'backgroundColor': backgroundColor,
'secondaryBackgroundColor': secondaryBackgroundColor,
'textColor': textColor,
'font': font
}
)
# Call the function to set the theme
set_theme()
ss = st.session_state
GC_NAMES = ['Hydrogen sulphide',
'Carbone dioxide', 'Nitrogen', 'Methane', 'Ethane', 'Propane', 'N-butane', 'Iso-butane', 'N-pentane',
'Iso-pentane', 'N-hexane',
'N-heptane', 'C7+', 'Hydrogen', 'Air', 'Water', 'Oxygen']
center_html = """
<div style='display: flex; flex-direction: column; justify-content: center;; height: 38px;'>
<span style='text-align: center; word-wrap: break-word;'>{}</span>
</div>
"""
sg_k = 'sg_value'
pc_k = 'p_crit_value'
tc_k = 't_crit_value'
gc_state_k = 'gc_state'
for key in [sg_k, pc_k, tc_k]:
if key not in ss:
ss[key] = 0
# Display the selected options
if st.button("Rerun"):
st.rerun()
if st.button("Calculate"):
ss[sg_k] = 30
# Force a rerun to update the display
# st.rerun()
UD = "User defined"
SG_LIST = [UD,
"Gas components",
"Condensate"]
SG_UD, SG_GC, SG_CON = SG_LIST
# Dropdown 1 with options A and B
sg_source = st.selectbox("sg source", SG_LIST)
if sg_source == UD:
user_input = st.text_input("sg", value=ss[sg_k], key="input_field")
ss[sg_k] = user_input
else:
st.text_input("sg", value=ss[sg_k], key="input_field", disabled=True, help="Calculated")
params = []
ss[gc_state_k] = UD
if sg_source != SG_GC:
cur_gc = GC_NAMES[:3]
else:
cur_gc = GC_NAMES
with st.expander("Gas components") as gc_exp:
for i in range(0, len(cur_gc), 3):
cols = st.columns(3)
j = i
for col in cols:
if j >= len(cur_gc):
break
gc11, gc12 = col.columns([1, 1.5])
gc11.markdown(center_html.format(cur_gc[j]), unsafe_allow_html=True)
params.append(gc12.text_input(cur_gc[j], value=0, label_visibility='collapsed'))
j += 1
CRIT_LIST = [UD]
CORRS = ["Sutton", "Standing wet gas", "standing natural gas"]
crit_options = [UD]
if sg_source == SG_GC:
crit_options.append("From gas components")
else:
for c in CORRS:
crit_options.append(c)
crit_params_source = st.selectbox("Critical params", crit_options)
# Create two columns for input fields
col1, col2 = st.columns(2)
if crit_params_source == UD:
dis = False
else:
dis = True
# Add input fields to the columns
param1 = col1.text_input('Pcrit', value=ss[tc_k], disabled=dis)
param2 = col2.text_input('Tcrit', value=ss[pc_k], disabled=dis)