youngtsai commited on
Commit
f3fe998
·
1 Parent(s): 2685d2a

def setup_education_buttons(buttons_config):

Browse files
Files changed (1) hide show
  1. app.py +92 -240
app.py CHANGED
@@ -1910,7 +1910,6 @@ def get_ai_content(password, video_id, df_string, topic, grade, level, specific_
1910
  verify_password(password)
1911
  if source == "gcs":
1912
  print("===get_ai_content on gcs===")
1913
- gcs_client = GCS_CLIENT
1914
  bucket_name = 'video_ai_assistant'
1915
  file_name = f'{video_id}_ai_content_list.json'
1916
  blob_name = f"{video_id}/{file_name}"
@@ -3048,182 +3047,9 @@ with gr.Blocks(theme=gr.themes.Base(primary_hue=gr.themes.colors.orange, seconda
3048
  inputs=update_state_inputs,
3049
  outputs=update_state_outputs
3050
  )
3051
-
3052
 
3053
- # 当输入网页链接时触发
3054
- # web_link.change(process_web_link, inputs=web_link, outputs=[btn_1, btn_2, btn_3, df_summarise, df_string_output])
3055
-
3056
- # reading_passage event
3057
- # reading_passage_text_to_latex.click(
3058
- # reading_passage_add_latex_version,
3059
- # inputs=[video_id],
3060
- # outputs=[reading_passage_text]
3061
- # )
3062
- # reading_passage_get_button.click(
3063
- # get_LLM_content,
3064
- # inputs=[video_id, reading_passage_kind],
3065
- # outputs=[reading_passage_text]
3066
- # )
3067
- # reading_passage_create_button.click(
3068
- # create_LLM_content,
3069
- # inputs=[video_id, df_string_output, reading_passage_kind],
3070
- # outputs=[reading_passage_text]
3071
- # )
3072
- # reading_passage_delete_button.click(
3073
- # delete_LLM_content,
3074
- # inputs=[video_id, reading_passage_kind],
3075
- # outputs=[reading_passage_text]
3076
- # )
3077
- # reading_passage_edit_button.click(
3078
- # enable_edit_mode,
3079
- # inputs=[],
3080
- # outputs=[reading_passage_text]
3081
- # )
3082
- # reading_passage_update_button.click(
3083
- # update_LLM_content,
3084
- # inputs=[video_id, reading_passage_text, reading_passage_kind],
3085
- # outputs=[reading_passage_text]
3086
- # )
3087
-
3088
- # # summary event
3089
- # # summary_to_markdown.click(
3090
- # # summary_add_markdown_version,
3091
- # # inputs=[video_id],
3092
- # # outputs=[summary_text]
3093
- # # )
3094
- # summary_get_button.click(
3095
- # get_LLM_content,
3096
- # inputs=[video_id, summary_kind],
3097
- # outputs=[summary_text]
3098
- # )
3099
- # summary_create_button.click(
3100
- # create_LLM_content,
3101
- # inputs=[video_id, df_string_output, summary_kind],
3102
- # outputs=[summary_text]
3103
- # )
3104
- # summary_delete_button.click(
3105
- # delete_LLM_content,
3106
- # inputs=[video_id, summary_kind],
3107
- # outputs=[summary_text]
3108
- # )
3109
- # summary_edit_button.click(
3110
- # enable_edit_mode,
3111
- # inputs=[],
3112
- # outputs=[summary_text]
3113
- # )
3114
- # summary_update_button.click(
3115
- # update_LLM_content,
3116
- # inputs=[video_id, summary_text, summary_kind],
3117
- # outputs=[summary_text]
3118
- # )
3119
-
3120
- # # transcript event
3121
- # transcript_get_button.click(
3122
- # get_LLM_content,
3123
- # inputs=[video_id, transcript_kind],
3124
- # outputs=[df_string_output]
3125
- # )
3126
- # transcript_create_button.click(
3127
- # create_LLM_content,
3128
- # inputs=[video_id, df_string_output, transcript_kind],
3129
- # outputs=[df_string_output]
3130
- # )
3131
- # transcript_delete_button.click(
3132
- # delete_LLM_content,
3133
- # inputs=[video_id, transcript_kind],
3134
- # outputs=[df_string_output]
3135
- # )
3136
- # transcript_edit_button.click(
3137
- # enable_edit_mode,
3138
- # inputs=[],
3139
- # outputs=[df_string_output]
3140
- # )
3141
- # transcript_update_button.click(
3142
- # update_LLM_content,
3143
- # inputs=[video_id, df_string_output, transcript_kind],
3144
- # outputs=[df_string_output]
3145
- # )
3146
-
3147
- # # key_moments event
3148
- # key_moments_get_button.click(
3149
- # get_LLM_content,
3150
- # inputs=[video_id, key_moments_kind],
3151
- # outputs=[key_moments]
3152
- # )
3153
- # key_moments_create_button.click(
3154
- # create_LLM_content,
3155
- # inputs=[video_id, df_string_output, key_moments_kind],
3156
- # outputs=[key_moments]
3157
- # )
3158
- # key_moments_delete_button.click(
3159
- # delete_LLM_content,
3160
- # inputs=[video_id, key_moments_kind],
3161
- # outputs=[key_moments]
3162
- # )
3163
- # key_moments_edit_button.click(
3164
- # enable_edit_mode,
3165
- # inputs=[],
3166
- # outputs=[key_moments]
3167
- # )
3168
- # key_moments_update_button.click(
3169
- # update_LLM_content,
3170
- # inputs=[video_id, key_moments, key_moments_kind],
3171
- # outputs=[key_moments]
3172
- # )
3173
-
3174
- # # question_list event
3175
- # questions_get_button.click(
3176
- # get_LLM_content,
3177
- # inputs=[video_id, questions_kind],
3178
- # outputs=[questions_json]
3179
- # )
3180
- # questions_create_button.click(
3181
- # create_LLM_content,
3182
- # inputs=[video_id, df_string_output, questions_kind],
3183
- # outputs=[questions_json]
3184
- # )
3185
- # questions_delete_button.click(
3186
- # delete_LLM_content,
3187
- # inputs=[video_id, questions_kind],
3188
- # outputs=[questions_json]
3189
- # )
3190
- # questions_edit_button.click(
3191
- # enable_edit_mode,
3192
- # inputs=[],
3193
- # outputs=[questions_json]
3194
- # )
3195
- # questions_update_button.click(
3196
- # update_LLM_content,
3197
- # inputs=[video_id, questions_json, questions_kind],
3198
- # outputs=[questions_json]
3199
- # )
3200
- # # questions_answers event
3201
- # questions_answers_get_button.click(
3202
- # get_LLM_content,
3203
- # inputs=[video_id, questions_answers_kind],
3204
- # outputs=[questions_answers_json]
3205
- # )
3206
- # questions_answers_create_button.click(
3207
- # create_LLM_content,
3208
- # inputs=[video_id, df_string_output, questions_answers_kind],
3209
- # outputs=[questions_answers_json]
3210
- # )
3211
- # questions_answers_delete_button.click(
3212
- # delete_LLM_content,
3213
- # inputs=[video_id, questions_answers_kind],
3214
- # outputs=[questions_answers_json]
3215
- # )
3216
- # questions_answers_edit_button.click(
3217
- # enable_edit_mode,
3218
- # inputs=[],
3219
- # outputs=[questions_answers_json]
3220
- # )
3221
- # questions_answers_update_button.click(
3222
- # update_LLM_content,
3223
- # inputs=[video_id, questions_answers_json, questions_answers_kind],
3224
- # outputs=[questions_answers_json]
3225
- # )
3226
 
 
3227
  def setup_content_buttons(buttons_config):
3228
  for config in buttons_config:
3229
  button = config['button']
@@ -3231,7 +3057,7 @@ with gr.Blocks(theme=gr.themes.Base(primary_hue=gr.themes.colors.orange, seconda
3231
  inputs = config['inputs']
3232
  outputs = config['outputs']
3233
  button.click(
3234
- action,
3235
  inputs=inputs,
3236
  outputs=outputs
3237
  )
@@ -3426,70 +3252,96 @@ with gr.Blocks(theme=gr.themes.Base(primary_hue=gr.themes.colors.orange, seconda
3426
  ]
3427
  setup_content_buttons(content_buttons_config)
3428
 
3429
-
3430
- # 教師版
3431
- worksheet_content_btn.click(
3432
- get_ai_content,
3433
- inputs=[password, video_id, df_string_output, content_subject, content_grade, content_level, worksheet_algorithm, worksheet_content_type_name],
3434
- outputs=[worksheet_exam_result_original, worksheet_exam_result, worksheet_prompt, worksheet_exam_result_prompt]
3435
- )
3436
- lesson_plan_btn.click(
3437
- get_ai_content,
3438
- inputs=[password, video_id, df_string_output, content_subject, content_grade, content_level, lesson_plan_time, lesson_plan_content_type_name],
3439
- outputs=[lesson_plan_exam_result_original, lesson_plan_exam_result, lesson_plan_prompt, lesson_plan_exam_result_prompt]
3440
- )
3441
- exit_ticket_btn.click(
3442
- get_ai_content,
3443
- inputs=[password, video_id, df_string_output, content_subject, content_grade, content_level, exit_ticket_time, exit_ticket_content_type_name],
3444
- outputs=[exit_ticket_exam_result_original, exit_ticket_exam_result, exit_ticket_prompt, exit_ticket_exam_result_prompt]
3445
- )
3446
-
3447
- # 生成結果微調
3448
- worksheet_exam_result_fine_tune_btn.click(
3449
- generate_exam_fine_tune_result,
3450
- inputs=[password, worksheet_exam_result_prompt, df_string_output, worksheet_exam_result, worksheet_exam_result_fine_tune_prompt],
3451
- outputs=[worksheet_exam_result]
3452
- )
3453
- worksheet_download_exam_result_button.click(
3454
- download_exam_result,
3455
- inputs=[worksheet_exam_result],
3456
- outputs=[worksheet_exam_result_word_link]
3457
- )
3458
- worksheet_exam_result_retrun_original.click(
3459
- return_original_exam_result,
3460
- inputs=[worksheet_exam_result_original],
3461
- outputs=[worksheet_exam_result]
3462
- )
3463
- lesson_plan_exam_result_fine_tune_btn.click(
3464
- generate_exam_fine_tune_result,
3465
- inputs=[password, lesson_plan_exam_result_prompt, df_string_output, lesson_plan_exam_result, lesson_plan_exam_result_fine_tune_prompt],
3466
- outputs=[lesson_plan_exam_result]
3467
- )
3468
- lesson_plan_download_exam_result_button.click(
3469
- download_exam_result,
3470
- inputs=[lesson_plan_exam_result],
3471
- outputs=[lesson_plan_exam_result_word_link]
3472
- )
3473
- lesson_plan_exam_result_retrun_original.click(
3474
- return_original_exam_result,
3475
- inputs=[lesson_plan_exam_result_original],
3476
- outputs=[lesson_plan_exam_result]
3477
- )
3478
- exit_ticket_exam_result_fine_tune_btn.click(
3479
- generate_exam_fine_tune_result,
3480
- inputs=[password, exit_ticket_exam_result_prompt, df_string_output, exit_ticket_exam_result, exit_ticket_exam_result_fine_tune_prompt],
3481
- outputs=[exit_ticket_exam_result]
3482
- )
3483
- exit_ticket_download_exam_result_button.click(
3484
- download_exam_result,
3485
- inputs=[exit_ticket_exam_result],
3486
- outputs=[exit_ticket_exam_result_word_link]
3487
- )
3488
- exit_ticket_exam_result_retrun_original.click(
3489
- return_original_exam_result,
3490
- inputs=[exit_ticket_exam_result_original],
3491
- outputs=[exit_ticket_exam_result]
3492
- )
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
3493
 
3494
  # init_params
3495
  init_outputs = [
 
1910
  verify_password(password)
1911
  if source == "gcs":
1912
  print("===get_ai_content on gcs===")
 
1913
  bucket_name = 'video_ai_assistant'
1914
  file_name = f'{video_id}_ai_content_list.json'
1915
  blob_name = f"{video_id}/{file_name}"
 
3047
  inputs=update_state_inputs,
3048
  outputs=update_state_outputs
3049
  )
 
3050
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
3051
 
3052
+ # --- CRUD admin ---
3053
  def setup_content_buttons(buttons_config):
3054
  for config in buttons_config:
3055
  button = config['button']
 
3057
  inputs = config['inputs']
3058
  outputs = config['outputs']
3059
  button.click(
3060
+ fn=action,
3061
  inputs=inputs,
3062
  outputs=outputs
3063
  )
 
3252
  ]
3253
  setup_content_buttons(content_buttons_config)
3254
 
3255
+ # --- Education Material ---
3256
+ def setup_education_buttons(buttons_config):
3257
+ for config in buttons_config:
3258
+ button = config["button"]
3259
+ action = config["action"]
3260
+ inputs = config["inputs"]
3261
+ outputs = config["outputs"]
3262
+ button.click(
3263
+ fn=action,
3264
+ inputs=inputs,
3265
+ outputs=outputs
3266
+ )
3267
+ education_buttons_config = [
3268
+ # 學習單相關按鈕
3269
+ {
3270
+ "button": worksheet_content_btn,
3271
+ "action": get_ai_content,
3272
+ "inputs": [password, video_id, df_string_output, content_subject, content_grade, content_level, worksheet_algorithm, worksheet_content_type_name],
3273
+ "outputs": [worksheet_exam_result_original, worksheet_exam_result, worksheet_prompt, worksheet_exam_result_prompt]
3274
+ },
3275
+ {
3276
+ "button": worksheet_exam_result_fine_tune_btn,
3277
+ "action": generate_exam_fine_tune_result,
3278
+ "inputs": [password, worksheet_exam_result_prompt, df_string_output, worksheet_exam_result, worksheet_exam_result_fine_tune_prompt],
3279
+ "outputs": [worksheet_exam_result]
3280
+ },
3281
+ {
3282
+ "button": worksheet_download_exam_result_button,
3283
+ "action": download_exam_result,
3284
+ "inputs": [worksheet_exam_result],
3285
+ "outputs": [worksheet_exam_result_word_link]
3286
+ },
3287
+ {
3288
+ "button": worksheet_exam_result_retrun_original,
3289
+ "action": return_original_exam_result,
3290
+ "inputs": [worksheet_exam_result_original],
3291
+ "outputs": [worksheet_exam_result]
3292
+ },
3293
+ # 教案相關按鈕
3294
+ {
3295
+ "button": lesson_plan_btn,
3296
+ "action": get_ai_content,
3297
+ "inputs": [password, video_id, df_string_output, content_subject, content_grade, content_level, lesson_plan_time, lesson_plan_content_type_name],
3298
+ "outputs": [lesson_plan_exam_result_original, lesson_plan_exam_result, lesson_plan_prompt, lesson_plan_exam_result_prompt]
3299
+ },
3300
+ {
3301
+ "button": lesson_plan_exam_result_fine_tune_btn,
3302
+ "action": generate_exam_fine_tune_result,
3303
+ "inputs": [password, lesson_plan_exam_result_prompt, df_string_output, lesson_plan_exam_result, lesson_plan_exam_result_fine_tune_prompt],
3304
+ "outputs": [lesson_plan_exam_result]
3305
+ },
3306
+ {
3307
+ "button": lesson_plan_download_exam_result_button,
3308
+ "action": download_exam_result,
3309
+ "inputs": [lesson_plan_exam_result],
3310
+ "outputs": [lesson_plan_exam_result_word_link]
3311
+ },
3312
+ {
3313
+ "button": lesson_plan_exam_result_retrun_original,
3314
+ "action": return_original_exam_result,
3315
+ "inputs": [lesson_plan_exam_result_original],
3316
+ "outputs": [lesson_plan_exam_result]
3317
+ },
3318
+ # 出場券相關按鈕
3319
+ {
3320
+ "button": exit_ticket_btn,
3321
+ "action": get_ai_content,
3322
+ "inputs": [password, video_id, df_string_output, content_subject, content_grade, content_level, exit_ticket_time, exit_ticket_content_type_name],
3323
+ "outputs": [exit_ticket_exam_result_original, exit_ticket_exam_result, exit_ticket_prompt, exit_ticket_exam_result_prompt]
3324
+ },
3325
+ {
3326
+ "button": exit_ticket_exam_result_fine_tune_btn,
3327
+ "action": generate_exam_fine_tune_result,
3328
+ "inputs": [password, exit_ticket_exam_result_prompt, df_string_output, exit_ticket_exam_result, exit_ticket_exam_result_fine_tune_prompt],
3329
+ "outputs": [exit_ticket_exam_result]
3330
+ },
3331
+ {
3332
+ "button": exit_ticket_download_exam_result_button,
3333
+ "action": download_exam_result,
3334
+ "inputs": [exit_ticket_exam_result],
3335
+ "outputs": [exit_ticket_exam_result_word_link]
3336
+ },
3337
+ {
3338
+ "button": exit_ticket_exam_result_retrun_original,
3339
+ "action": return_original_exam_result,
3340
+ "inputs": [exit_ticket_exam_result_original],
3341
+ "outputs": [exit_ticket_exam_result]
3342
+ }
3343
+ ]
3344
+ setup_education_buttons(education_buttons_config)
3345
 
3346
  # init_params
3347
  init_outputs = [