Update app.py
Browse files
app.py
CHANGED
@@ -8,8 +8,7 @@ import marimo
|
|
8 |
__generated_with = "0.13.4"
|
9 |
app = marimo.App(
|
10 |
width="full",
|
11 |
-
app_title="
|
12 |
-
html_head_file="ExcelSheetProcessor-9000.html",
|
13 |
)
|
14 |
|
15 |
|
@@ -181,15 +180,6 @@ def _(mo, prompt_stack):
|
|
181 |
return
|
182 |
|
183 |
|
184 |
-
@app.cell
|
185 |
-
def _(mo, results_stack):
|
186 |
-
ui_accordion_section_7 = mo.accordion(
|
187 |
-
{"Section 7: **Run and View Results**": results_stack}
|
188 |
-
)
|
189 |
-
ui_accordion_section_7
|
190 |
-
return
|
191 |
-
|
192 |
-
|
193 |
@app.cell
|
194 |
def _(client_instantiation_form, os):
|
195 |
if client_instantiation_form.value:
|
@@ -338,8 +328,6 @@ def _(file, io, mo, os, pd):
|
|
338 |
|
339 |
@app.cell
|
340 |
def _(mo, table_dataframe_raw):
|
341 |
-
_ = table_dataframe_raw
|
342 |
-
|
343 |
if not table_dataframe_raw.empty:
|
344 |
apply_header_readjustment = mo.ui.checkbox(label="Activate Header Adjustment")
|
345 |
else:
|
@@ -348,9 +336,13 @@ def _(mo, table_dataframe_raw):
|
|
348 |
|
349 |
|
350 |
@app.cell
|
351 |
-
def _(
|
352 |
-
|
|
|
353 |
|
|
|
|
|
|
|
354 |
if not table_dataframe_raw.empty:
|
355 |
if apply_header_readjustment.value:
|
356 |
header_row = mo.ui.number(
|
@@ -439,11 +431,10 @@ def _(
|
|
439 |
|
440 |
@app.cell
|
441 |
def _(mo, pd, table_column_names, table_dataframe):
|
442 |
-
_ = table_dataframe
|
443 |
-
|
444 |
if not table_dataframe.empty:
|
445 |
center_column_text = {col: "center" for col in table_column_names}
|
446 |
table = mo.ui.table(table_dataframe,
|
|
|
447 |
initial_selection=[0],
|
448 |
wrapped_columns=table_column_names,
|
449 |
text_justify_columns=center_column_text,
|
@@ -462,8 +453,6 @@ def _(mo, pd, table_column_names, table_dataframe):
|
|
462 |
|
463 |
@app.cell
|
464 |
def _(create_parameter_table, table_column_names, table_dataframe):
|
465 |
-
_ = table_dataframe
|
466 |
-
|
467 |
if not table_dataframe.empty:
|
468 |
column_selector = create_parameter_table(
|
469 |
label="Select the Columns to Process",
|
@@ -590,8 +579,15 @@ def _(GenParams, ModelInference, ast, client, llm_parameters, selected_model):
|
|
590 |
|
591 |
|
592 |
@app.cell
|
593 |
-
def _(
|
594 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
595 |
templates = load_templates(template_folder)
|
596 |
return (templates,)
|
597 |
|
@@ -603,8 +599,14 @@ def _(mo):
|
|
603 |
|
604 |
|
605 |
@app.cell
|
606 |
-
def _(mo, prompt_number_slider,
|
607 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
608 |
return (prompt_setup_stack,)
|
609 |
|
610 |
|
@@ -614,6 +616,35 @@ def _(mo):
|
|
614 |
return get_pt_state, set_pt_state
|
615 |
|
616 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
617 |
@app.cell
|
618 |
def _(mo, prompt_number_slider, set_pt_state, templates):
|
619 |
def update_state_from_templates(value):
|
@@ -635,18 +666,29 @@ def _(mo, prompt_number_slider, set_pt_state, templates):
|
|
635 |
)
|
636 |
|
637 |
template_selectors = [create_template_dropdowns(i) for i in range(1, prompt_number_slider.value+1)]
|
638 |
-
template_selector_stack = mo.
|
639 |
return (template_selector_stack,)
|
640 |
|
641 |
|
642 |
@app.cell
|
643 |
-
def _(fields_to_process
|
644 |
if fields_to_process:
|
645 |
variable_names = [key for key in fields_to_process[0].keys()
|
646 |
if key != "_marimo_row_id" and key != "upload_a_file"]
|
647 |
else:
|
648 |
variable_names = []
|
649 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
650 |
def create_stats_from_variables(variable_names):
|
651 |
"""
|
652 |
Creates mo.stat objects for each variable name in the list.
|
@@ -654,7 +696,7 @@ def _(fields_to_process, mo, prompt_number_slider):
|
|
654 |
Values display the variable name itself.
|
655 |
"""
|
656 |
stats = []
|
657 |
-
|
658 |
for i, var_name in enumerate(variable_names):
|
659 |
stat = mo.stat(
|
660 |
value=f"{{{var_name}}}",
|
@@ -662,23 +704,18 @@ def _(fields_to_process, mo, prompt_number_slider):
|
|
662 |
bordered=True
|
663 |
)
|
664 |
stats.append(stat)
|
665 |
-
|
666 |
-
return mo.sidebar(stats, width="525")
|
667 |
|
668 |
-
|
669 |
-
|
670 |
-
return create_stats_from_variables, is_disabled, variable_names
|
671 |
|
672 |
|
673 |
@app.cell
|
674 |
def _(create_stats_from_variables, variable_names):
|
675 |
if variable_names:
|
676 |
-
|
677 |
else:
|
678 |
-
|
679 |
-
|
680 |
-
prompt_input_variables
|
681 |
-
return
|
682 |
|
683 |
|
684 |
@app.cell
|
@@ -691,12 +728,12 @@ def _(get_pt_state, mo, prompt_number_slider):
|
|
691 |
|
692 |
prompt_column_label = mo.ui.text(label=f"**Add output column name for Prompt {num}:**", value=f"Added Column {num}")
|
693 |
prompt_editor = mo.ui.code_editor(value=get_template_content(num), language="python", min_height=300, theme="dark")
|
694 |
-
|
695 |
return [
|
696 |
prompt_column_label,
|
697 |
prompt_editor
|
698 |
]
|
699 |
-
|
700 |
prompts_raw = [create_prompt(i) for i in range(1, prompt_number_slider.value+1)]
|
701 |
return (prompts_raw,)
|
702 |
|
@@ -842,9 +879,28 @@ def _(
|
|
842 |
|
843 |
|
844 |
@app.cell
|
845 |
-
def _(
|
846 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
847 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
848 |
if not table_dataframe.empty:
|
849 |
results_table = table_dataframe.copy()
|
850 |
else:
|
@@ -868,6 +924,7 @@ def _(
|
|
868 |
results_table_view = mo.ui.table(results_table)
|
869 |
return (results_table_view,)
|
870 |
|
|
|
871 |
@app.cell
|
872 |
def _(mo, prompts_raw):
|
873 |
prompts = [mo.vstack([prompt[0], prompt[1]]) for prompt in prompts_raw]
|
|
|
8 |
__generated_with = "0.13.4"
|
9 |
app = marimo.App(
|
10 |
width="full",
|
11 |
+
app_title="watsonx-SheetProcessor-9000",
|
|
|
12 |
)
|
13 |
|
14 |
|
|
|
180 |
return
|
181 |
|
182 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
183 |
@app.cell
|
184 |
def _(client_instantiation_form, os):
|
185 |
if client_instantiation_form.value:
|
|
|
328 |
|
329 |
@app.cell
|
330 |
def _(mo, table_dataframe_raw):
|
|
|
|
|
331 |
if not table_dataframe_raw.empty:
|
332 |
apply_header_readjustment = mo.ui.checkbox(label="Activate Header Adjustment")
|
333 |
else:
|
|
|
336 |
|
337 |
|
338 |
@app.cell
|
339 |
+
def _(mo):
|
340 |
+
show_variable_sidebar = mo.ui.checkbox(label="Show Sidebar with Input Variables", value=False)
|
341 |
+
return (show_variable_sidebar,)
|
342 |
|
343 |
+
|
344 |
+
@app.cell
|
345 |
+
def _(apply_header_readjustment, mo, sheet_selector, table_dataframe_raw):
|
346 |
if not table_dataframe_raw.empty:
|
347 |
if apply_header_readjustment.value:
|
348 |
header_row = mo.ui.number(
|
|
|
431 |
|
432 |
@app.cell
|
433 |
def _(mo, pd, table_column_names, table_dataframe):
|
|
|
|
|
434 |
if not table_dataframe.empty:
|
435 |
center_column_text = {col: "center" for col in table_column_names}
|
436 |
table = mo.ui.table(table_dataframe,
|
437 |
+
show_column_summaries=False,
|
438 |
initial_selection=[0],
|
439 |
wrapped_columns=table_column_names,
|
440 |
text_justify_columns=center_column_text,
|
|
|
453 |
|
454 |
@app.cell
|
455 |
def _(create_parameter_table, table_column_names, table_dataframe):
|
|
|
|
|
456 |
if not table_dataframe.empty:
|
457 |
column_selector = create_parameter_table(
|
458 |
label="Select the Columns to Process",
|
|
|
579 |
|
580 |
|
581 |
@app.cell
|
582 |
+
def _(mo):
|
583 |
+
prompt_template_folders = get_subfolder_paths("watsonx Sheet Processor MNB/prompt_templates", depth=1)
|
584 |
+
prompt_template_model_paths = mo.ui.dropdown(options=prompt_template_folders, label="Prompt Template Variants *(Select Based on your Model)*")
|
585 |
+
return (prompt_template_model_paths,)
|
586 |
+
|
587 |
+
|
588 |
+
@app.cell
|
589 |
+
def _(load_templates, prompt_template_model_paths):
|
590 |
+
template_folder = str(prompt_template_model_paths.value)
|
591 |
templates = load_templates(template_folder)
|
592 |
return (templates,)
|
593 |
|
|
|
599 |
|
600 |
|
601 |
@app.cell
|
602 |
+
def _(mo, prompt_number_slider, prompt_template_model_paths):
|
603 |
+
prompt_mechanics_stack = mo.vstack([prompt_number_slider, prompt_template_model_paths], align="start")
|
604 |
+
return (prompt_mechanics_stack,)
|
605 |
+
|
606 |
+
|
607 |
+
@app.cell
|
608 |
+
def _(mo, prompt_mechanics_stack, template_selector_stack):
|
609 |
+
prompt_setup_stack = mo.hstack([prompt_mechanics_stack, template_selector_stack], justify="space-around")
|
610 |
return (prompt_setup_stack,)
|
611 |
|
612 |
|
|
|
616 |
return get_pt_state, set_pt_state
|
617 |
|
618 |
|
619 |
+
@app.function
|
620 |
+
def get_subfolder_paths(base_path, depth=1):
|
621 |
+
"""Lists subfolder paths up to specified depth.
|
622 |
+
|
623 |
+
Args:
|
624 |
+
base_path: Directory to search in
|
625 |
+
depth: Subdirectory levels to traverse (default: 1)
|
626 |
+
|
627 |
+
Returns:
|
628 |
+
Dict with folder names as keys and paths as values
|
629 |
+
"""
|
630 |
+
import os
|
631 |
+
|
632 |
+
result = {}
|
633 |
+
if depth <= 0 or not os.path.isdir(base_path):
|
634 |
+
return result
|
635 |
+
|
636 |
+
for entry in os.scandir(base_path):
|
637 |
+
if entry.is_dir():
|
638 |
+
result[entry.name] = entry.path
|
639 |
+
if depth > 1:
|
640 |
+
# Recursively get subdirectories
|
641 |
+
subfolders = get_subfolder_paths(entry.path, depth - 1)
|
642 |
+
# Update result with subfolders
|
643 |
+
result.update(subfolders)
|
644 |
+
|
645 |
+
return result
|
646 |
+
|
647 |
+
|
648 |
@app.cell
|
649 |
def _(mo, prompt_number_slider, set_pt_state, templates):
|
650 |
def update_state_from_templates(value):
|
|
|
666 |
)
|
667 |
|
668 |
template_selectors = [create_template_dropdowns(i) for i in range(1, prompt_number_slider.value+1)]
|
669 |
+
template_selector_stack = mo.vstack(template_selectors, align="start")
|
670 |
return (template_selector_stack,)
|
671 |
|
672 |
|
673 |
@app.cell
|
674 |
+
def _(fields_to_process):
|
675 |
if fields_to_process:
|
676 |
variable_names = [key for key in fields_to_process[0].keys()
|
677 |
if key != "_marimo_row_id" and key != "upload_a_file"]
|
678 |
else:
|
679 |
variable_names = []
|
680 |
+
return (variable_names,)
|
681 |
+
|
682 |
+
|
683 |
+
@app.cell
|
684 |
+
def _(prompt_number_slider):
|
685 |
+
def is_disabled(button_num):
|
686 |
+
return prompt_number_slider.value < button_num
|
687 |
+
return (is_disabled,)
|
688 |
+
|
689 |
+
|
690 |
+
@app.cell
|
691 |
+
def _(mo):
|
692 |
def create_stats_from_variables(variable_names):
|
693 |
"""
|
694 |
Creates mo.stat objects for each variable name in the list.
|
|
|
696 |
Values display the variable name itself.
|
697 |
"""
|
698 |
stats = []
|
699 |
+
|
700 |
for i, var_name in enumerate(variable_names):
|
701 |
stat = mo.stat(
|
702 |
value=f"{{{var_name}}}",
|
|
|
704 |
bordered=True
|
705 |
)
|
706 |
stats.append(stat)
|
|
|
|
|
707 |
|
708 |
+
return mo.sidebar(stats, width="375")
|
709 |
+
return (create_stats_from_variables,)
|
|
|
710 |
|
711 |
|
712 |
@app.cell
|
713 |
def _(create_stats_from_variables, variable_names):
|
714 |
if variable_names:
|
715 |
+
prompt_input_variables_sidebar = create_stats_from_variables(variable_names)
|
716 |
else:
|
717 |
+
prompt_input_variables_sidebar = None
|
718 |
+
return (prompt_input_variables_sidebar,)
|
|
|
|
|
719 |
|
720 |
|
721 |
@app.cell
|
|
|
728 |
|
729 |
prompt_column_label = mo.ui.text(label=f"**Add output column name for Prompt {num}:**", value=f"Added Column {num}")
|
730 |
prompt_editor = mo.ui.code_editor(value=get_template_content(num), language="python", min_height=300, theme="dark")
|
731 |
+
|
732 |
return [
|
733 |
prompt_column_label,
|
734 |
prompt_editor
|
735 |
]
|
736 |
+
|
737 |
prompts_raw = [create_prompt(i) for i in range(1, prompt_number_slider.value+1)]
|
738 |
return (prompts_raw,)
|
739 |
|
|
|
879 |
|
880 |
|
881 |
@app.cell
|
882 |
+
def _(mo, results_stack):
|
883 |
+
ui_accordion_section_7 = mo.accordion(
|
884 |
+
{"Section 7: **Run and View Results**": results_stack}
|
885 |
+
)
|
886 |
+
ui_accordion_section_7
|
887 |
+
return
|
888 |
+
|
889 |
+
|
890 |
+
@app.cell
|
891 |
+
def _(show_variable_sidebar):
|
892 |
+
show_variable_sidebar.right()
|
893 |
+
return
|
894 |
|
895 |
+
|
896 |
+
@app.cell
|
897 |
+
def _(prompt_input_variables_sidebar, show_variable_sidebar):
|
898 |
+
show_variable_sidebar.value is not False and prompt_input_variables_sidebar
|
899 |
+
return
|
900 |
+
|
901 |
+
|
902 |
+
@app.cell
|
903 |
+
def _(table_dataframe):
|
904 |
if not table_dataframe.empty:
|
905 |
results_table = table_dataframe.copy()
|
906 |
else:
|
|
|
924 |
results_table_view = mo.ui.table(results_table)
|
925 |
return (results_table_view,)
|
926 |
|
927 |
+
|
928 |
@app.cell
|
929 |
def _(mo, prompts_raw):
|
930 |
prompts = [mo.vstack([prompt[0], prompt[1]]) for prompt in prompts_raw]
|