Skip to content

Commit d1d1cc3

Browse files
committed
feat: deploy active upgrade endpoint tool
1 parent cf42d03 commit d1d1cc3

File tree

2 files changed

+55
-11
lines changed

2 files changed

+55
-11
lines changed

pyproject.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,14 @@ dependencies = [
2020
'pydantic<=2.11.0',
2121
'panel>=1.8.2',
2222
'altair',
23-
'aind-data-schema>=2.0.3',
23+
'aind-data-schema>=2.0.5',
2424
'aind-data-access-api[docdb]',
2525
'aind-data-access-api[rds]',
2626
'aind-metadata-validator>=0.11.1',
2727
'flask',
2828
'langchain',
2929
'langchain_aws',
30+
'aind-metadata-upgrader>=0.3.0',
3031
]
3132

3233
[project.optional-dependencies]

src/aind_metadata_viz/upgrade.py

Lines changed: 53 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,15 @@
1818
"name": 1,
1919
}
2020

21+
client = MetadataDbClient(
22+
host="api.allenneuraldynamics.org",
23+
version="v1",
24+
)
25+
2126

2227
@pn.cache()
2328
def get_extra_col_df():
2429
print("Retrieving extra columns from DocDB...")
25-
client = MetadataDbClient(
26-
host="api.allenneuraldynamics.org",
27-
version="v1",
28-
)
2930

3031
all_records = client.retrieve_docdb_records(
3132
filter_query={},
@@ -88,12 +89,41 @@ def get_data():
8889
return df
8990

9091

92+
def run_upgrade(record_id_or_name: str):
93+
record = None
94+
# Try to find by _id first
95+
record = client.retrieve_docdb_records(
96+
filter_query={"_id": record_id_or_name},
97+
limit=1,
98+
)
99+
if not record:
100+
# Try to find by name
101+
record = client.retrieve_docdb_records(
102+
filter_query={"name": record_id_or_name},
103+
limit=1,
104+
)
105+
if not record:
106+
return f"Record with _id or name '{record_id_or_name}' not found."
107+
108+
record = record[0]
109+
try:
110+
Upgrade(record)
111+
return f"Upgrade successful for record '{record_id_or_name}'."
112+
except Exception as e:
113+
return f"Upgrade failed for record '{record_id_or_name}': {e}"
114+
115+
91116
def build_panel_app():
92-
col = pn.Column("# Metadata Upgrade Status Table", sizing_mode="stretch_width")
117+
table_col = pn.Column()
93118
button = pn.widgets.Button(name="Load Table", button_type="primary")
94119

120+
# New widgets for upgrade functionality
121+
text_input = pn.widgets.TextInput(name="Enter _id or name", placeholder="Type _id or name here...")
122+
upgrade_button = pn.widgets.Button(name="Run Upgrade", button_type="success")
123+
output_box = pn.pane.Markdown("", sizing_mode="stretch_width")
124+
95125
def load_table(event):
96-
col.loading = True
126+
table_col.loading = True
97127
df = get_data()
98128
tab = pn.widgets.Tabulator(
99129
df,
@@ -104,12 +134,25 @@ def load_table(event):
104134
page_size=500,
105135
show_index=False,
106136
)
107-
col[:] = ["# Metadata Upgrade Status Table", tab]
108-
col.loading = False
137+
table_col[:] = ["# Metadata Upgrade Status Table", tab]
138+
table_col.loading = False
139+
140+
def run_upgrade_callback(event):
141+
record_id_or_name = text_input.value
142+
result = run_upgrade(record_id_or_name)
143+
output_box.object = f"**Upgrade Output:**\n{result}"
109144

110145
button.on_click(load_table)
111-
col.append(button)
112-
return col
146+
upgrade_button.on_click(run_upgrade_callback)
147+
table_col.append(button)
148+
main_col = pn.Column(
149+
"# Metadata Upgrade Status Table",
150+
table_col,
151+
pn.Row(text_input, upgrade_button),
152+
output_box,
153+
sizing_mode="stretch_width"
154+
)
155+
return main_col
113156

114157

115158
app = build_panel_app()

0 commit comments

Comments
 (0)