youngtsai commited on
Commit
af1d454
·
1 Parent(s): e56d3c5

# Step 7. 段落確認與修訂

Browse files
Files changed (1) hide show
  1. app.py +175 -83
app.py CHANGED
@@ -196,8 +196,12 @@ def generate_conclusion_sentences(model, max_tokens, sys_content, scenario, eng_
196
 
197
  response = OPEN_AI_CLIENT.chat.completions.create(**request_payload)
198
  content = response.choices[0].message.content.strip()
 
199
 
200
- return content
 
 
 
201
 
202
  def generate_paragraph(topic_sentence, supporting_sentences, conclusion_sentence):
203
  """
@@ -549,82 +553,178 @@ with gr.Blocks(theme=gr.themes.Soft(primary_hue=gr.themes.colors.blue, secondary
549
  outputs= [supporting_sentences_input]
550
  )
551
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
552
 
 
 
 
 
 
553
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
554
 
 
 
 
 
 
 
 
 
 
555
 
556
- gr.Markdown("## 6. Conclusion sentence 結論句")
557
- default_generate_conclusion_sentence_prompt = """
558
- I'm aiming to improve my writing.
559
- By the topic sentence, please assist me by "Developing conclusion sentences"
560
- based on keywords of points to finish a paragrpah as an example.
561
- - Make sure any revised vocabulary aligns with the correctly eng_level.
562
- - Guidelines for Length and Complexity:
563
- Please keep the example concise and straightforward,
564
- avoiding overly technical language.
565
- Total word-count is around 20.
566
- """
567
- user_generate_conclusion_sentence_prompt = gr.Textbox(label="Conclusion Sentence Prompt", value=default_generate_conclusion_sentence_prompt, visible=False)
568
- generate_conclusion_sentence_button = gr.Button("AI Generate Conclusion Sentence")
569
- conclusion_sentence_output = gr.Textbox(label="AI Generated Conclusion Sentence 結論句", show_copy_button=True)
570
- conclusion_sentence_input = gr.Textbox(label="Conclusion Sentence")
571
-
572
- gr.Markdown("## 7. Paragraph Integration and Revision 段落確認與修訂")
573
- generate_paragraph_button = gr.Button("Generate Paragraph")
574
- paragraph_output = gr.Textbox(label="Generated Paragraph 完整段落", show_copy_button=True)
575
- paragraph_input = gr.Textbox(label="Paragraph")
576
-
577
- gr.Markdown("## 8. Evaluate 分析")
578
- default_user_generate_paragraph_evaluate_prompt = """
579
- Based on the final paragraph provided, evaluate the writing in terms of content, organization, grammar, and vocabulary. Provide feedback in simple and supportive language.
580
-
581
- -- 根據上述的文章,以「內容(content)」層面評分。
582
- - 評分等級有三級:beginner, intermediate, advanced. - 以繁體中文解釋
583
- 評分結果以 JSON 格式輸出: content: {
584
- "content_level": "#beginner/intermediate/advanced",
585
- "content_explanation": "#中文解釋"
586
- }
587
-
588
- -- 根據上述的文章,以「組織(organization)」層面評分。
589
- - 評分等級有三級:beginner, intermediate, advanced. - 以繁體中文解釋
590
- 評分結果以 JSON 格式輸出: organization: {
591
- "organization_level": "#beginner/intermediate/advanced",
592
- "organization_explanation": "#中文解釋"
593
- }
594
-
595
- -- 根據上述的文章,以「文法和用法(Grammar and usage)」層面評分。
596
- - 評分等級有三級:beginner, intermediate, advanced. - 以繁體中文解釋
597
- 評分結果以 JSON 格式輸出: grammar_and_usage: {
598
- "GrammarAndUsage_level": "#beginner/intermediate/advanced",
599
- "GrammarAndUsage_explanation": "#中文解釋"
600
- }
601
-
602
- -- 根據上述的文章,以「詞彙(Vocabulary )」層面評分。
603
- - 評分等級有三級:beginner, intermediate, advanced. - 以繁體中文解釋
604
- 評分結果以 JSON 格式輸出: vocabulary: {
605
- "Vocabulary_level": "#beginner/intermediate/advanced",
606
- "Vocabulary_explanation": "#中文解釋"
607
- }
608
-
609
- -- 根據上述的文章,以「連貫性和連接詞(Coherence and Cohesion)」層面評分。
610
- - 評分等級有三級:beginner, intermediate, advanced. - 以繁體中文解釋
611
- 評分結果以 JSON 格式輸出: coherence_and_cohesion: {
612
- "CoherenceAndCohesion_level": "#beginner/intermediate/advanced",
613
- "CoherenceAndCohesion_explanation": "#中文解釋"
614
- }
615
 
616
- 將上述的輸出為 JSON:
617
- {{
618
- “content“: {content’s dict},
619
- “organization“: {organization dict},
620
- “grammar_and_usage“: {grammar_and_usage dict},
621
- “vocabulary“: {vocabulary dict},
622
- “coherence_and_cohesion“: {coherence_and_cohesion dict}
623
- }}
624
- """
625
- user_generate_paragraph_evaluate_prompt = gr.Textbox(label="Paragraph evaluate Prompt", value=default_user_generate_paragraph_evaluate_prompt, visible=False)
626
- generate_paragraph_evaluate_button = gr.Button("Save and Evaluate")
627
- paragraph_evaluate_output = gr.Textbox(label="Generated Paragraph evaluate 完整段落分析", show_copy_button=True)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
628
 
629
  gr.Markdown("## 9. Correct Grammatical and Spelling Errors 修訂文法與拼字錯誤")
630
  default_user_correct_grammatical_spelling_errors_prompt = """
@@ -757,20 +857,12 @@ with gr.Blocks(theme=gr.themes.Soft(primary_hue=gr.themes.colors.blue, secondary
757
  outputs=conclusion_sentence_output
758
  )
759
 
760
- generate_paragraph_button.click(
761
- fn=generate_paragraph,
762
- inputs=[
763
- topic_sentence_input,
764
- supporting_sentences_input,
765
- conclusion_sentence_input
766
- ],
767
- outputs=paragraph_output
768
- )
769
 
770
  generate_paragraph_evaluate_button.click(
771
  fn=generate_paragraph_evaluate,
772
  inputs=[
773
- paragraph_input,
774
  user_generate_paragraph_evaluate_prompt
775
  ],
776
  outputs=paragraph_evaluate_output
@@ -780,7 +872,7 @@ with gr.Blocks(theme=gr.themes.Soft(primary_hue=gr.themes.colors.blue, secondary
780
  fn=generate_correct_grammatical_spelling_errors,
781
  inputs=[
782
  eng_level_input,
783
- paragraph_input,
784
  user_correct_grammatical_spelling_errors_prompt
785
  ],
786
  outputs=correct_grammatical_spelling_errors_output
 
196
 
197
  response = OPEN_AI_CLIENT.chat.completions.create(**request_payload)
198
  content = response.choices[0].message.content.strip()
199
+ gr_update = gr.update(choices=[content])
200
 
201
+ return gr_update
202
+
203
+ def update_conclusion_sentence_input(conclusion_sentence_radio):
204
+ return conclusion_sentence_radio
205
 
206
  def generate_paragraph(topic_sentence, supporting_sentences, conclusion_sentence):
207
  """
 
553
  outputs= [supporting_sentences_input]
554
  )
555
 
556
+ # Step 6. 寫出結論句
557
+ with gr.Row():
558
+ with gr.Column():
559
+ with gr.Row() as conclusion_sentences_params:
560
+ default_generate_conclusion_sentence_prompt = """
561
+ I'm aiming to improve my writing.
562
+ By the topic sentence, please assist me by "Developing conclusion sentences"
563
+ based on keywords of points to finish a paragrpah as an example.
564
+ - Make sure any revised vocabulary aligns with the correctly eng_level.
565
+ - Guidelines for Length and Complexity:
566
+ Please keep the example concise and straightforward,
567
+ avoiding overly technical language.
568
+ Total word-count is around 20.
569
+ """
570
+ user_generate_conclusion_sentence_prompt = gr.Textbox(label="Conclusion Sentence Prompt", value=default_generate_conclusion_sentence_prompt, visible=False)
571
+
572
+ with gr.Row() as conclusion_sentences_html:
573
+ gr.Markdown("# Step 6. 寫出結論句")
574
+ with gr.Row():
575
+ with gr.Column():
576
+ gr.Markdown("## 總結主要觀點,強化整個資訊的傳遞。重述、摘要、回應或評論主題句。")
577
+ with gr.Column():
578
+ with gr.Accordion("參考指引:撰寫結論句的方法?", open=False):
579
+ gr.Markdown("""
580
+ - 以換句話說 (paraphrase) 的方式把主題句再說一次
581
+ - 摘要三要點方式寫結論句
582
+ - 回應或評論主題句的方式來寫結論句(例如主題句要從事課外活動,就說課外活動有這麼多好處,應該多參加課外活動等等)
583
+ """)
584
+ with gr.Row():
585
+ with gr.Column():
586
+ conclusion_sentence_input = gr.Textbox(label="寫出總結段落的結論句")
587
+ with gr.Column():
588
+ generate_conclusion_sentence_button = gr.Button("讓 JUTOR 產生例句,幫助你撰寫結論句。")
589
+ conclusion_sentence_output = gr.Radio(choices=[], label="AI Generated Conclusion Sentence 結論句")
590
 
591
+ conclusion_sentence_output.select(
592
+ fn=update_conclusion_sentence_input,
593
+ inputs=[conclusion_sentence_output],
594
+ outputs= [conclusion_sentence_input]
595
+ )
596
 
597
+ # Step 7. 段落確認與修訂
598
+ with gr.Row():
599
+ with gr.Column():
600
+ with gr.Row():
601
+ gr.Markdown("## 7. Paragraph Integration and Revision 段落確認與修訂")
602
+ with gr.Row():
603
+ with gr.Column():
604
+ gr.Markdown("""### 你已經完成段落草稿,可再檢視幾次:
605
+ 1. 找出文法、拼字或標點錯誤
606
+ 2. 需要之處加入合適的轉折詞,例如:first, second, however, moreover, etc.
607
+ 3. 整個段落是否連貫、流暢、容易理解
608
+ """)
609
+ with gr.Column():
610
+ with gr.Accordion("參考指引:什麼是段落的連貫性?", open=False):
611
+ gr.Markdown("""
612
+ - 能夠以清晰、邏輯的方式表達自己的想法,使讀者易於理解。
613
+ - 連貫的段落應該有一個清晰的主題句來介紹主要想法(main idea),接著是支持句,提供更多細節和例子來支持主題句。
614
+ - 支持句應該按照邏輯制序,引導讀者從一個idea順利讀懂下一個idea。
615
+ - 有些句子間邏輯關係不清楚,還需要使用轉折詞(邏輯膠水)做連結,來引導讀者,例如:
616
+ - first, second, finally 表示段落要點的秩序
617
+ - moreover, furthermore, additionally 表示介紹另外一個要點
618
+ - however, nevertheless 表示下面句子是相反的關係
619
+ - therefore, as a result表示下面句子是結果
620
+ - in comparison, by contrast表示下面句子比較的關係
621
+ - for example, for instance 表示下面句子是舉例
622
+ - 最後,段落應該有一個結論句,總結主要觀點,強化所要傳遞的資訊。
623
+ """)
624
+ with gr.Row():
625
+ generate_paragraph_button = gr.Button("Generate Paragraph")
626
+ with gr.Row():
627
+ paragraph_output = gr.Textbox(label="Generated Paragraph 完整段落", show_copy_button=True)
628
 
629
+ generate_paragraph_button.click(
630
+ fn=generate_paragraph,
631
+ inputs=[
632
+ topic_sentence_input,
633
+ supporting_sentences_input,
634
+ conclusion_sentence_input
635
+ ],
636
+ outputs=paragraph_output
637
+ )
638
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
639
 
640
+ with gr.Row():
641
+ with gr.Column():
642
+ with gr.Row():
643
+ gr.Markdown("## 8. Evaluate 分析")
644
+ with gr.Row():
645
+ default_user_generate_paragraph_evaluate_prompt = """
646
+ Based on the final paragraph provided, evaluate the writing in terms of content, organization, grammar, and vocabulary. Provide feedback in simple and supportive language.
647
+
648
+ -- 根據上述的文章,以「內容(content)」層面評分。
649
+ Assess the student's writing by focusing on the 'Content' category according to the established rubric. Determine the clarity of the theme or thesis statement and whether it is supported by specific and complete details relevant to the topic. Use the following levels to guide your evaluation:
650
+
651
+ - Excellent (5-4 points): Look for a clear and pertinent theme or thesis, directly related to the topic, with detailed support.
652
+ - Good (3 points): The theme should be present but may lack clarity or emphasis; some narrative development related to the theme should be evident.
653
+ - Fair (2-1 points): Identify if the theme is unclear or if the majority of the narrative is undeveloped or irrelevant to the theme.
654
+ - Poor (0 points): Determine if the response is off-topic or not written at all. Remember that any response that is off-topic or unwritten should receive zero points in all aspects.
655
+
656
+ Your detailed feedback should explain the score you assign, including specific examples from the text to illustrate how well the student's content meets the criteria. Translate your feedback into Traditional Chinese (zh_tw) as the final result (#中文解釋).
657
+
658
+ 評分結果以 JSON 格式輸出: content: {
659
+ "content_level": "#Excellent(5-4 pts)/Good(3 pts)/Fair(2-1 pts)/Poor(0 pts)",
660
+ "content_explanation": "#中文解釋 zh-TW"
661
+ }
662
+
663
+ -- 根據上述的文章,以「組織(organization)」層面評分。
664
+ Evaluate the student's writing with a focus on 'Organization' according to the grading rubric. Consider the structure of the text, including the presence of a clear introduction, development, and conclusion, as well as the coherence throughout the piece and the use of transitional phrases. Use the following levels to structure your feedback:
665
+
666
+ - Excellent (5-4 points): Look for clear key points with a logical introduction, development, and conclusion, and note whether transitions are coherent and effectively used.
667
+ - Good (3 points): The key points should be identifiable but may not be well-arranged; observe any imbalance in development and transitional phrase usage.
668
+ - Fair (2-1 points): Identify if the key points are unclear and if the text lacks coherence.
669
+ - Poor (0 points): Check if the writing is completely unorganized or not written according to the prompts. Texts that are entirely unorganized should receive zero points.
670
+
671
+ Your detailed feedback should explain the score you assign, including specific examples from the text to illustrate how well the student's Organization meets the criteria. Translate your feedback into Traditional Chinese (zh_tw) as the final result (#中文解釋).
672
+
673
+ 評分結果以 JSON 格式輸出: organization: {
674
+ "organization_level": "#Excellent(5-4 pts)/Good(3 pts)/Fair(2-1 pts)/Poor(0 pts)",
675
+ "organization_explanation": "#中文解釋 zh-TW"
676
+ }
677
+
678
+ -- 根據上述的文章,以「文法和用法(Grammar and usage)」層面評分。
679
+ Review the student's writing, paying special attention to 'Grammar/Sentence Structure'. Assess the accuracy of grammar and the variety of sentence structures throughout the essay. Use the rubric levels to judge the work as follows:
680
+
681
+ - Excellent (5-4 points): Search for text with minimal grammatical errors and a diverse range of sentence structures.
682
+ - Good (3 points): There may be some grammatical errors, but they should not affect the overall meaning or flow of the text.
683
+ - Fair (2-1 points): Determine if grammatical errors are frequent and if they significantly affect the meaning of the text.
684
+ - Poor (0 points): If the essay contains severe grammatical errors throughout, leading to an unclear meaning, it should be marked accordingly.
685
+
686
+ Your detailed feedback should explain the score you assign, including specific examples from the text to illustrate how well the student's Grammar/Sentence Structure meets the criteria. Translate your feedback into Traditional Chinese (zh_tw) as the final result (#中文解釋).
687
+
688
+ 評分結果以 JSON 格式輸出: grammar_and_usage: {
689
+ "GrammarAndUsage_level": "#Excellent(5-4 pts)/Good(3 pts)/Fair(2-1 pts)/Poor(0 pts)",
690
+ "GrammarAndUsage_explanation": "#中文解釋 zh-TW"
691
+ }
692
+
693
+ -- 根據上述的文章,以「詞彙(Vocabulary )」層面評分。
694
+ Assess the use of 'Vocabulary/Spelling' in the student's writing based on the criteria provided. Evaluate the precision and appropriateness of the vocabulary and the presence of spelling errors. Reference the following scoring levels in your analysis:
695
+
696
+ - Excellent (5-4 points): The writing should contain accurate and appropriate vocabulary with almost no spelling mistakes.
697
+ - Good (3 points): Vocabulary might be somewhat repetitive or mundane; there may be occasional misused words and minor spelling mistakes, but they should not impede understanding.
698
+ - Fair (2-1 points): Notice if there are many vocabulary errors and spelling mistakes that clearly affect the clarity of the text's meaning.
699
+ - Poor (0 points): Writing that only contains scattered words related to the topic or is copied should be scored as such.
700
+
701
+ Your detailed feedback should explain the score you assign, including specific examples from the text to illustrate how well the student's Vocabulary/Spelling meets the criteria. Translate your feedback into Traditional Chinese (zh_tw) as the final result (#中文解釋).
702
+
703
+ 評分結果以 JSON 格式輸出: vocabulary: {
704
+ "Vocabulary_level": "#Excellent(5-4 pts)/Good(3 pts)/Fair(2-1 pts)/Poor(0 pts)",
705
+ "Vocabulary_explanation": "#中文解釋 zh-TW"
706
+ }
707
+
708
+ -- 根據上述的文章,以「連貫性和連接詞(Coherence and Cohesion)」層面評分。
709
+ - 評分等級有三級:beginner, intermediate, advanced.
710
+ - 以繁體中文 zh-TW 解釋
711
+ 評分結果以 JSON 格式輸出: coherence_and_cohesion: {
712
+ "CoherenceAndCohesion_level": "#beginner/intermediate/advanced",
713
+ "CoherenceAndCohesion_explanation": "#中文解釋 zh-TW"
714
+ }
715
+
716
+ Final Output JSON Format:
717
+ {{
718
+ “content“: {{content’s dict}},
719
+ “organization“: {{organization'dict}},
720
+ “grammar_and_usage“: {{grammar_and_usage'dict}},
721
+ “vocabulary“: {{vocabulary'dict}},
722
+ “coherence_and_cohesion“: {{coherence_and_cohesion'dict}}
723
+ }}
724
+ """
725
+ user_generate_paragraph_evaluate_prompt = gr.Textbox(label="Paragraph evaluate Prompt", value=default_user_generate_paragraph_evaluate_prompt, visible=False)
726
+ generate_paragraph_evaluate_button = gr.Button("Save and Evaluate")
727
+ paragraph_evaluate_output = gr.Textbox(label="Generated Paragraph evaluate 完整段落分析", show_copy_button=True)
728
 
729
  gr.Markdown("## 9. Correct Grammatical and Spelling Errors 修訂文法與拼字錯誤")
730
  default_user_correct_grammatical_spelling_errors_prompt = """
 
857
  outputs=conclusion_sentence_output
858
  )
859
 
860
+
 
 
 
 
 
 
 
 
861
 
862
  generate_paragraph_evaluate_button.click(
863
  fn=generate_paragraph_evaluate,
864
  inputs=[
865
+ paragraph_output,
866
  user_generate_paragraph_evaluate_prompt
867
  ],
868
  outputs=paragraph_evaluate_output
 
872
  fn=generate_correct_grammatical_spelling_errors,
873
  inputs=[
874
  eng_level_input,
875
+ paragraph_output,
876
  user_correct_grammatical_spelling_errors_prompt
877
  ],
878
  outputs=correct_grammatical_spelling_errors_output