ayushnoori commited on
Commit
31e2a19
·
1 Parent(s): 48009b1

Patch index error

Browse files
Files changed (1) hide show
  1. pages/input.py +15 -5
pages/input.py CHANGED
@@ -60,25 +60,35 @@ else:
60
  target_node_type_index = st.session_state.query_options['target_node_type'].index(st.session_state.query['target_node_type'])
61
  relation_index = st.session_state.query_options['relation'].index(st.session_state.query['relation'])
62
 
 
 
 
 
 
 
 
63
  # Select source node type
64
  source_node_type_options = node_types['node_type']
65
  source_node_type = st.selectbox("Source Node Type", source_node_type_options,
66
- format_func = lambda x: x.replace("_", " "), index = source_node_type_index)
 
67
 
68
  # Select source node
69
  source_node_options = kg_nodes[kg_nodes['node_type'] == source_node_type]['node_name']
70
  source_node = st.selectbox("Source Node", source_node_options,
71
- index = source_node_index)
72
 
73
  # Select target node type
74
  target_node_type_options = edge_types[edge_types.x_type == source_node_type].y_type.unique()
75
  target_node_type = st.selectbox("Target Node Type", target_node_type_options,
76
- format_func = lambda x: x.replace("_", " "), index = target_node_type_index)
 
77
 
78
  # Select relation
79
  relation_options = edge_types[(edge_types.x_type == source_node_type) & (edge_types.y_type == target_node_type)].relation.unique()
80
  relation = st.selectbox("Edge Type", relation_options,
81
- format_func = lambda x: x.replace("_", "-"), index = relation_index)
 
82
 
83
  # Button to submit query
84
  if st.button("Submit Query"):
@@ -115,4 +125,4 @@ if st.button("Submit Query"):
115
  st.subheader("Knowledge Graph", divider = "red")
116
  display_data = kg_nodes[['node_id', 'node_type', 'node_name', 'node_source']].copy()
117
  display_data = display_data.rename(columns = {'node_id': 'ID', 'node_type': 'Type', 'node_name': 'Name', 'node_source': 'Database'})
118
- st.dataframe(display_data, use_container_width = True)
 
60
  target_node_type_index = st.session_state.query_options['target_node_type'].index(st.session_state.query['target_node_type'])
61
  relation_index = st.session_state.query_options['relation'].index(st.session_state.query['relation'])
62
 
63
+ # Define error catching function
64
+ def catch_index_error(index, index_options):
65
+ if index >= len(index_options):
66
+ return 0
67
+ else:
68
+ return index
69
+
70
  # Select source node type
71
  source_node_type_options = node_types['node_type']
72
  source_node_type = st.selectbox("Source Node Type", source_node_type_options,
73
+ format_func = lambda x: x.replace("_", " "),
74
+ index = catch_index_error(source_node_type_index, source_node_type_options))
75
 
76
  # Select source node
77
  source_node_options = kg_nodes[kg_nodes['node_type'] == source_node_type]['node_name']
78
  source_node = st.selectbox("Source Node", source_node_options,
79
+ index = catch_index_error(source_node_index, source_node_options))
80
 
81
  # Select target node type
82
  target_node_type_options = edge_types[edge_types.x_type == source_node_type].y_type.unique()
83
  target_node_type = st.selectbox("Target Node Type", target_node_type_options,
84
+ format_func = lambda x: x.replace("_", " "),
85
+ index = catch_index_error(target_node_type_index, target_node_type_options))
86
 
87
  # Select relation
88
  relation_options = edge_types[(edge_types.x_type == source_node_type) & (edge_types.y_type == target_node_type)].relation.unique()
89
  relation = st.selectbox("Edge Type", relation_options,
90
+ format_func = lambda x: x.replace("_", "-"),
91
+ index = catch_index_error(relation_index, relation_options))
92
 
93
  # Button to submit query
94
  if st.button("Submit Query"):
 
125
  st.subheader("Knowledge Graph", divider = "red")
126
  display_data = kg_nodes[['node_id', 'node_type', 'node_name', 'node_source']].copy()
127
  display_data = display_data.rename(columns = {'node_id': 'ID', 'node_type': 'Type', 'node_name': 'Name', 'node_source': 'Database'})
128
+ st.dataframe(display_data, use_container_width = True, hide_index = True)