youngtsai commited on
Commit
c9b8261
·
1 Parent(s): 2b22105
Files changed (1) hide show
  1. app.py +17 -69
app.py CHANGED
@@ -579,7 +579,7 @@ def generate_paragraph(topic_sentence, supporting_sentences, conclusion_sentence
579
  paragraph = f"{topic_sentence} {supporting_sentences} {conclusion_sentence}"
580
  return paragraph
581
 
582
- def generate_paragraph_evaluate(model, max_tokens, sys_content, paragraph, user_generate_paragraph_evaluate_prompt):
583
  """
584
  根據用戶輸入的段落,調用 LLM API 生成相關的段落分析。
585
 
@@ -654,7 +654,7 @@ def generate_paragraph_evaluate(model, max_tokens, sys_content, paragraph, user_
654
  prompt=f"{sys_content}\n{user_content}" if "gemini" in model.lower() else None,
655
  messages=messages,
656
  model=model,
657
- max_tokens=max_tokens,
658
  response_format={"type": "json_object"}
659
  )
660
 
@@ -681,7 +681,7 @@ def generate_paragraph_evaluate(model, max_tokens, sys_content, paragraph, user_
681
  error_msg = handle_evaluation_error(e)
682
  raise gr.Error(error_msg)
683
 
684
- def generate_correct_grammatical_spelling_errors(model, max_tokens, sys_content, eng_level, paragraph, user_correct_grammatical_spelling_errors_prompt):
685
  """
686
  根據用戶輸入的段落,生成文法和拼字錯誤修正建議。
687
  """
@@ -712,7 +712,7 @@ def generate_correct_grammatical_spelling_errors(model, max_tokens, sys_content,
712
  prompt=f"{sys_content}\n{user_content}" if "gemini" in model.lower() else None,
713
  messages=messages,
714
  model=model,
715
- max_tokens=max_tokens,
716
  response_format={"type": "json_object"}
717
  )
718
 
@@ -796,7 +796,7 @@ def highlight_diff_texts(highlight_list, text):
796
  def update_paragraph_correct_grammatical_spelling_errors_input(paragraph):
797
  return paragraph
798
 
799
- def generate_refine_paragraph(model, max_tokens, sys_content, eng_level, paragraph, user_refine_paragraph_prompt):
800
  """
801
  根据用户输入的段落,调用 LLM API 生成相关的段落改善建議。
802
  """
@@ -3065,7 +3065,6 @@ with gr.Blocks(theme=THEME, css=CSS) as demo:
3065
  fn=generate_paragraph_evaluate,
3066
  inputs=[
3067
  model,
3068
- max_tokens,
3069
  sys_content_input,
3070
  paragraph_output,
3071
  user_generate_paragraph_evaluate_prompt
@@ -3086,7 +3085,6 @@ with gr.Blocks(theme=THEME, css=CSS) as demo:
3086
  fn=generate_correct_grammatical_spelling_errors,
3087
  inputs=[
3088
  model,
3089
- max_tokens,
3090
  sys_content_input,
3091
  eng_level_input,
3092
  paragraph_output,
@@ -3115,7 +3113,6 @@ with gr.Blocks(theme=THEME, css=CSS) as demo:
3115
  fn=generate_refine_paragraph,
3116
  inputs=[
3117
  model,
3118
- max_tokens,
3119
  sys_content_input,
3120
  eng_level_input,
3121
  paragraph_correct_grammatical_spelling_errors_input,
@@ -3275,7 +3272,7 @@ with gr.Blocks(theme=THEME, css=CSS) as demo:
3275
  generate_full_paragraph_refine_button = gr.Button("✨ JUTOR 段落改善建議", variant="primary")
3276
  full_paragraph_refine_output_table = gr.DataFrame(label="段落改善建議", wrap=True, interactive=False)
3277
  full_paragraph_refine_output = gr.HTML(label="改建議", visible=False)
3278
- gr.Markdown("## 修訂建議")
3279
  full_paragraph_refine_output_diff = gr.HTML()
3280
 
3281
  # 寫作完成
@@ -3316,13 +3313,7 @@ with gr.Blocks(theme=THEME, css=CSS) as demo:
3316
 
3317
  full_paragraph_evaluate_button.click(
3318
  fn=generate_paragraph_evaluate,
3319
- inputs=[
3320
- model,
3321
- max_tokens,
3322
- sys_content_input,
3323
- full_paragraph_input,
3324
- user_generate_full_paragraph_evaluate_prompt
3325
- ],
3326
  outputs=full_paragraph_evaluate_output
3327
  ).then(
3328
  fn=update_paragraph_correct_grammatical_spelling_errors_input,
@@ -3332,24 +3323,11 @@ with gr.Blocks(theme=THEME, css=CSS) as demo:
3332
 
3333
  generate_full_paragraph_correct_grammatical_spelling_errors_button.click(
3334
  fn=generate_correct_grammatical_spelling_errors,
3335
- inputs=[
3336
- model,
3337
- max_tokens,
3338
- sys_content_input,
3339
- eng_level_input,
3340
- full_paragraph_correct_grammatical_spelling_errors_input,
3341
- user_correct_grammatical_spelling_errors_prompt
3342
- ],
3343
- outputs=[
3344
- full_paragraph_correct_grammatical_spelling_errors_output_table,
3345
- revised_full_paragraph_output
3346
- ]
3347
  ).then(
3348
  fn=highlight_diff_texts,
3349
- inputs=[
3350
- full_paragraph_correct_grammatical_spelling_errors_output_table,
3351
- revised_full_paragraph_output
3352
- ],
3353
  outputs=revised_full_paragraph_diff
3354
  ).then(
3355
  fn=update_paragraph_refine_input,
@@ -3360,8 +3338,7 @@ with gr.Blocks(theme=THEME, css=CSS) as demo:
3360
  generate_full_paragraph_refine_button.click(
3361
  fn=generate_refine_paragraph,
3362
  inputs=[
3363
- model,
3364
- max_tokens,
3365
  sys_content_input,
3366
  eng_level_input,
3367
  full_paragraph_refine_input,
@@ -3582,13 +3559,7 @@ with gr.Blocks(theme=THEME, css=CSS) as demo:
3582
 
3583
  past_exam_evaluation_button.click(
3584
  fn=generate_paragraph_evaluate,
3585
- inputs=[
3586
- model,
3587
- max_tokens,
3588
- past_exam_evaluation_sys_content_prompt,
3589
- past_exam_evaluation_input,
3590
- past_exam_evaluation_user_prompt
3591
- ],
3592
  outputs=past_exam_evaluation_output
3593
  ).then(
3594
  fn=update_paragraph_correct_grammatical_spelling_errors_input,
@@ -3598,21 +3569,11 @@ with gr.Blocks(theme=THEME, css=CSS) as demo:
3598
 
3599
  past_exam_generate_correct_grammatical_spelling_errors_button.click(
3600
  fn=generate_correct_grammatical_spelling_errors,
3601
- inputs=[
3602
- model,
3603
- max_tokens,
3604
- past_exam_evaluation_sys_content_prompt,
3605
- eng_level_input,
3606
- past_exam_correct_grammatical_spelling_errors_input,
3607
- past_exam_correct_grammatical_spelling_errors_prompt
3608
- ],
3609
  outputs=[past_exam_correct_grammatical_spelling_errors_output_table, past_exam_revised_output]
3610
  ).then(
3611
  fn=highlight_diff_texts,
3612
- inputs=[
3613
- past_exam_correct_grammatical_spelling_errors_output_table,
3614
- past_exam_revised_output
3615
- ],
3616
  outputs=past_exam_revised_diff
3617
  ).then(
3618
  fn=update_paragraph_refine_input,
@@ -3622,24 +3583,11 @@ with gr.Blocks(theme=THEME, css=CSS) as demo:
3622
 
3623
  past_exam_generate_refine_button.click(
3624
  fn=generate_refine_paragraph,
3625
- inputs=[
3626
- model,
3627
- max_tokens,
3628
- past_exam_evaluation_sys_content_prompt,
3629
- eng_level_input,
3630
- past_exam_refine_input,
3631
- past_exam_refine_paragraph_prompt
3632
- ],
3633
- outputs=[
3634
- past_exam_refine_output_table,
3635
- past_exam_refine_output
3636
- ]
3637
  ).then(
3638
  fn=highlight_diff_texts,
3639
- inputs=[
3640
- past_exam_refine_output_table,
3641
- past_exam_refine_output
3642
- ],
3643
  outputs=past_exam_refine_output_diff
3644
  )
3645
 
 
579
  paragraph = f"{topic_sentence} {supporting_sentences} {conclusion_sentence}"
580
  return paragraph
581
 
582
+ def generate_paragraph_evaluate(model, sys_content, paragraph, user_generate_paragraph_evaluate_prompt):
583
  """
584
  根據用戶輸入的段落,調用 LLM API 生成相關的段落分析。
585
 
 
654
  prompt=f"{sys_content}\n{user_content}" if "gemini" in model.lower() else None,
655
  messages=messages,
656
  model=model,
657
+ max_tokens=4000,
658
  response_format={"type": "json_object"}
659
  )
