Rimjhim Mittal commited on
Commit
8777e24
·
1 Parent(s): b95e413

multiple textbox in one row

Browse files
Files changed (1) hide show
  1. app.py +51 -38
app.py CHANGED
@@ -8,12 +8,7 @@ st.set_page_config(layout="wide", page_icon="logo.png", page_title="Model Descri
8
  'Report a bug': "https://github.com/ModECI/MDF/",
9
  'About': "ModECI (Model Exchange and Convergence Initiative) is a multi-investigator collaboration that aims to develop a standardized format for exchanging computational models across diverse software platforms and domains of scientific research and technology development, with a particular focus on neuroscience, Machine Learning and Artificial Intelligence. Refer to https://modeci.org/ for more."
10
  })
11
- header1, header2 = st.columns([1,12], vertical_alignment="top")
12
- with header1:
13
- st.image("logo.png", width=100)
14
- with header2:
15
- st.title("Welcome to Model Description Format")
16
- st.write("Lets get started! Choose one of the following methods.")
17
  # models: Purpose: To store the state of the model and update the model
18
  def run_simulation(param_inputs, mdf_model):
19
  mod_graph = mdf_model.graphs[0]
@@ -57,7 +52,7 @@ def show_mdf_graph(mdf_model):
57
  st.subheader("MDF Graph")
58
  mdf_model.to_graph_image(engine="dot", output_format="png", view_on_render=False, level=3, filename_root=mdf_model.id, only_warn_on_fail=(os.name == "nt"))
59
  image_path = mdf_model.id + ".png"
60
- st.sidebar.image(image_path, caption="Model Graph Visualization")
61
 
62
  def show_json_output(mdf_model):
63
  st.subheader("JSON Output")
@@ -82,40 +77,54 @@ def view_tabs(mdf_model, param_inputs): # view
82
  show_json_output(mdf_model) # view
83
 
84
  def parameter_form_to_update_model_and_view(mdf_model, parameters, param_inputs, mod_graph, nodes):
85
- form = st.form(key="parameter_form")
86
- valid_inputs = True
87
- for node_wise_parameter_key, node_wise_parameter in enumerate(parameters):
88
- # st.write("hi i am b", node_wise_parameter)
89
- for i, param in enumerate(node_wise_parameter):
90
- if isinstance(param.value, str) or param.value is None:
91
- continue
92
- key = f"{param.id}_{i}"
93
- if mdf_model.metadata:
94
- value = form.text_input(f"{param.metadata.get('description', param.id)} ({param.id})", value=str(param.value), key=key)
95
- else:
96
- value = form.text_input(f"{param.id}", value=str(param.value), key=key)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
97
 
98
  try:
99
- param_inputs[param.id] = float(value)
100
  except ValueError:
101
- st.error(f"Invalid input for {param.id}. Please enter a valid number.")
102
  valid_inputs = False
 
 
 
 
 
103
 
104
- sim_duration = form.text_input("Simulation Duration (s)", value=str(param_inputs["Simulation Duration (s)"]), key="sim_duration")
105
- time_step = form.text_input("Time Step (s)", value=str(param_inputs["Time Step (s)"]), key="time_step")
106
-
107
- try:
108
- param_inputs["Simulation Duration (s)"] = float(sim_duration)
109
- except ValueError:
110
- st.error("Invalid input for Simulation Duration. Please enter a valid number.")
111
- valid_inputs = False
112
- try:
113
- param_inputs["Time Step (s)"] = float(time_step)
114
- except ValueError:
115
- st.error("Invalid input for Time Step. Please enter a valid number.")
116
- valid_inputs = False
117
-
118
- run_button = form.form_submit_button("Run Simulation")
119
  if run_button:
120
  if valid_inputs:
121
  for b in parameters:
@@ -123,8 +132,6 @@ def parameter_form_to_update_model_and_view(mdf_model, parameters, param_inputs,
123
  if param.id in param_inputs:
124
  param.value = param_inputs[param.id]
125
  view_tabs(mdf_model, param_inputs)
126
- # else:
127
- # st.error("Please correct the invalid inputs before running the simulation.")
128
 
129
  # def upload_file_and_load_to_model():
130
  # st.write("Choose how to load the model:")
@@ -239,6 +246,12 @@ def load_model_from_content(file_content, file_extension):
239
 
240
 
241
  def main():
 
 
 
 
 
 
242
  mdf_model = upload_file_and_load_to_model() # controller
243
  if mdf_model:
244
  mod_graph = mdf_model.graphs[0]
 
8
  'Report a bug': "https://github.com/ModECI/MDF/",
9
  'About': "ModECI (Model Exchange and Convergence Initiative) is a multi-investigator collaboration that aims to develop a standardized format for exchanging computational models across diverse software platforms and domains of scientific research and technology development, with a particular focus on neuroscience, Machine Learning and Artificial Intelligence. Refer to https://modeci.org/ for more."
10
  })
