|
|
|
|
|
import gradio as gr |
|
import pandas as pd |
|
|
|
|
|
def update_mode_visibility( |
|
mode: str, |
|
current_subject: str, |
|
current_description: str, |
|
current_text: str, |
|
current_url: str, |
|
): |
|
"""Updates visibility and values of UI elements based on generation mode.""" |
|
is_subject = mode == "subject" |
|
is_path = mode == "path" |
|
is_text = mode == "text" |
|
is_web = mode == "web" |
|
|
|
|
|
subject_val = current_subject if is_subject else "" |
|
description_val = current_description if is_path else "" |
|
text_val = current_text if is_text else "" |
|
url_val = current_url if is_web else "" |
|
|
|
|
|
return ( |
|
gr.update(visible=is_subject), |
|
gr.update(visible=is_path), |
|
gr.update(visible=is_text), |
|
gr.update(visible=is_web), |
|
gr.update(visible=is_path), |
|
gr.update(visible=is_subject or is_text or is_web), |
|
gr.update(value=subject_val), |
|
gr.update(value=description_val), |
|
gr.update(value=text_val), |
|
gr.update(value=url_val), |
|
gr.update(value=None), |
|
gr.update(value=None), |
|
gr.update(value=""), |
|
gr.update(value=""), |
|
gr.update(value="", visible=False), |
|
gr.update(value=0, visible=False), |
|
) |
|
|
|
|
|
def use_selected_subjects(subjects_df: pd.DataFrame | None): |
|
"""Updates UI to use subjects from learning path analysis.""" |
|
if subjects_df is None or subjects_df.empty: |
|
gr.Warning("No subjects available to copy from Learning Path analysis.") |
|
|
|
|
|
return { |
|
"generation_mode_radio": gr.update(), |
|
"subject_mode_group": gr.update(), |
|
"path_mode_group": gr.update(), |
|
"text_mode_group": gr.update(), |
|
"web_mode_group": gr.update(), |
|
"path_results_group": gr.update(), |
|
"cards_output_group": gr.update(), |
|
"subject_textbox": gr.update(), |
|
"description_textbox": gr.update(), |
|
"source_text_textbox": gr.update(), |
|
"url_textbox": gr.update(), |
|
"topic_number_slider": gr.update(), |
|
"preference_prompt_textbox": gr.update(), |
|
"output_dataframe": gr.update(), |
|
"subjects_dataframe": gr.update(), |
|
"learning_order_markdown": gr.update(), |
|
"projects_markdown": gr.update(), |
|
"progress_html": gr.update(), |
|
"total_cards_number": gr.update(), |
|
} |
|
|
|
try: |
|
subjects = subjects_df["Subject"].tolist() |
|
combined_subject = ", ".join(subjects) |
|
suggested_topics = min(len(subjects) + 1, 20) |
|
except KeyError: |
|
gr.Error("Learning path analysis result is missing the 'Subject' column.") |
|
|
|
return { |
|
"generation_mode_radio": gr.update(), |
|
"subject_mode_group": gr.update(), |
|
"path_mode_group": gr.update(), |
|
"text_mode_group": gr.update(), |
|
"web_mode_group": gr.update(), |
|
"path_results_group": gr.update(), |
|
"cards_output_group": gr.update(), |
|
"subject_textbox": gr.update(), |
|
"description_textbox": gr.update(), |
|
"source_text_textbox": gr.update(), |
|
"url_textbox": gr.update(), |
|
"topic_number_slider": gr.update(), |
|
"preference_prompt_textbox": gr.update(), |
|
"output_dataframe": gr.update(), |
|
"subjects_dataframe": gr.update(), |
|
"learning_order_markdown": gr.update(), |
|
"projects_markdown": gr.update(), |
|
"progress_html": gr.update(), |
|
"total_cards_number": gr.update(), |
|
} |
|
|
|
|
|
return { |
|
"generation_mode_radio": "subject", |
|
"subject_mode_group": gr.update(visible=True), |
|
"path_mode_group": gr.update(visible=False), |
|
"text_mode_group": gr.update(visible=False), |
|
"web_mode_group": gr.update(visible=False), |
|
"path_results_group": gr.update(visible=False), |
|
"cards_output_group": gr.update(visible=True), |
|
"subject_textbox": combined_subject, |
|
"description_textbox": "", |
|
"source_text_textbox": "", |
|
"url_textbox": "", |
|
"topic_number_slider": suggested_topics, |
|
"preference_prompt_textbox": "Focus on connections between these subjects and their practical applications.", |
|
"output_dataframe": gr.update(value=None), |
|
"subjects_dataframe": subjects_df, |
|
"learning_order_markdown": gr.update(), |
|
"projects_markdown": gr.update(), |
|
"progress_html": gr.update(visible=False), |
|
"total_cards_number": gr.update(visible=False), |
|
} |
|
|