660
 
 
681
  error_msg = handle_evaluation_error(e)
682
  raise gr.Error(error_msg)
683
 
684
+ def generate_correct_grammatical_spelling_errors(model, sys_content, eng_level, paragraph, user_correct_grammatical_spelling_errors_prompt):
685
  """
686
  根據用戶輸入的段落,生成文法和拼字錯誤修正建議。
687
  """
 
712
  prompt=f"{sys_content}\n{user_content}" if "gemini" in model.lower() else None,
713
  messages=messages,
714
  model=model,
715
+ max_tokens=4000,
716
  response_format={"type": "json_object"}
717
  )
718
 
 
796
  def update_paragraph_correct_grammatical_spelling_errors_input(paragraph):
797
  return paragraph
798
 
799
+ def generate_refine_paragraph(model, sys_content, eng_level, paragraph, user_refine_paragraph_prompt):
800
  """
801
  根据用户输入的段落,调用 LLM API 生成相关的段落改善建議。
802
  """
 
3065
  fn=generate_paragraph_evaluate,
3066
  inputs=[
3067
  model,
 
3068
  sys_content_input,
3069
  paragraph_output,
3070
  user_generate_paragraph_evaluate_prompt
 
3085
  fn=generate_correct_grammatical_spelling_errors,
3086
  inputs=[
3087
  model,
 
3088
  sys_content_input,
3089
  eng_level_input,
3090
  paragraph_output,
 
3113
  fn=generate_refine_paragraph,
3114
  inputs=[
3115
  model,
 
3116
  sys_content_input,
3117
  eng_level_input,
3118
  paragraph_correct_grammatical_spelling_errors_input,
 
3272
  generate_full_paragraph_refine_button = gr.Button("✨ JUTOR 段落改善建議", variant="primary")
3273
  full_paragraph_refine_output_table = gr.DataFrame(label="段落改善建議", wrap=True, interactive=False)
3274
  full_paragraph_refine_output = gr.HTML(label="改建議", visible=False)
3275
+ gr.Markdown("## 修改建議")
3276
  full_paragraph_refine_output_diff = gr.HTML()
3277
 
3278
  # 寫作完成
 
3313
 
3314
  full_paragraph_evaluate_button.click(
3315
  fn=generate_paragraph_evaluate,
3316
+ inputs=[model, sys_content_input, full_paragraph_input, user_generate_full_paragraph_evaluate_prompt],
 
 
 
 
 
 
3317
  outputs=full_paragraph_evaluate_output
3318
  ).then(
3319
  fn=update_paragraph_correct_grammatical_spelling_errors_input,
 
3323
 
3324
  generate_full_paragraph_correct_grammatical_spelling_errors_button.click(
3325
  fn=generate_correct_grammatical_spelling_errors,
3326
+ inputs=[model, sys_content_input, eng_level_input, full_paragraph_correct_grammatical_spelling_errors_input, user_correct_grammatical_spelling_errors_prompt],
3327
+ outputs=[full_paragraph_correct_grammatical_spelling_errors_output_table, revised_full_paragraph_output]
 
 
 
 
 
 
 
 
 
 
3328
  ).then(
3329
  fn=highlight_diff_texts,
3330
+ inputs=[full_paragraph_correct_grammatical_spelling_errors_output_table, revised_full_paragraph_output],
 
 
 
3331
  outputs=revised_full_paragraph_diff
3332
  ).then(
3333
  fn=update_paragraph_refine_input,
 
3338
  generate_full_paragraph_refine_button.click(
3339
  fn=generate_refine_paragraph,
3340
  inputs=[
3341
+ model,
 
3342
  sys_content_input,
3343
  eng_level_input,
3344
  full_paragraph_refine_input,
 
3559
 
3560
  past_exam_evaluation_button.click(
3561
  fn=generate_paragraph_evaluate,
3562
+ inputs=[model, past_exam_evaluation_sys_content_prompt, past_exam_evaluation_input, past_exam_evaluation_user_prompt],
 
 
 
 
 
 
3563
  outputs=past_exam_evaluation_output
3564
  ).then(
3565
  fn=update_paragraph_correct_grammatical_spelling_errors_input,
 
3569
 
3570
  past_exam_generate_correct_grammatical_spelling_errors_button.click(
3571
  fn=generate_correct_grammatical_spelling_errors,
3572
+ inputs=[model, past_exam_evaluation_sys_content_prompt, eng_level_input, past_exam_correct_grammatical_spelling_errors_input, past_exam_correct_grammatical_spelling_errors_prompt],
 
 
 
 
 
 
 
3573
  outputs=[past_exam_correct_grammatical_spelling_errors_output_table, past_exam_revised_output]
3574
  ).then(
3575
  fn=highlight_diff_texts,
3576
+ inputs=[past_exam_correct_grammatical_spelling_errors_output_table, past_exam_revised_output],
 
 
 
3577
  outputs=past_exam_revised_diff
3578
  ).then(
3579
  fn=update_paragraph_refine_input,
 
3583
 
3584
  past_exam_generate_refine_button.click(
3585
  fn=generate_refine_paragraph,
3586
+ inputs=[model, past_exam_evaluation_sys_content_prompt, eng_level_input, past_exam_refine_input, past_exam_refine_paragraph_prompt],
3587
+ outputs=[past_exam_refine_output_table, past_exam_refine_output]
 
 
 
 
 
 
 
 
 
 
3588
  ).then(
3589
  fn=highlight_diff_texts,
3590
+ inputs=[past_exam_refine_output_table, past_exam_refine_output],
 
 
 
3591
  outputs=past_exam_refine_output_diff
3592
  )
3593