11
+
 
 
 
 
 
12
  # models: Purpose: To store the state of the model and update the model
13
  def run_simulation(param_inputs, mdf_model):
14
  mod_graph = mdf_model.graphs[0]
 
52
  st.subheader("MDF Graph")
53
  mdf_model.to_graph_image(engine="dot", output_format="png", view_on_render=False, level=3, filename_root=mdf_model.id, only_warn_on_fail=(os.name == "nt"))
54
  image_path = mdf_model.id + ".png"
55
+ st.image(image_path, caption="Model Graph Visualization")
56
 
57
  def show_json_output(mdf_model):
58
  st.subheader("JSON Output")
 
77
  show_json_output(mdf_model) # view
78
 
79
  def parameter_form_to_update_model_and_view(mdf_model, parameters, param_inputs, mod_graph, nodes):
80
+ with st.form(key="parameter_form"):
81
+ valid_inputs = True
82
+
83
+ # Create two columns outside the loop
84
+ col1, col2 = st.columns(2)
85
+
86
+ for node_wise_parameter_key, node_wise_parameter in enumerate(parameters):
87
+ for i, param in enumerate(node_wise_parameter):
88
+ if isinstance(param.value, str) or param.value is None:
89
+ continue
90
+ key = f"{param.id}_{i}"
91
+
92
+ # Alternate between columns
93
+ current_col = col1 if i % 2 == 0 else col2
94
+
95
+ with current_col:
96
+ if mdf_model.metadata:
97
+ value = st.text_input(f"{param.metadata.get('description', param.id)} ({param.id})", value=str(param.value), key=key)
98
+ else:
99
+ value = st.text_input(f"{param.id}", value=str(param.value), key=key)
100
+
101
+ try:
102
+ param_inputs[param.id] = float(value)
103
+ except ValueError:
104
+ st.error(f"Invalid input for {param.id}. Please enter a valid number.")
105
+ valid_inputs = False
106
+ st.write("Simulation Parameters:")
107
+ with st.container(border=True):
108
+ # Add Simulation Duration and Time Step inputs
109
+ col1, col2 = st.columns(2)
110
+ with col1:
111
+ sim_duration = st.text_input("Simulation Duration (s)", value=str(param_inputs["Simulation Duration (s)"]), key="sim_duration")
112
+ with col2:
113
+ time_step = st.text_input("Time Step (s)", value=str(param_inputs["Time Step (s)"]), key="time_step")
114
 
115
  try:
116
+ param_inputs["Simulation Duration (s)"] = float(sim_duration)
117
  except ValueError:
118
+ st.error("Invalid input for Simulation Duration. Please enter a valid number.")
119
  valid_inputs = False
120
+ try:
121
+ param_inputs["Time Step (s)"] = float(time_step)
122
+ except ValueError:
123
+ st.error("Invalid input for Time Step. Please enter a valid number.")
124
+ valid_inputs = False
125
 
126
+ run_button = st.form_submit_button("Run Simulation")
127
+
 
 
 
 
 
 
 
 
 
 
 
 
 
128
  if run_button:
129
  if valid_inputs:
130
  for b in parameters:
 
132
  if param.id in param_inputs:
133
  param.value = param_inputs[param.id]
134
  view_tabs(mdf_model, param_inputs)
 
 
135
 
136
  # def upload_file_and_load_to_model():
137
  # st.write("Choose how to load the model:")
 
246
 
247
 
248
  def main():
249
+ header1, header2 = st.columns([1,12], vertical_alignment="top")
250
+ with header1:
251
+ st.image("logo.png", width=100)
252
+ with header2:
253
+ st.title("Welcome to Model Description Format")
254
+ st.write("Lets get started! Choose one of the following methods.")
255
  mdf_model = upload_file_and_load_to_model() # controller
256
  if mdf_model:
257
  mod_graph = mdf_model.graphs[0]