youngtsai commited on
Commit
07a55ac
·
1 Parent(s): d585564
Files changed (1) hide show
  1. app.py +86 -63
app.py CHANGED
@@ -32,8 +32,9 @@ def generate_topics(model, max_tokens, sys_content, scenario, eng_level, user_ge
32
  根据系统提示和用户输入的情境及主题,调用OpenAI API生成相关的主题句。
33
  """
34
  user_content = f"""
35
- scenario is {scenario}
36
- english level is {eng_level}
 
37
  {user_generate_topics_prompt}
38
  """
39
  messages = [
@@ -64,9 +65,10 @@ def generate_points(model, max_tokens, sys_content, scenario, eng_level, topic,
64
  根据系统提示和用户输入的情境、主题,调用OpenAI API生成相关的主题句。
65
  """
66
  user_content = f"""
67
- scenario is {scenario}
68
- english level is {eng_level}
69
- topic is {topic}
 
70
  {user_generate_points_prompt}
71
  """
72
  messages = [
@@ -97,10 +99,11 @@ def generate_topic_sentences(model, max_tokens, sys_content, scenario, eng_level
97
  根据系统提示和用户输入的情境及要点,调用OpenAI API生成相关的主题句及其合理性解释。
98
  """
99
  user_content = f"""
100
- scenario is {scenario}
101
- english level is {eng_level}
102
- topic is {topic}
103
- points is {points}
 
104
  {user_generate_topic_sentences_prompt}
105
  """
106
  messages = [
@@ -153,11 +156,12 @@ def generate_supporting_sentences(model, max_tokens, sys_content, scenario, eng_
153
  根据系统提示和用户输入的情境、主题、要点、主题句,调用OpenAI API生成相关的支持句。
154
  """
155
  user_content = f"""
156
- scenario is {scenario}
157
- english level is {eng_level}
158
- topic is {topic}
159
- points is {points}
160
- topic sentence is {topic_sentence}
 
161
  {user_generate_supporting_sentences_prompt}
162
  """
163
  messages = [
@@ -185,11 +189,12 @@ def generate_conclusion_sentences(model, max_tokens, sys_content, scenario, eng_
185
  根据系统提示和用户输入的情境、主题、要点、主题句,调用OpenAI API生成相关的结论句。
186
  """
187
  user_content = f"""
188
- scenario is {scenario}
189
- english level is {eng_level}
190
- topic is {topic}
191
- points is {points}
192
- topic sentence is {topic_sentence}
 
193
  {user_generate_conclusion_sentence_prompt}
194
  """
195
  messages = [
@@ -221,12 +226,13 @@ def generate_paragraph(topic_sentence, supporting_sentences, conclusion_sentence
221
  paragraph = f"{topic_sentence} {supporting_sentences} {conclusion_sentence}"
222
  return paragraph
223
 
224
- def generate_paragraph_evaluate(sys_content, paragraph, user_generate_paragraph_evaluate_prompt):
225
  """
226
  根据用户输入的段落,调用OpenAI API生成相关的段落分析。
227
  """
228
  user_content = f"""
229
- paragraph is {paragraph}
 
230
  {user_generate_paragraph_evaluate_prompt}
231
  """
232
  messages = [
@@ -237,7 +243,7 @@ def generate_paragraph_evaluate(sys_content, paragraph, user_generate_paragraph_
237
  response_format = { "type": "json_object" }
238
 
239
  request_payload = {
240
- "model": "gpt-3.5-turbo",
241
  "messages": messages,
242
  "max_tokens": 2000,
243
  "response_format": response_format
@@ -263,13 +269,14 @@ def generate_paragraph_evaluate(sys_content, paragraph, user_generate_paragraph_
263
  return gr_update
264
 
265
 
266
- def generate_correct_grammatical_spelling_errors(sys_content, eng_level, paragraph, user_correct_grammatical_spelling_errors_prompt):
267
  """
268
  根据用户输入的段落,调用OpenAI API生成相关的文法和拼字错误修正。
269
  """
270
  user_content = f"""
271
- level is {eng_level}
272
- paragraph is {paragraph}
 
273
  {user_correct_grammatical_spelling_errors_prompt}
274
  """
275
  messages = [
@@ -278,7 +285,7 @@ def generate_correct_grammatical_spelling_errors(sys_content, eng_level, paragra
278
  ]
279
  response_format = { "type": "json_object" }
280
  request_payload = {
281
- "model": "gpt-3.5-turbo",
282
  "messages": messages,
283
  "max_tokens": 1000,
284
  "response_format": response_format
@@ -326,13 +333,14 @@ def highlight_diff_texts(highlight_list, text):
326
  def update_paragraph_correct_grammatical_spelling_errors_input(paragraph):
327
  return paragraph
328
 
329
- def generate_refine_paragraph(sys_content, eng_level, paragraph, user_refine_paragraph_prompt):
330
  """
331
  根据用户输入的段落,调用OpenAI API生成相关的段落改善建议。
332
  """
333
  user_content = f"""
334
- eng_level is {eng_level}
335
- paragraph is {paragraph}
 
336
  {user_refine_paragraph_prompt}
337
  """
338
  messages = [
@@ -343,7 +351,7 @@ def generate_refine_paragraph(sys_content, eng_level, paragraph, user_refine_par
343
  response_format = { "type": "json_object" }
344
 
345
  request_payload = {
346
- "model": "gpt-3.5-turbo",
347
  "messages": messages,
348
  "max_tokens": 4000,
349
  "response_format": response_format
@@ -425,7 +433,7 @@ def update_history_accordion():
425
  return history_accordion_gr_update
426
 
427
 
428
- def generate_chinese_evaluation_table(sys_content, user_prompt, text):
429
  # https://www.ceec.edu.tw/files/file_pool/1/0j052575870800204600/1216%E5%9C%8B%E6%96%87%E4%BD%9C%E6%96%87%E5%88%86%E9%A0%85%E5%BC%8F%E8%A9%95%E5%88%86%E6%8C%87%E6%A8%99.pdf
430
 
431
  user_content = f"""
@@ -441,7 +449,7 @@ def generate_chinese_evaluation_table(sys_content, user_prompt, text):
441
  response_format = { "type": "json_object" }
442
 
443
  request_payload = {
444
- "model": "gpt-4-turbo",
445
  "messages": messages,
446
  "max_tokens": 2000,
447
  "response_format": response_format
@@ -489,7 +497,7 @@ with gr.Blocks(theme=gr.themes.Soft(primary_hue=gr.themes.colors.blue, secondary
489
  with gr.Tab(label="英文段落寫作練習"):
490
  # ===== 基礎級使用者 =====
491
  with gr.Row(visible=False) as default_params:
492
- model = gr.Radio(["gpt-4-turbo", "gpt-3.5-turbo"], label="Model", value="gpt-4-turbo")
493
  max_tokens = gr.Slider(minimum=50, maximum=4000, value=4000, label="Max Tokens")
494
  sys_content_input = gr.Textbox(label="System Prompt", value="You are an English teacher who is practicing with me to improve my English writing skill.")
495
  eng_level_input = gr.Radio(["beginner", "intermediate", "advanced"], label="English Level", value="beginner")
@@ -533,7 +541,7 @@ with gr.Blocks(theme=gr.themes.Soft(primary_hue=gr.themes.colors.blue, secondary
533
  outputs=[scenario_input]
534
  )
535
 
536
- # Step 2. 確定段落主題
537
  with gr.Row():
538
  with gr.Column():
539
  with gr.Row():
@@ -588,7 +596,7 @@ with gr.Blocks(theme=gr.themes.Soft(primary_hue=gr.themes.colors.blue, secondary
588
  )
589
  return topic_radio
590
 
591
- # Step 3. 寫出段落要點
592
  with gr.Row():
593
  with gr.Column():
594
  with gr.Row() as points_params:
@@ -640,7 +648,7 @@ with gr.Blocks(theme=gr.themes.Soft(primary_hue=gr.themes.colors.blue, secondary
640
  )
641
  return points_radio
642
 
643
- # Step 4. 選定主題句
644
  with gr.Row():
645
  with gr.Column():
646
  with gr.Row() as topic_sentences_params:
@@ -716,7 +724,7 @@ with gr.Blocks(theme=gr.themes.Soft(primary_hue=gr.themes.colors.blue, secondary
716
 
717
  return topic_sentences_radio
718
 
719
- # Step 5.寫出完整段落
720
  with gr.Row():
721
  with gr.Column():
722
  with gr.Row() as supporting_sentences_params:
@@ -742,12 +750,13 @@ with gr.Blocks(theme=gr.themes.Soft(primary_hue=gr.themes.colors.blue, secondary
742
  user_generate_supporting_sentences_prompt = gr.Textbox(label="Supporting Sentences Prompt", value=default_generate_supporting_sentences_prompt, visible=False)
743
 
744
  with gr.Row() as supporting_sentences_html:
745
- gr.Markdown("# Step 5.寫出完整段落")
746
- with gr.Row():
747
- gr.Markdown("## 請根據主題句,練習寫出 「支持句」及「結論句」來完成一個完整的段落。")
748
  with gr.Row():
749
  with gr.Column():
750
- gr.Markdown("### 支持句:以支持句來解釋要點,必要時舉例説明,來支持主題句。這些句子應該按照邏輯順序來組織,例如時間順序、空間順序、重要性順序、因果關係等。並使用轉折詞���引導讀者從一個 idea 到下一個 idea,讓讀者讀起來很順暢,不需反覆閱讀。")
 
 
 
751
  with gr.Column():
752
  with gr.Accordion("參考指引:撰寫支持句的方法?", open=False):
753
  gr.Markdown("""
@@ -761,13 +770,13 @@ with gr.Blocks(theme=gr.themes.Soft(primary_hue=gr.themes.colors.blue, secondary
761
  """)
762
  with gr.Accordion("參考指引:針對要點的支持句,要寫幾句呢?", open=False):
763
  gr.Markdown("""
764
- - 一個要點,寫 3-6 句
765
- - 兩個要點,每個要點寫 2-3 句
766
- - 三個要點,每個要點寫 1-2 句
767
  """)
768
  with gr.Row():
769
  with gr.Column():
770
- gr.Markdown("### 寫出關於 focus 的支持句")
771
  supporting_sentences_input = gr.Textbox(label="Supporting Sentences")
772
  with gr.Column():
773
  generate_supporting_sentences_button = gr.Button("讓 JUTOR 產生例句,幫助你撰寫支持句。", variant="primary")
@@ -795,7 +804,7 @@ with gr.Blocks(theme=gr.themes.Soft(primary_hue=gr.themes.colors.blue, secondary
795
  outputs= [supporting_sentences_input]
796
  )
797
 
798
- # Step 6. 寫出結論句
799
  with gr.Row():
800
  with gr.Column():
801
  with gr.Row() as conclusion_sentences_params:
@@ -826,7 +835,7 @@ with gr.Blocks(theme=gr.themes.Soft(primary_hue=gr.themes.colors.blue, secondary
826
  with gr.Column():
827
  gr.Markdown("## 總結主要觀點,強化整個資訊的傳遞。重述、摘要、回應或評論主題句。")
828
  with gr.Column():
829
- with gr.Accordion("參考指引:撰寫結論句的方法?", open=False):
830
  gr.Markdown("""
831
  - 以換句話說 (paraphrase) 的方式把主題句再說一次
832
  - 摘要三要點方式寫結論句
@@ -861,11 +870,11 @@ with gr.Blocks(theme=gr.themes.Soft(primary_hue=gr.themes.colors.blue, secondary
861
  outputs= [conclusion_sentence_input]
862
  )
863
 
864
- # Step 7. 段落確認與修訂
865
  with gr.Row():
866
  with gr.Column():
867
  with gr.Row():
868
- gr.Markdown("# Step 7. 段落確認與修訂")
869
  with gr.Row():
870
  with gr.Column():
871
  gr.Markdown("""### 你已經完成段落草稿,可再檢視幾次:
@@ -997,6 +1006,7 @@ with gr.Blocks(theme=gr.themes.Soft(primary_hue=gr.themes.colors.blue, secondary
997
  generate_paragraph_evaluate_button.click(
998
  fn=generate_paragraph_evaluate,
999
  inputs=[
 
1000
  sys_content_input,
1001
  paragraph_output,
1002
  user_generate_paragraph_evaluate_prompt
@@ -1012,14 +1022,19 @@ with gr.Blocks(theme=gr.themes.Soft(primary_hue=gr.themes.colors.blue, secondary
1012
  I'm aiming to improve my writing.
1013
  Please assist me by "Correcting Grammatical and Spelling Errors" in the provided paragraph.
1014
  For every correction you make, I'd like an "Explanation" to understand the reasoning behind it.
 
 
1015
  - Paragraph for Correction: [paragraph split by punctuation mark]
1016
  - The sentence to remain unchanged: [sentence_to_remain_unchanged]
1017
  - When explaining, use Traditional Chinese (Taiwan, 繁體中文) for clarity.
1018
  - But others(original, Correction, revised_paragraph) in English.
1019
  - Make sure any revised vocabulary aligns with the eng_level.
 
 
 
1020
  Guidelines for Length and Complexity:
1021
  - Please keep explanations concise and straightforward
1022
- - if no more suggestions, please provide at least 2 suggestions and explain that the paragraph is another possible way to improve.
1023
 
1024
  Restrictions:
1025
  - avoiding overly technical language.
@@ -1057,7 +1072,7 @@ with gr.Blocks(theme=gr.themes.Soft(primary_hue=gr.themes.colors.blue, secondary
1057
  with gr.Column():
1058
  paragraph_correct_grammatical_spelling_errors_input = gr.Textbox(label="這是你的原始寫作內容,參考 JUTOR 的改正,你可以選擇是否修改:")
1059
  with gr.Column():
1060
- generate_correct_grammatical_spelling_errors_button = gr.Button("JUTOR 修訂", variant="primary")
1061
  correct_grammatical_spelling_errors_output_table = gr.Dataframe(label="修訂文法與拼字錯誤", interactive=False)
1062
  revised_paragraph_output = gr.Textbox(label="Revised Paragraph", show_copy_button=True, visible=False)
1063
  gr.Markdown("## 修訂結果")
@@ -1066,6 +1081,7 @@ with gr.Blocks(theme=gr.themes.Soft(primary_hue=gr.themes.colors.blue, secondary
1066
  generate_correct_grammatical_spelling_errors_button.click(
1067
  fn=generate_correct_grammatical_spelling_errors,
1068
  inputs=[
 
1069
  sys_content_input,
1070
  eng_level_input,
1071
  paragraph_output,
@@ -1099,7 +1115,7 @@ with gr.Blocks(theme=gr.themes.Soft(primary_hue=gr.themes.colors.blue, secondary
1099
 
1100
  Guidelines for Length and Complexity:
1101
  - Please keep explanations concise and straightforward
1102
- - if totally no more suggestions, please provide at least 2 suggestions and explain that the paragraph is another possible way to improve.
1103
 
1104
  Restrictions:
1105
  - avoiding overly technical language.
@@ -1139,6 +1155,7 @@ with gr.Blocks(theme=gr.themes.Soft(primary_hue=gr.themes.colors.blue, secondary
1139
  generate_refine_paragraph_button.click(
1140
  fn=generate_refine_paragraph,
1141
  inputs=[
 
1142
  sys_content_input,
1143
  eng_level_input,
1144
  paragraph_correct_grammatical_spelling_errors_input,
@@ -1252,7 +1269,7 @@ with gr.Blocks(theme=gr.themes.Soft(primary_hue=gr.themes.colors.blue, secondary
1252
  with gr.Column():
1253
  full_paragraph_correct_grammatical_spelling_errors_input = gr.Textbox(label="這是你的原始寫作內容,參考 JUTOR 的建議,你可以選擇是否修改:")
1254
  with gr.Column():
1255
- generate_full_paragraph_correct_grammatical_spelling_errors_button = gr.Button("JUTOR 修訂", variant="primary")
1256
  full_paragraph_correct_grammatical_spelling_errors_output_table = gr.Dataframe(label="修訂文法與拼字錯誤", interactive=False, column_widths=[30, 30, 40])
1257
  revised_full_paragraph_output = gr.Textbox(label="Revised Paragraph", show_copy_button=True, visible=False)
1258
  gr.Markdown("## 修訂結果")
@@ -1285,7 +1302,7 @@ with gr.Blocks(theme=gr.themes.Soft(primary_hue=gr.themes.colors.blue, secondary
1285
 
1286
  full_paragraph_evaluate_button.click(
1287
  fn=generate_paragraph_evaluate,
1288
- inputs=[sys_content_input, full_paragraph_input, user_generate_full_paragraph_evaluate_prompt],
1289
  outputs=full_paragraph_evaluate_output
1290
  ).then(
1291
  fn=update_paragraph_correct_grammatical_spelling_errors_input,
@@ -1295,7 +1312,7 @@ with gr.Blocks(theme=gr.themes.Soft(primary_hue=gr.themes.colors.blue, secondary
1295
 
1296
  generate_full_paragraph_correct_grammatical_spelling_errors_button.click(
1297
  fn=generate_correct_grammatical_spelling_errors,
1298
- inputs=[sys_content_input, eng_level_input, full_paragraph_correct_grammatical_spelling_errors_input, user_correct_grammatical_spelling_errors_prompt],
1299
  outputs=[full_paragraph_correct_grammatical_spelling_errors_output_table, revised_full_paragraph_output]
1300
  ).then(
1301
  fn=highlight_diff_texts,
@@ -1309,7 +1326,13 @@ with gr.Blocks(theme=gr.themes.Soft(primary_hue=gr.themes.colors.blue, secondary
1309
 
1310
  generate_full_paragraph_refine_button.click(
1311
  fn=generate_refine_paragraph,
1312
- inputs=[sys_content_input, eng_level_input, full_paragraph_refine_input, user_refine_paragraph_prompt],
 
 
 
 
 
 
1313
  outputs=[full_paragraph_refine_output_table, full_paragraph_refine_output]
1314
  ).then(
1315
  fn=highlight_diff_texts,
@@ -1403,7 +1426,7 @@ with gr.Blocks(theme=gr.themes.Soft(primary_hue=gr.themes.colors.blue, secondary
1403
  with gr.Column():
1404
  chinese_full_paragraph_correct_grammatical_spelling_errors_input = gr.Textbox(label="這是你的原始寫作內容,參考 JUTOR 的建議,你可以選擇是否修改:")
1405
  with gr.Column():
1406
- generate_chinese_full_paragraph_correct_grammatical_spelling_errors_button = gr.Button("JUTOR 修訂", variant="primary")
1407
  chinese_full_paragraph_correct_grammatical_spelling_errors_output_table = gr.Dataframe(label="修訂文法與拼字錯誤", interactive=False, column_widths=[30, 30, 40])
1408
  revised_chinese_full_paragraph_output = gr.Textbox(label="Revised Paragraph", show_copy_button=True, visible=False)
1409
  gr.Markdown("## 修訂結果")
@@ -1436,7 +1459,7 @@ with gr.Blocks(theme=gr.themes.Soft(primary_hue=gr.themes.colors.blue, secondary
1436
 
1437
  chinese_full_paragraph_evaluate_button.click(
1438
  fn=generate_chinese_evaluation_table,
1439
- inputs=[chinese_full_paragraph_sys_content_input, user_generate_chinese_full_paragraph_evaluate_prompt, chinese_full_paragraph_input],
1440
  outputs=chinese_full_paragraph_evaluate_output
1441
  ).then(
1442
  fn=update_paragraph_correct_grammatical_spelling_errors_input,
@@ -1446,7 +1469,7 @@ with gr.Blocks(theme=gr.themes.Soft(primary_hue=gr.themes.colors.blue, secondary
1446
 
1447
  generate_chinese_full_paragraph_correct_grammatical_spelling_errors_button.click(
1448
  fn=generate_correct_grammatical_spelling_errors,
1449
- inputs=[chinese_full_paragraph_sys_content_input, eng_level_input, chinese_full_paragraph_correct_grammatical_spelling_errors_input, user_correct_grammatical_spelling_errors_prompt],
1450
  outputs=[chinese_full_paragraph_correct_grammatical_spelling_errors_output_table, revised_chinese_full_paragraph_output]
1451
  ).then(
1452
  fn=highlight_diff_texts,
@@ -1460,7 +1483,7 @@ with gr.Blocks(theme=gr.themes.Soft(primary_hue=gr.themes.colors.blue, secondary
1460
 
1461
  generate_chinese_full_paragraph_refine_button.click(
1462
  fn=generate_refine_paragraph,
1463
- inputs=[chinese_full_paragraph_sys_content_input, eng_level_input, chinese_full_paragraph_refine_input, user_refine_paragraph_prompt],
1464
  outputs=[chinese_full_paragraph_refine_output_table, chinese_full_paragraph_refine_output]
1465
  ).then(
1466
  fn=highlight_diff_texts,
@@ -1506,7 +1529,7 @@ with gr.Blocks(theme=gr.themes.Soft(primary_hue=gr.themes.colors.blue, secondary
1506
  )
1507
 
1508
  # 評分
1509
- with gr.Row(visible=False):
1510
  with gr.Column():
1511
  with gr.Row():
1512
  past_exam_evaluation_sys_content_prompt = gr.Textbox(label="System Prompt", value="You are an English teacher who is practicing with me to improve my English writing skill.", visible=False)
@@ -1527,7 +1550,7 @@ with gr.Blocks(theme=gr.themes.Soft(primary_hue=gr.themes.colors.blue, secondary
1527
  with gr.Accordion("prompt 提供微調測試", open=False, elem_classes=['accordion-prompts']):
1528
  past_exam_correct_grammatical_spelling_errors_prompt = gr.Textbox(label="Correct Grammatical and Spelling Errors Prompt", value=default_user_correct_grammatical_spelling_errors_prompt, lines= 20)
1529
  with gr.Row():
1530
- past_exam_generate_correct_grammatical_spelling_errors_button = gr.Button("JUTOR 修訂", variant="primary")
1531
  with gr.Row():
1532
  past_exam_correct_grammatical_spelling_errors_output_table = gr.Dataframe(label="修訂文法與拼字錯誤", interactive=False, column_widths=[30, 30, 40])
1533
  with gr.Row():
@@ -1568,7 +1591,7 @@ with gr.Blocks(theme=gr.themes.Soft(primary_hue=gr.themes.colors.blue, secondary
1568
 
1569
  past_exam_generate_correct_grammatical_spelling_errors_button.click(
1570
  fn=generate_correct_grammatical_spelling_errors,
1571
- inputs=[past_exam_evaluation_sys_content_prompt, eng_level_input, past_exam_correct_grammatical_spelling_errors_input, past_exam_correct_grammatical_spelling_errors_prompt],
1572
  outputs=[past_exam_correct_grammatical_spelling_errors_output_table, past_exam_revised_output]
1573
  ).then(
1574
  fn=highlight_diff_texts,
 
32
  根据系统提示和用户输入的情境及主题,调用OpenAI API生成相关的主题句。
33
  """
34
  user_content = f"""
35
+ scenario is: {scenario}
36
+ english level is: {eng_level}
37
+ ---
38
  {user_generate_topics_prompt}
39
  """
40
  messages = [
 
65
  根据系统提示和用户输入的情境、主题,调用OpenAI API生成相关的主题句。
66
  """
67
  user_content = f"""
68
+ scenario is: {scenario}
69
+ english level is: {eng_level}
70
+ topic is: {topic}
71
+ ---
72
  {user_generate_points_prompt}
73
  """
74
  messages = [
 
99
  根据系统提示和用户输入的情境及要点,调用OpenAI API生成相关的主题句及其合理性解释。
100
  """
101
  user_content = f"""
102
+ scenario is: {scenario}
103
+ english level is: {eng_level}
104
+ topic is: {topic}
105
+ points is: {points}
106
+ ---
107
  {user_generate_topic_sentences_prompt}
108
  """
109
  messages = [
 
156
  根据系统提示和用户输入的情境、主题、要点、主题句,调用OpenAI API生成相关的支持句。
157
  """
158
  user_content = f"""
159
+ scenario is: {scenario}
160
+ english level is: {eng_level}
161
+ topic is: {topic}
162
+ points is: {points}
163
+ topic sentence is: {topic_sentence}
164
+ ---
165
  {user_generate_supporting_sentences_prompt}
166
  """
167
  messages = [
 
189
  根据系统提示和用户输入的情境、主题、要点、主题句,调用OpenAI API生成相关的结论句。
190
  """
191
  user_content = f"""
192
+ scenario is: {scenario}
193
+ english level is: {eng_level}
194
+ topic is: {topic}
195
+ points is: {points}
196
+ topic sentence is: {topic_sentence}
197
+ ---
198
  {user_generate_conclusion_sentence_prompt}
199
  """
200
  messages = [
 
226
  paragraph = f"{topic_sentence} {supporting_sentences} {conclusion_sentence}"
227
  return paragraph
228
 
229
+ def generate_paragraph_evaluate(model, sys_content, paragraph, user_generate_paragraph_evaluate_prompt):
230
  """
231
  根据用户输入的段落,调用OpenAI API生成相关的段落分析。
232
  """
233
  user_content = f"""
234
+ paragraph is: {paragraph}
235
+ ---
236
  {user_generate_paragraph_evaluate_prompt}
237
  """
238
  messages = [
 
243
  response_format = { "type": "json_object" }
244
 
245
  request_payload = {
246
+ "model": model,
247
  "messages": messages,
248
  "max_tokens": 2000,
249
  "response_format": response_format
 
269
  return gr_update
270
 
271
 
272
+ def generate_correct_grammatical_spelling_errors(model, sys_content, eng_level, paragraph, user_correct_grammatical_spelling_errors_prompt):
273
  """
274
  根据用户输入的段落,调用OpenAI API生成相关的文法和拼字错误修正。
275
  """
276
  user_content = f"""
277
+ level is: {eng_level}
278
+ paragraph is: {paragraph}
279
+ ---
280
  {user_correct_grammatical_spelling_errors_prompt}
281
  """
282
  messages = [
 
285
  ]
286
  response_format = { "type": "json_object" }
287
  request_payload = {
288
+ "model": model,
289
  "messages": messages,
290
  "max_tokens": 1000,
291
  "response_format": response_format
 
333
  def update_paragraph_correct_grammatical_spelling_errors_input(paragraph):
334
  return paragraph
335
 
336
+ def generate_refine_paragraph(model, sys_content, eng_level, paragraph, user_refine_paragraph_prompt):
337
  """
338
  根据用户输入的段落,调用OpenAI API生成相关的段落改善建议。
339
  """
340
  user_content = f"""
341
+ eng_level is: {eng_level}
342
+ paragraph is: {paragraph}
343
+ ---
344
  {user_refine_paragraph_prompt}
345
  """
346
  messages = [
 
351
  response_format = { "type": "json_object" }
352
 
353
  request_payload = {
354
+ "model": model,
355
  "messages": messages,
356
  "max_tokens": 4000,
357
  "response_format": response_format
 
433
  return history_accordion_gr_update
434
 
435
 
436
+ def generate_chinese_evaluation_table(model, sys_content, user_prompt, text):
437
  # https://www.ceec.edu.tw/files/file_pool/1/0j052575870800204600/1216%E5%9C%8B%E6%96%87%E4%BD%9C%E6%96%87%E5%88%86%E9%A0%85%E5%BC%8F%E8%A9%95%E5%88%86%E6%8C%87%E6%A8%99.pdf
438
 
439
  user_content = f"""
 
449
  response_format = { "type": "json_object" }
450
 
451
  request_payload = {
452
+ "model": model,
453
  "messages": messages,
454
  "max_tokens": 2000,
455
  "response_format": response_format
 
497
  with gr.Tab(label="英文段落寫作練習"):
498
  # ===== 基礎級使用者 =====
499
  with gr.Row(visible=False) as default_params:
500
+ model = gr.Radio(["gpt-4o", "gpt-4-turbo"], label="Model", value="gpt-4o")
501
  max_tokens = gr.Slider(minimum=50, maximum=4000, value=4000, label="Max Tokens")
502
  sys_content_input = gr.Textbox(label="System Prompt", value="You are an English teacher who is practicing with me to improve my English writing skill.")
503
  eng_level_input = gr.Radio(["beginner", "intermediate", "advanced"], label="English Level", value="beginner")
 
541
  outputs=[scenario_input]
542
  )
543
 
544
+ # Step 1. 確定段落主題
545
  with gr.Row():
546
  with gr.Column():
547
  with gr.Row():
 
596
  )
597
  return topic_radio
598
 
599
+ # Step 2. 寫出關鍵字
600
  with gr.Row():
601
  with gr.Column():
602
  with gr.Row() as points_params:
 
648
  )
649
  return points_radio
650
 
651
+ # Step 3. 選定主題句
652
  with gr.Row():
653
  with gr.Column():
654
  with gr.Row() as topic_sentences_params:
 
724
 
725
  return topic_sentences_radio
726
 
727
+ # Step 4.寫出支持句
728
  with gr.Row():
729
  with gr.Column():
730
  with gr.Row() as supporting_sentences_params:
 
750
  user_generate_supporting_sentences_prompt = gr.Textbox(label="Supporting Sentences Prompt", value=default_generate_supporting_sentences_prompt, visible=False)
751
 
752
  with gr.Row() as supporting_sentences_html:
753
+ gr.Markdown("# Step 4. 寫出支持句")
 
 
754
  with gr.Row():
755
  with gr.Column():
756
+ with gr.Row():
757
+ gr.Markdown("## 請根據主題句,練習寫出支持句")
758
+ with gr.Row():
759
+ gr.Markdown("### 支持句:以支持句來解釋要點,必要時舉例説明,來支持主題句。這些句子應該按照邏輯順序來組織,例如時間順序、空間順序、重要性順序、因果關係等。並使用轉折詞來引導讀者從一個 idea 到下一個 idea,讓讀者讀起來很順暢,不需反覆閱讀。")
760
  with gr.Column():
761
  with gr.Accordion("參考指引:撰寫支持句的方法?", open=False):
762
  gr.Markdown("""
 
770
  """)
771
  with gr.Accordion("參考指引:針對要點的支持句,要寫幾句呢?", open=False):
772
  gr.Markdown("""
773
+ - 一個關鍵字,寫 3-6 句
774
+ - 兩個關鍵字,每個要點寫 2-3 句
775
+ - 三個關鍵字,每個要點寫 1-2 句
776
  """)
777
  with gr.Row():
778
  with gr.Column():
779
+ gr.Markdown("### 寫出關於「關鍵字」的支持句")
780
  supporting_sentences_input = gr.Textbox(label="Supporting Sentences")
781
  with gr.Column():
782
  generate_supporting_sentences_button = gr.Button("讓 JUTOR 產生例句,幫助你撰寫支持句。", variant="primary")
 
804
  outputs= [supporting_sentences_input]
805
  )
806
 
807
+ # Step 5. 寫出結論句
808
  with gr.Row():
809
  with gr.Column():
810
  with gr.Row() as conclusion_sentences_params:
 
835
  with gr.Column():
836
  gr.Markdown("## 總結主要觀點,強化整個資訊的傳遞。重述、摘要、回應或評論主題句。")
837
  with gr.Column():
838
+ with gr.Accordion("參考指引:撰寫「結論句」的方法?", open=False):
839
  gr.Markdown("""
840
  - 以換句話說 (paraphrase) 的方式把主題句再說一次
841
  - 摘要三要點方式寫結論句
 
870
  outputs= [conclusion_sentence_input]
871
  )
872
 
873
+ # Step 6. 段落確認與修訂
874
  with gr.Row():
875
  with gr.Column():
876
  with gr.Row():
877
+ gr.Markdown("# Step 6. 段落確認與修訂")
878
  with gr.Row():
879
  with gr.Column():
880
  gr.Markdown("""### 你已經完成段落草稿,可再檢視幾次:
 
1006
  generate_paragraph_evaluate_button.click(
1007
  fn=generate_paragraph_evaluate,
1008
  inputs=[
1009
+ model,
1010
  sys_content_input,
1011
  paragraph_output,
1012
  user_generate_paragraph_evaluate_prompt
 
1022
  I'm aiming to improve my writing.
1023
  Please assist me by "Correcting Grammatical and Spelling Errors" in the provided paragraph.
1024
  For every correction you make, I'd like an "Explanation" to understand the reasoning behind it.
1025
+
1026
+ Rules:
1027
  - Paragraph for Correction: [paragraph split by punctuation mark]
1028
  - The sentence to remain unchanged: [sentence_to_remain_unchanged]
1029
  - When explaining, use Traditional Chinese (Taiwan, 繁體中文) for clarity.
1030
  - But others(original, Correction, revised_paragraph) in English.
1031
  - Make sure any revised vocabulary aligns with the eng_level.
1032
+ - Prepositions Followed by Gerunds: After a preposition, a gerund (the -ing form of a verb) should be used. For example: "interested in reading."
1033
+ - Two Main Verbs in a Sentence: When a sentence has two main verbs, it is necessary to use conjunctions, infinitives, clauses, or participles to correctly organize and connect the verbs, avoiding confusion in the sentence structure.
1034
+
1035
  Guidelines for Length and Complexity:
1036
  - Please keep explanations concise and straightforward
1037
+ - if there are no grammatical or spelling errors, don't need to revise either no more suggestions to show in the revised paragraph.
1038
 
1039
  Restrictions:
1040
  - avoiding overly technical language.
 
1072
  with gr.Column():
1073
  paragraph_correct_grammatical_spelling_errors_input = gr.Textbox(label="這是你的原始寫作內容,參考 JUTOR 的改正,你可以選擇是否修改:")
1074
  with gr.Column():
1075
+ generate_correct_grammatical_spelling_errors_button = gr.Button("修訂文法與拼字錯誤", variant="primary")
1076
  correct_grammatical_spelling_errors_output_table = gr.Dataframe(label="修訂文法與拼字錯誤", interactive=False)
1077
  revised_paragraph_output = gr.Textbox(label="Revised Paragraph", show_copy_button=True, visible=False)
1078
  gr.Markdown("## 修訂結果")
 
1081
  generate_correct_grammatical_spelling_errors_button.click(
1082
  fn=generate_correct_grammatical_spelling_errors,
1083
  inputs=[
1084
+ model,
1085
  sys_content_input,
1086
  eng_level_input,
1087
  paragraph_output,
 
1115
 
1116
  Guidelines for Length and Complexity:
1117
  - Please keep explanations concise and straightforward
1118
+ - if there are no problems, don't need to revise either no more suggestions to show in the revised paragraph.
1119
 
1120
  Restrictions:
1121
  - avoiding overly technical language.
 
1155
  generate_refine_paragraph_button.click(
1156
  fn=generate_refine_paragraph,
1157
  inputs=[
1158
+ model,
1159
  sys_content_input,
1160
  eng_level_input,
1161
  paragraph_correct_grammatical_spelling_errors_input,
 
1269
  with gr.Column():
1270
  full_paragraph_correct_grammatical_spelling_errors_input = gr.Textbox(label="這是你的原始寫作內容,參考 JUTOR 的建議,你可以選擇是否修改:")
1271
  with gr.Column():
1272
+ generate_full_paragraph_correct_grammatical_spelling_errors_button = gr.Button("修訂文法與拼字錯誤", variant="primary")
1273
  full_paragraph_correct_grammatical_spelling_errors_output_table = gr.Dataframe(label="修訂文法與拼字錯誤", interactive=False, column_widths=[30, 30, 40])
1274
  revised_full_paragraph_output = gr.Textbox(label="Revised Paragraph", show_copy_button=True, visible=False)
1275
  gr.Markdown("## 修訂結果")
 
1302
 
1303
  full_paragraph_evaluate_button.click(
1304
  fn=generate_paragraph_evaluate,
1305
+ inputs=[model, sys_content_input, full_paragraph_input, user_generate_full_paragraph_evaluate_prompt],
1306
  outputs=full_paragraph_evaluate_output
1307
  ).then(
1308
  fn=update_paragraph_correct_grammatical_spelling_errors_input,
 
1312
 
1313
  generate_full_paragraph_correct_grammatical_spelling_errors_button.click(
1314
  fn=generate_correct_grammatical_spelling_errors,
1315
+ inputs=[model, sys_content_input, eng_level_input, full_paragraph_correct_grammatical_spelling_errors_input, user_correct_grammatical_spelling_errors_prompt],
1316
  outputs=[full_paragraph_correct_grammatical_spelling_errors_output_table, revised_full_paragraph_output]
1317
  ).then(
1318
  fn=highlight_diff_texts,
 
1326
 
1327
  generate_full_paragraph_refine_button.click(
1328
  fn=generate_refine_paragraph,
1329
+ inputs=[
1330
+ model,
1331
+ sys_content_input,
1332
+ eng_level_input,
1333
+ full_paragraph_refine_input,
1334
+ user_refine_paragraph_prompt
1335
+ ],
1336
  outputs=[full_paragraph_refine_output_table, full_paragraph_refine_output]
1337
  ).then(
1338
  fn=highlight_diff_texts,
 
1426
  with gr.Column():
1427
  chinese_full_paragraph_correct_grammatical_spelling_errors_input = gr.Textbox(label="這是你的原始寫作內容,參考 JUTOR 的建議,你可以選擇是否修改:")
1428
  with gr.Column():
1429
+ generate_chinese_full_paragraph_correct_grammatical_spelling_errors_button = gr.Button("修訂文法與拼字錯誤", variant="primary")
1430
  chinese_full_paragraph_correct_grammatical_spelling_errors_output_table = gr.Dataframe(label="修訂文法與拼字錯誤", interactive=False, column_widths=[30, 30, 40])
1431
  revised_chinese_full_paragraph_output = gr.Textbox(label="Revised Paragraph", show_copy_button=True, visible=False)
1432
  gr.Markdown("## 修訂結果")
 
1459
 
1460
  chinese_full_paragraph_evaluate_button.click(
1461
  fn=generate_chinese_evaluation_table,
1462
+ inputs=[model, chinese_full_paragraph_sys_content_input, user_generate_chinese_full_paragraph_evaluate_prompt, chinese_full_paragraph_input],
1463
  outputs=chinese_full_paragraph_evaluate_output
1464
  ).then(
1465
  fn=update_paragraph_correct_grammatical_spelling_errors_input,
 
1469
 
1470
  generate_chinese_full_paragraph_correct_grammatical_spelling_errors_button.click(
1471
  fn=generate_correct_grammatical_spelling_errors,
1472
+ inputs=[model, chinese_full_paragraph_sys_content_input, eng_level_input, chinese_full_paragraph_correct_grammatical_spelling_errors_input, user_correct_grammatical_spelling_errors_prompt],
1473
  outputs=[chinese_full_paragraph_correct_grammatical_spelling_errors_output_table, revised_chinese_full_paragraph_output]
1474
  ).then(
1475
  fn=highlight_diff_texts,
 
1483
 
1484
  generate_chinese_full_paragraph_refine_button.click(
1485
  fn=generate_refine_paragraph,
1486
+ inputs=[model, chinese_full_paragraph_sys_content_input, eng_level_input, chinese_full_paragraph_refine_input, user_refine_paragraph_prompt],
1487
  outputs=[chinese_full_paragraph_refine_output_table, chinese_full_paragraph_refine_output]
1488
  ).then(
1489
  fn=highlight_diff_texts,
 
1529
  )
1530
 
1531
  # 評分
1532
+ with gr.Row():
1533
  with gr.Column():
1534
  with gr.Row():
1535
  past_exam_evaluation_sys_content_prompt = gr.Textbox(label="System Prompt", value="You are an English teacher who is practicing with me to improve my English writing skill.", visible=False)
 
1550
  with gr.Accordion("prompt 提供微調測試", open=False, elem_classes=['accordion-prompts']):
1551
  past_exam_correct_grammatical_spelling_errors_prompt = gr.Textbox(label="Correct Grammatical and Spelling Errors Prompt", value=default_user_correct_grammatical_spelling_errors_prompt, lines= 20)
1552
  with gr.Row():
1553
+ past_exam_generate_correct_grammatical_spelling_errors_button = gr.Button("修訂文法與拼字錯誤", variant="primary")
1554
  with gr.Row():
1555
  past_exam_correct_grammatical_spelling_errors_output_table = gr.Dataframe(label="修訂文法與拼字錯誤", interactive=False, column_widths=[30, 30, 40])
1556
  with gr.Row():
 
1591
 
1592
  past_exam_generate_correct_grammatical_spelling_errors_button.click(
1593
  fn=generate_correct_grammatical_spelling_errors,
1594
+ 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],
1595
  outputs=[past_exam_correct_grammatical_spelling_errors_output_table, past_exam_revised_output]
1596
  ).then(
1597
  fn=highlight_diff_texts,