thearn commited on
Commit
25dabdb
·
1 Parent(s): d7e687c

working dropdown

Browse files
Files changed (1) hide show
  1. app.py +37 -3
app.py CHANGED
@@ -87,13 +87,47 @@ def tree_to_dot(graph: Dict[str, Any]) -> str:
87
  return "\n".join(lines)
88
 
89
  def main():
90
- st.title("Math Genealogy Ancestor Tree (WebSocket API)")
91
- mgp_id_str = st.text_input("Enter MGP ID (integer):")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
92
  progress_placeholder = st.empty()
93
  graph_placeholder = st.empty()
94
  run_btn = st.button("Show Ancestor Tree")
95
  if run_btn:
96
- mgp_id = get_id_from_input(mgp_id_str)
97
  if mgp_id is None:
98
  st.error("Please enter a valid integer MGP ID.")
99
  return
 
87
  return "\n".join(lines)
88
 
89
  def main():
90
+ st.title("Math Genealogy Ancestor Tree")
91
+
92
+ mathematicians = [
93
+ ("Tristan Hearn", 162833),
94
+ ("Alexander Grothendieck", 31245),
95
+ ("Emmy Noether", 6967),
96
+ ("David Hilbert", 7298),
97
+ ("Sophie Germain", 55175),
98
+ ("Carl Friedrich Gauss", 18231),
99
+ ]
100
+ names = [f"{name} ({mid})" for name, mid in mathematicians]
101
+ default_index = 0 # Tristan Hearn
102
+
103
+ # initialize session state for mgp_id_str if not set
104
+ if "mgp_id_str" not in st.session_state:
105
+ st.session_state["mgp_id_str"] = str(mathematicians[default_index][1])
106
+
107
+ mgp_id_str = st.text_input(
108
+ "Enter MGP ID (integer):",
109
+ value=st.session_state["mgp_id_str"],
110
+ key="mgp_id_str",
111
+ help="You can type a custom ID or use the selection below."
112
+ )
113
+
114
+ def on_select():
115
+ st.session_state["mgp_id_str"] = str(mathematicians[st.session_state["mathematician_idx"]][1])
116
+
117
+ selected_idx = st.selectbox(
118
+ "Or select a mathematician:",
119
+ range(len(names)),
120
+ format_func=lambda i: names[i],
121
+ index=default_index,
122
+ key="mathematician_idx",
123
+ on_change=on_select,
124
+ )
125
+
126
  progress_placeholder = st.empty()
127
  graph_placeholder = st.empty()
128
  run_btn = st.button("Show Ancestor Tree")
129
  if run_btn:
130
+ mgp_id = get_id_from_input(st.session_state["mgp_id_str"])
131
  if mgp_id is None:
132
  st.error("Please enter a valid integer MGP ID.")
133
  return