Spaces:
Sleeping
Sleeping
update
Browse files
app.py
CHANGED
@@ -27,73 +27,6 @@ OPEN_AI_CLIENT = OpenAI(api_key=OPEN_AI_KEY)
|
|
27 |
def update_scenario_input(scenario_radio):
|
28 |
return scenario_radio
|
29 |
|
30 |
-
def generate_topics(model, max_tokens, sys_content, scenario, eng_level, user_generate_topics_prompt):
|
31 |
-
"""
|
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 = [
|
41 |
-
{"role": "system", "content": sys_content},
|
42 |
-
{"role": "user", "content": user_content}
|
43 |
-
]
|
44 |
-
|
45 |
-
request_payload = {
|
46 |
-
"model": model,
|
47 |
-
"messages": messages,
|
48 |
-
"max_tokens": max_tokens,
|
49 |
-
"response_format": { "type": "json_object" }
|
50 |
-
}
|
51 |
-
|
52 |
-
response = OPEN_AI_CLIENT.chat.completions.create(**request_payload)
|
53 |
-
content = response.choices[0].message.content
|
54 |
-
topics = json.loads(content)["topics"]
|
55 |
-
topics_text = json.dumps(topics)
|
56 |
-
|
57 |
-
gr_update = gr.update(visible=False, value=topics_text)
|
58 |
-
return gr_update
|
59 |
-
|
60 |
-
def update_topic_input(topic):
|
61 |
-
return topic
|
62 |
-
|
63 |
-
def generate_points(model, max_tokens, sys_content, scenario, eng_level, topic, user_generate_points_prompt):
|
64 |
-
"""
|
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 = [
|
75 |
-
{"role": "system", "content": sys_content},
|
76 |
-
{"role": "user", "content": user_content}
|
77 |
-
]
|
78 |
-
|
79 |
-
request_payload = {
|
80 |
-
"model": model,
|
81 |
-
"messages": messages,
|
82 |
-
"max_tokens": max_tokens,
|
83 |
-
}
|
84 |
-
|
85 |
-
response = OPEN_AI_CLIENT.chat.completions.create(**request_payload)
|
86 |
-
content = response.choices[0].message.content
|
87 |
-
|
88 |
-
points = json.loads(content)["points"]
|
89 |
-
points_text = json.dumps(points)
|
90 |
-
|
91 |
-
gr_update = gr.update(visible=False, value=points_text)
|
92 |
-
return gr_update
|
93 |
-
|
94 |
-
def update_points_input(points):
|
95 |
-
return points
|
96 |
-
|
97 |
def get_exam_history():
|
98 |
exam_history = """
|
99 |
92
|
@@ -170,6 +103,85 @@ def get_exam_history():
|
|
170 |
|
171 |
return exam_history
|
172 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
173 |
def generate_topic_sentences(model, max_tokens, sys_content, scenario, eng_level, topic, points, user_generate_topic_sentences_prompt):
|
174 |
"""
|
175 |
根据系统提示和用户输入的情境及要点,调用OpenAI API生成相关的主题句及其合理性解释。
|
@@ -211,17 +223,17 @@ def generate_topic_sentences(model, max_tokens, sys_content, scenario, eng_level
|
|
211 |
response = OPEN_AI_CLIENT.chat.completions.create(**request_payload)
|
212 |
response_content = json.loads(response.choices[0].message.content)
|
213 |
json_content = response_content["results"]
|
214 |
-
|
215 |
-
|
|
|
|
|
|
|
216 |
|
217 |
-
|
218 |
-
return gr_update
|
219 |
|
220 |
-
def update_topic_sentence_input(
|
221 |
-
selected_topic_sentence = topic_sentences_radio
|
222 |
-
topic_sentence_output = json.loads(topic_sentence_output)
|
223 |
topic_sentence_input = ""
|
224 |
-
for ts in
|
225 |
if ts["topic-sentence"] == selected_topic_sentence:
|
226 |
appropriate = "O 適合" if ts["appropriate"] == "Y" else "X 不適合"
|
227 |
border_color = "green" if ts["appropriate"] == "Y" else "red"
|
@@ -238,7 +250,9 @@ def update_topic_sentence_input(topic_sentences_radio, topic_sentence_output):
|
|
238 |
topic_sentence_input = ts["topic-sentence"] if ts["appropriate"] == "Y" else ""
|
239 |
break
|
240 |
|
241 |
-
|
|
|
|
|
242 |
|
243 |
def generate_supporting_sentences(model, max_tokens, sys_content, scenario, eng_level, topic, points, topic_sentence, user_generate_supporting_sentences_prompt):
|
244 |
"""
|
@@ -266,7 +280,7 @@ def generate_supporting_sentences(model, max_tokens, sys_content, scenario, eng_
|
|
266 |
|
267 |
response = OPEN_AI_CLIENT.chat.completions.create(**request_payload)
|
268 |
content = response.choices[0].message.content.strip()
|
269 |
-
gr_update = gr.update(choices=[content])
|
270 |
|
271 |
return gr_update
|
272 |
|
@@ -301,7 +315,7 @@ def generate_conclusion_sentences(model, max_tokens, sys_content, scenario, eng_
|
|
301 |
response = OPEN_AI_CLIENT.chat.completions.create(**request_payload)
|
302 |
response_content = json.loads(response.choices[0].message.content)
|
303 |
json_content = response_content["results"]
|
304 |
-
gr_update = gr.update(choices=[json_content])
|
305 |
|
306 |
return gr_update
|
307 |
|
@@ -353,7 +367,7 @@ def generate_paragraph_evaluate(model, sys_content, paragraph, user_generate_par
|
|
353 |
["JUTOR 架構|連貫性和連接詞(Coherence and Cohesion)", data['coherence_and_cohesion']['level'], data['coherence_and_cohesion']['explanation']]
|
354 |
]
|
355 |
headers = ["架構", "評分", "解釋"]
|
356 |
-
gr_update = gr.update(value=table_data, headers=headers)
|
357 |
|
358 |
return gr_update
|
359 |
|
@@ -577,6 +591,32 @@ def update_exam_contents(selected_title):
|
|
577 |
def show_elements():
|
578 |
return gr.update(visible=True)
|
579 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
580 |
# elem_classes=['accordion-prompts']
|
581 |
CSS = """
|
582 |
.accordion-prompts {
|
@@ -593,7 +633,7 @@ with gr.Blocks(theme=gr.themes.Soft(primary_hue=gr.themes.colors.blue, secondary
|
|
593 |
max_tokens = gr.Slider(minimum=50, maximum=4000, value=4000, label="Max Tokens")
|
594 |
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.")
|
595 |
with gr.Row():
|
596 |
-
eng_level_input = gr.Radio([("初學", "beginner"), ("
|
597 |
|
598 |
# basic inputs 主題與情境
|
599 |
with gr.Group():
|
@@ -665,11 +705,11 @@ with gr.Blocks(theme=gr.themes.Soft(primary_hue=gr.themes.colors.blue, secondary
|
|
665 |
user_generate_topics_prompt = gr.Textbox(label="Topics Prompt", value=default_generate_topics_prompt, visible=False)
|
666 |
with gr.Row():
|
667 |
with gr.Column():
|
668 |
-
topic_input = gr.Textbox(label="
|
669 |
with gr.Column():
|
670 |
-
generate_topics_button = gr.Button("✨ JUTOR
|
671 |
-
topic_output = gr.
|
672 |
-
|
673 |
generate_topics_button.click(
|
674 |
fn=show_elements,
|
675 |
inputs=[],
|
@@ -687,16 +727,12 @@ with gr.Blocks(theme=gr.themes.Soft(primary_hue=gr.themes.colors.blue, secondary
|
|
687 |
outputs=[topic_output]
|
688 |
)
|
689 |
|
690 |
-
|
691 |
-
|
692 |
-
|
693 |
-
|
694 |
-
|
695 |
-
|
696 |
-
inputs=[topic_radio],
|
697 |
-
outputs=[topic_input]
|
698 |
-
)
|
699 |
-
return topic_radio
|
700 |
|
701 |
# Step 2. 寫出關鍵字
|
702 |
with gr.Row():
|
@@ -719,14 +755,13 @@ with gr.Blocks(theme=gr.themes.Soft(primary_hue=gr.themes.colors.blue, secondary
|
|
719 |
with gr.Row():
|
720 |
gr.Markdown("## 根據主題,思考段落的方向及內容,然後用兩個要點/關鍵字來呈現。例如主題:「The Benefits of Learning a Second Language 學習第二種語言的好處」,內容及方向:因為學習第二種語言,例如日語,就可以和日本人溝通,進而學習瞭解日本文化,因而要點/關鍵字就是「Improving communication skills 提升溝通能力」及「Understanding other cultures 瞭解其他文化」。")
|
721 |
with gr.Row():
|
722 |
-
gr.Markdown("
|
723 |
with gr.Row():
|
724 |
with gr.Column():
|
725 |
-
points_input = gr.Textbox(label="
|
726 |
with gr.Column():
|
727 |
generate_points_button = gr.Button("✨ 找尋靈感?使用 JUTOR 產生要點/關鍵字", variant="primary")
|
728 |
-
points_output = gr.
|
729 |
-
|
730 |
generate_points_button.click(
|
731 |
fn=show_elements,
|
732 |
inputs=[],
|
@@ -744,17 +779,12 @@ with gr.Blocks(theme=gr.themes.Soft(primary_hue=gr.themes.colors.blue, secondary
|
|
744 |
],
|
745 |
outputs=points_output
|
746 |
)
|
747 |
-
|
748 |
-
|
749 |
-
|
750 |
-
|
751 |
-
|
752 |
-
|
753 |
-
fn=update_points_input,
|
754 |
-
inputs=[points_radio],
|
755 |
-
outputs=[points_input]
|
756 |
-
)
|
757 |
-
return points_radio
|
758 |
|
759 |
# Step 3. 選定主題句
|
760 |
with gr.Row():
|
@@ -782,7 +812,7 @@ with gr.Blocks(theme=gr.themes.Soft(primary_hue=gr.themes.colors.blue, secondary
|
|
782 |
user_generate_topic_sentences_prompt = gr.Textbox(label="Topic Sentences Prompt", value=default_generate_topic_sentences_prompt, visible=False)
|
783 |
|
784 |
with gr.Row() as topic_sentences_html:
|
785 |
-
gr.Markdown("# Step
|
786 |
with gr.Row():
|
787 |
with gr.Column():
|
788 |
gr.Markdown("## 主題句(Topic Sentence)通常位於段落的開頭,幫助讀者迅速理解段落的內容。是段落中最重要的句子,介紹主題並含括段落的所有要點/關鍵字。")
|
@@ -793,15 +823,21 @@ with gr.Blocks(theme=gr.themes.Soft(primary_hue=gr.themes.colors.blue, secondary
|
|
793 |
gr.Markdown("""舉例,情境是 `School & Learning`,段落主題是 `Time Management`,那麼 `Balancing school work and leisure time is a crucial aspect of effective time management` 就是合適的主題句,因為它清楚點出該段落將説明有效運用時間來讓課業及娛樂取得平衡。""")
|
794 |
with gr.Row():
|
795 |
with gr.Column():
|
796 |
-
topic_sentence_input = gr.Textbox(label="
|
797 |
with gr.Column():
|
798 |
-
generate_topic_sentences_button = gr.Button("
|
799 |
-
|
800 |
-
|
|
|
|
|
801 |
generate_topic_sentences_button.click(
|
802 |
fn=show_elements,
|
803 |
inputs=[],
|
804 |
-
outputs=[
|
|
|
|
|
|
|
|
|
805 |
).then(
|
806 |
fn=generate_topic_sentences,
|
807 |
inputs=[
|
@@ -814,27 +850,14 @@ with gr.Blocks(theme=gr.themes.Soft(primary_hue=gr.themes.colors.blue, secondary
|
|
814 |
points_input,
|
815 |
user_generate_topic_sentences_prompt
|
816 |
],
|
817 |
-
outputs=
|
818 |
)
|
819 |
|
820 |
-
|
821 |
-
|
822 |
-
|
823 |
-
|
824 |
-
|
825 |
-
# Extracting only the topic sentences for the radio button options
|
826 |
-
radio_options = [ts["topic-sentence"] for ts in topic_sentences_list]
|
827 |
-
|
828 |
-
# Creating the radio button element
|
829 |
-
topic_sentences_radio = gr.Radio(radio_options, label="主題句", elem_id="topic_sentence_button")
|
830 |
-
topic_sentences_suggestions = gr.HTML()
|
831 |
-
topic_sentences_radio.select(
|
832 |
-
fn=update_topic_sentence_input,
|
833 |
-
inputs=[topic_sentences_radio, topic_sentence_output],
|
834 |
-
outputs= [topic_sentence_input, topic_sentences_suggestions]
|
835 |
-
)
|
836 |
-
|
837 |
-
return topic_sentences_radio
|
838 |
|
839 |
# Step 4.寫出支持句
|
840 |
with gr.Row():
|
@@ -866,9 +889,7 @@ with gr.Blocks(theme=gr.themes.Soft(primary_hue=gr.themes.colors.blue, secondary
|
|
866 |
with gr.Row():
|
867 |
with gr.Column():
|
868 |
with gr.Row():
|
869 |
-
gr.Markdown("##
|
870 |
-
with gr.Row():
|
871 |
-
gr.Markdown("### 支持句:以支持句來解釋要點,必要時舉例説明,來支持主題句。這些句子應該按照邏輯順序來組織,例如時間順序、空間順序、重要性順序、因果關係等。並使用轉折詞來引導讀者從一個 idea 到下一個 idea,讓讀者讀起來很順暢,不需反覆閱讀。")
|
872 |
with gr.Column():
|
873 |
with gr.Accordion("參考指引:撰寫支持句的方法?", open=False):
|
874 |
gr.Markdown("""
|
@@ -890,10 +911,14 @@ with gr.Blocks(theme=gr.themes.Soft(primary_hue=gr.themes.colors.blue, secondary
|
|
890 |
with gr.Column():
|
891 |
supporting_sentences_input = gr.Textbox(label="根據要點/關鍵字來寫支持句")
|
892 |
with gr.Column():
|
893 |
-
generate_supporting_sentences_button = gr.Button("JUTOR 產出支持句,供參考並自行寫出支持句", variant="primary")
|
894 |
-
supporting_sentences_output = gr.Radio(
|
895 |
|
896 |
generate_supporting_sentences_button.click(
|
|
|
|
|
|
|
|
|
897 |
fn=generate_supporting_sentences,
|
898 |
inputs=[
|
899 |
model,
|
@@ -956,10 +981,14 @@ with gr.Blocks(theme=gr.themes.Soft(primary_hue=gr.themes.colors.blue, secondary
|
|
956 |
with gr.Column():
|
957 |
conclusion_sentence_input = gr.Textbox(label="寫出總結段落的結論句")
|
958 |
with gr.Column():
|
959 |
-
generate_conclusion_sentence_button = gr.Button("JUTOR 產出結論句,供參考並自行寫出支持句", variant="primary")
|
960 |
-
conclusion_sentence_output = gr.Radio(
|
961 |
|
962 |
generate_conclusion_sentence_button.click(
|
|
|
|
|
|
|
|
|
963 |
fn=generate_conclusion_sentences,
|
964 |
inputs=[
|
965 |
model,
|
@@ -988,10 +1017,10 @@ with gr.Blocks(theme=gr.themes.Soft(primary_hue=gr.themes.colors.blue, secondary
|
|
988 |
gr.Markdown("# Step 6. 段落確認與修訂")
|
989 |
with gr.Row():
|
990 |
with gr.Column():
|
991 |
-
gr.Markdown("""
|
992 |
-
1. 找出文法、拼字或標點錯誤
|
993 |
-
2. 需要之處加入合適的轉折詞,例如:first, second, however, moreover, etc.
|
994 |
-
3. 整個段落是否連貫、流暢、容易理解
|
995 |
""")
|
996 |
with gr.Column():
|
997 |
with gr.Accordion("參考指引:什麼是段落的連貫性?", open=False):
|
@@ -1009,110 +1038,112 @@ with gr.Blocks(theme=gr.themes.Soft(primary_hue=gr.themes.colors.blue, secondary
|
|
1009 |
- 最後,段落應該有一個結論句,總結主要觀點,強化所要傳遞的資訊。
|
1010 |
""")
|
1011 |
with gr.Row():
|
1012 |
-
|
1013 |
-
|
1014 |
-
|
1015 |
-
|
1016 |
-
|
1017 |
-
|
1018 |
-
|
1019 |
-
|
1020 |
-
|
1021 |
-
|
1022 |
-
|
1023 |
-
|
1024 |
-
|
1025 |
-
|
1026 |
-
|
1027 |
-
|
1028 |
-
|
1029 |
-
|
1030 |
-
|
1031 |
-
|
1032 |
-
|
1033 |
-
|
1034 |
-
|
1035 |
-
|
1036 |
-
|
1037 |
-
|
1038 |
-
|
1039 |
-
|
1040 |
-
|
1041 |
-
|
1042 |
-
|
1043 |
-
|
1044 |
-
|
1045 |
-
|
1046 |
-
|
1047 |
-
|
1048 |
-
|
1049 |
-
|
1050 |
-
|
1051 |
-
|
1052 |
-
|
1053 |
-
|
1054 |
-
|
1055 |
-
|
1056 |
-
|
1057 |
-
|
1058 |
-
|
1059 |
-
|
1060 |
-
|
1061 |
-
|
1062 |
-
|
1063 |
-
|
1064 |
-
|
1065 |
-
|
1066 |
-
|
1067 |
-
|
1068 |
-
|
1069 |
-
|
1070 |
-
|
1071 |
-
|
1072 |
-
|
1073 |
-
|
1074 |
-
|
1075 |
-
|
1076 |
-
|
1077 |
-
|
1078 |
-
|
1079 |
-
|
1080 |
-
|
1081 |
-
|
1082 |
-
|
1083 |
-
|
1084 |
-
|
1085 |
-
|
1086 |
-
|
1087 |
-
|
1088 |
-
|
1089 |
-
|
1090 |
-
|
1091 |
-
|
1092 |
-
|
1093 |
-
|
1094 |
-
|
1095 |
-
|
1096 |
-
|
1097 |
-
|
1098 |
-
|
1099 |
-
|
1100 |
-
|
1101 |
-
|
1102 |
-
|
1103 |
-
|
1104 |
-
|
1105 |
-
|
1106 |
-
|
1107 |
-
|
1108 |
-
|
1109 |
-
|
1110 |
-
|
1111 |
-
|
1112 |
-
|
1113 |
-
|
1114 |
-
|
1115 |
-
|
|
|
|
|
1116 |
|
1117 |
# 修訂文法與拼字錯誤
|
1118 |
with gr.Row():
|
@@ -1159,23 +1190,19 @@ with gr.Blocks(theme=gr.themes.Soft(primary_hue=gr.themes.colors.blue, secondary
|
|
1159 |
|
1160 |
with gr.Row() as paragraph_correct_grammatical_spelling_errors_html:
|
1161 |
gr.Markdown("# Step 7. 修訂文法與拼字錯誤")
|
1162 |
-
|
1163 |
-
|
1164 |
-
|
1165 |
-
|
1166 |
-
|
1167 |
-
gr.Markdown("""
|
1168 |
-
- 段落寫作的過程,如果全程採用 JUTOR 的建議例句,則不會有文法與拼字錯誤。JUTOR 有時後仍會挑出一些字詞修訂,並非原本字詞錯誤,而是改換不同說法,你可以參考。
|
1169 |
-
- 若是自行完成段落寫作,則不會發生自我修訂的混淆狀況。
|
1170 |
-
""")
|
1171 |
with gr.Row():
|
1172 |
with gr.Column():
|
1173 |
paragraph_correct_grammatical_spelling_errors_input = gr.Textbox(label="這是你的原始寫作內容,參考 JUTOR 的改正,你可以選擇是否修改:", show_copy_button=True)
|
1174 |
with gr.Column():
|
1175 |
-
generate_correct_grammatical_spelling_errors_button = gr.Button("修訂文法與拼字錯誤", variant="primary")
|
1176 |
correct_grammatical_spelling_errors_output_table = gr.Dataframe(label="修訂文法與拼字錯誤", interactive=False)
|
1177 |
revised_paragraph_output = gr.Textbox(label="Revised Paragraph", show_copy_button=True, visible=False)
|
1178 |
-
gr.Markdown("##
|
1179 |
revised_paragraph_diff = gr.HTML()
|
1180 |
|
1181 |
# 段落改善建議
|
@@ -1223,12 +1250,13 @@ with gr.Blocks(theme=gr.themes.Soft(primary_hue=gr.themes.colors.blue, secondary
|
|
1223 |
with gr.Column():
|
1224 |
paragraph_refine_input = gr.Textbox(label="這是你的原始寫作內容,參考 JUTOR 的建議,你可以選擇是否修改:", show_copy_button=True)
|
1225 |
with gr.Column():
|
1226 |
-
generate_refine_paragraph_button = gr.Button("段落改善建議", variant="primary")
|
1227 |
refine_output_table = gr.DataFrame(label="Refine Paragraph 段落改善建議", wrap=True, interactive=False)
|
1228 |
refine_output = gr.HTML(label="修改建議", visible=False)
|
1229 |
-
gr.Markdown("##
|
1230 |
refine_output_diff = gr.HTML()
|
1231 |
|
|
|
1232 |
generate_paragraph_evaluate_button.click(
|
1233 |
fn=generate_paragraph_evaluate,
|
1234 |
inputs=[
|
@@ -1244,6 +1272,7 @@ with gr.Blocks(theme=gr.themes.Soft(primary_hue=gr.themes.colors.blue, secondary
|
|
1244 |
outputs=paragraph_correct_grammatical_spelling_errors_input
|
1245 |
)
|
1246 |
|
|
|
1247 |
generate_correct_grammatical_spelling_errors_button.click(
|
1248 |
fn=generate_correct_grammatical_spelling_errors,
|
1249 |
inputs=[
|
@@ -1267,6 +1296,7 @@ with gr.Blocks(theme=gr.themes.Soft(primary_hue=gr.themes.colors.blue, secondary
|
|
1267 |
outputs=paragraph_refine_input
|
1268 |
)
|
1269 |
|
|
|
1270 |
generate_refine_paragraph_button.click(
|
1271 |
fn=generate_refine_paragraph,
|
1272 |
inputs=[
|
@@ -1572,6 +1602,33 @@ with gr.Blocks(theme=gr.themes.Soft(primary_hue=gr.themes.colors.blue, secondary
|
|
1572 |
outputs=past_exam_refine_output_diff
|
1573 |
)
|
1574 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1575 |
# =====中文全文批改=====
|
1576 |
with gr.Tab("中文全文批改"):
|
1577 |
with gr.Row(visible=False) as chinese_full_paragraph_params:
|
|
|
27 |
def update_scenario_input(scenario_radio):
|
28 |
return scenario_radio
|
29 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
30 |
def get_exam_history():
|
31 |
exam_history = """
|
32 |
92
|
|
|
103 |
|
104 |
return exam_history
|
105 |
|
106 |
+
def generate_topics(model, max_tokens, sys_content, scenario, eng_level, user_generate_topics_prompt):
|
107 |
+
"""
|
108 |
+
根据系统提示和用户输入的情境及主题,调用OpenAI API生成相关的主题句。
|
109 |
+
"""
|
110 |
+
|
111 |
+
exam_history = get_exam_history()
|
112 |
+
exam_history_prompt = f"""
|
113 |
+
Please refer a topic scenario from the following exam history:
|
114 |
+
{exam_history}
|
115 |
+
Base on English level to give similar topic scenario. But don't use the same topic scenario.
|
116 |
+
"""
|
117 |
+
|
118 |
+
user_content = f"""
|
119 |
+
english level is: {eng_level}
|
120 |
+
---
|
121 |
+
exam_history_prompt: {exam_history_prompt}
|
122 |
+
---
|
123 |
+
{user_generate_topics_prompt}
|
124 |
+
"""
|
125 |
+
messages = [
|
126 |
+
{"role": "system", "content": sys_content},
|
127 |
+
{"role": "user", "content": user_content}
|
128 |
+
]
|
129 |
+
|
130 |
+
request_payload = {
|
131 |
+
"model": model,
|
132 |
+
"messages": messages,
|
133 |
+
"max_tokens": max_tokens,
|
134 |
+
"response_format": { "type": "json_object" }
|
135 |
+
}
|
136 |
+
|
137 |
+
response = OPEN_AI_CLIENT.chat.completions.create(**request_payload)
|
138 |
+
content = response.choices[0].message.content
|
139 |
+
topics = json.loads(content)["topics"]
|
140 |
+
|
141 |
+
print(f"====generate_topics====")
|
142 |
+
print(topics)
|
143 |
+
|
144 |
+
gr_update = gr.update(choices=topics, visible=True)
|
145 |
+
|
146 |
+
return gr_update
|
147 |
+
|
148 |
+
def update_topic_input(topic):
|
149 |
+
return topic
|
150 |
+
|
151 |
+
def generate_points(model, max_tokens, sys_content, scenario, eng_level, topic, user_generate_points_prompt):
|
152 |
+
"""
|
153 |
+
根据系统提示和用户输入的情境、主题,调用OpenAI API生成相关的主题句。
|
154 |
+
"""
|
155 |
+
user_content = f"""
|
156 |
+
scenario is: {scenario}
|
157 |
+
english level is: {eng_level}
|
158 |
+
topic is: {topic}
|
159 |
+
---
|
160 |
+
{user_generate_points_prompt}
|
161 |
+
"""
|
162 |
+
messages = [
|
163 |
+
{"role": "system", "content": sys_content},
|
164 |
+
{"role": "user", "content": user_content}
|
165 |
+
]
|
166 |
+
|
167 |
+
request_payload = {
|
168 |
+
"model": model,
|
169 |
+
"messages": messages,
|
170 |
+
"max_tokens": max_tokens,
|
171 |
+
}
|
172 |
+
|
173 |
+
response = OPEN_AI_CLIENT.chat.completions.create(**request_payload)
|
174 |
+
content = response.choices[0].message.content
|
175 |
+
points = json.loads(content)["points"]
|
176 |
+
gr_update = gr.update(choices=points, visible=True)
|
177 |
+
|
178 |
+
return gr_update
|
179 |
+
|
180 |
+
def update_points_input(points):
|
181 |
+
return points
|
182 |
+
|
183 |
+
|
184 |
+
|
185 |
def generate_topic_sentences(model, max_tokens, sys_content, scenario, eng_level, topic, points, user_generate_topic_sentences_prompt):
|
186 |
"""
|
187 |
根据系统提示和用户输入的情境及要点,调用OpenAI API生成相关的主题句及其合理性解释。
|
|
|
223 |
response = OPEN_AI_CLIENT.chat.completions.create(**request_payload)
|
224 |
response_content = json.loads(response.choices[0].message.content)
|
225 |
json_content = response_content["results"]
|
226 |
+
topic_sentences_list = [item["topic-sentence"] for item in json_content]
|
227 |
+
random.shuffle(topic_sentences_list)
|
228 |
+
|
229 |
+
gr_update_json = gr.update(value=json_content)
|
230 |
+
gr_update_radio = gr.update(choices=topic_sentences_list, visible=True)
|
231 |
|
232 |
+
return gr_update_json, gr_update_radio
|
|
|
233 |
|
234 |
+
def update_topic_sentence_input(topic_sentences_json, selected_topic_sentence):
|
|
|
|
|
235 |
topic_sentence_input = ""
|
236 |
+
for ts in topic_sentences_json:
|
237 |
if ts["topic-sentence"] == selected_topic_sentence:
|
238 |
appropriate = "O 適合" if ts["appropriate"] == "Y" else "X 不適合"
|
239 |
border_color = "green" if ts["appropriate"] == "Y" else "red"
|
|
|
250 |
topic_sentence_input = ts["topic-sentence"] if ts["appropriate"] == "Y" else ""
|
251 |
break
|
252 |
|
253 |
+
gr_suggestion_html = gr.update(value=suggestion_html, visible=True)
|
254 |
+
|
255 |
+
return topic_sentence_input, gr_suggestion_html
|
256 |
|
257 |
def generate_supporting_sentences(model, max_tokens, sys_content, scenario, eng_level, topic, points, topic_sentence, user_generate_supporting_sentences_prompt):
|
258 |
"""
|
|
|
280 |
|
281 |
response = OPEN_AI_CLIENT.chat.completions.create(**request_payload)
|
282 |
content = response.choices[0].message.content.strip()
|
283 |
+
gr_update = gr.update(choices=[content], visible=True)
|
284 |
|
285 |
return gr_update
|
286 |
|
|
|
315 |
response = OPEN_AI_CLIENT.chat.completions.create(**request_payload)
|
316 |
response_content = json.loads(response.choices[0].message.content)
|
317 |
json_content = response_content["results"]
|
318 |
+
gr_update = gr.update(choices=[json_content], visible=True)
|
319 |
|
320 |
return gr_update
|
321 |
|
|
|
367 |
["JUTOR 架構|連貫性和連接詞(Coherence and Cohesion)", data['coherence_and_cohesion']['level'], data['coherence_and_cohesion']['explanation']]
|
368 |
]
|
369 |
headers = ["架構", "評分", "解釋"]
|
370 |
+
gr_update = gr.update(value=table_data, headers=headers, visible=True)
|
371 |
|
372 |
return gr_update
|
373 |
|
|
|
591 |
def show_elements():
|
592 |
return gr.update(visible=True)
|
593 |
|
594 |
+
def hide_elements():
|
595 |
+
return gr.update(visible=False)
|
596 |
+
|
597 |
+
def generate_chinese_essay_idea(model, user_prompt, chinese_essay_title_input):
|
598 |
+
sys_content = "你是一位老師,正在和我一起練習提高我的寫作技能。 給予的回覆不超過 500字。 用 Markdown 語法回答。"
|
599 |
+
user_content = f"""
|
600 |
+
{user_prompt}
|
601 |
+
---
|
602 |
+
題目:{chinese_essay_title_input}
|
603 |
+
"""
|
604 |
+
messages = [
|
605 |
+
{"role": "system", "content": sys_content},
|
606 |
+
{"role": "user", "content": user_content}
|
607 |
+
]
|
608 |
+
|
609 |
+
request_payload = {
|
610 |
+
"model": model,
|
611 |
+
"messages": messages,
|
612 |
+
"max_tokens": 2000,
|
613 |
+
}
|
614 |
+
|
615 |
+
response = OPEN_AI_CLIENT.chat.completions.create(**request_payload)
|
616 |
+
content = response.choices[0].message.content.strip()
|
617 |
+
|
618 |
+
return content
|
619 |
+
|
620 |
# elem_classes=['accordion-prompts']
|
621 |
CSS = """
|
622 |
.accordion-prompts {
|
|
|
633 |
max_tokens = gr.Slider(minimum=50, maximum=4000, value=4000, label="Max Tokens")
|
634 |
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.")
|
635 |
with gr.Row():
|
636 |
+
eng_level_input = gr.Radio([("初學", "beginner"), ("進階", "advanced")], label="English Level", value="beginner")
|
637 |
|
638 |
# basic inputs 主題與情境
|
639 |
with gr.Group():
|
|
|
705 |
user_generate_topics_prompt = gr.Textbox(label="Topics Prompt", value=default_generate_topics_prompt, visible=False)
|
706 |
with gr.Row():
|
707 |
with gr.Column():
|
708 |
+
topic_input = gr.Textbox(label="自訂主題:")
|
709 |
with gr.Column():
|
710 |
+
generate_topics_button = gr.Button("✨ JUTOR 隨機產出 10 個段落主題,挑選一個來練習吧!", variant="primary")
|
711 |
+
topic_output = gr.Radio(label="AI 產出主題", visible=False, interactive=True)
|
712 |
+
|
713 |
generate_topics_button.click(
|
714 |
fn=show_elements,
|
715 |
inputs=[],
|
|
|
727 |
outputs=[topic_output]
|
728 |
)
|
729 |
|
730 |
+
topic_output.select(
|
731 |
+
fn=update_topic_input,
|
732 |
+
inputs=[topic_output],
|
733 |
+
outputs=[topic_input]
|
734 |
+
)
|
735 |
+
|
|
|
|
|
|
|
|
|
736 |
|
737 |
# Step 2. 寫出關鍵字
|
738 |
with gr.Row():
|
|
|
755 |
with gr.Row():
|
756 |
gr.Markdown("## 根據主題,思考段落的方向及內容,然後用兩個要點/關鍵字來呈現。例如主題:「The Benefits of Learning a Second Language 學習第二種語言的好處」,內容及方向:因為學習第二種語言,例如日語,就可以和日本人溝通,進而學習瞭解日本文化,因而要點/關鍵字就是「Improving communication skills 提升溝通能力」及「Understanding other cultures 瞭解其他文化」。")
|
757 |
with gr.Row():
|
758 |
+
gr.Markdown("## 如果不知道要寫什麼,也可以讓Jutor提供要點/關鍵字,以兩個要點/關鍵字為限。")
|
759 |
with gr.Row():
|
760 |
with gr.Column():
|
761 |
+
points_input = gr.Textbox(label="寫出要點/關鍵字")
|
762 |
with gr.Column():
|
763 |
generate_points_button = gr.Button("✨ 找尋靈感?使用 JUTOR 產生要點/關鍵字", variant="primary")
|
764 |
+
points_output = gr.Radio(label="AI 產出要點/關鍵字", visible=False, interactive=True)
|
|
|
765 |
generate_points_button.click(
|
766 |
fn=show_elements,
|
767 |
inputs=[],
|
|
|
779 |
],
|
780 |
outputs=points_output
|
781 |
)
|
782 |
+
|
783 |
+
points_output.select(
|
784 |
+
fn=update_points_input,
|
785 |
+
inputs=[points_output],
|
786 |
+
outputs=[points_input]
|
787 |
+
)
|
|
|
|
|
|
|
|
|
|
|
788 |
|
789 |
# Step 3. 選定主題句
|
790 |
with gr.Row():
|
|
|
812 |
user_generate_topic_sentences_prompt = gr.Textbox(label="Topic Sentences Prompt", value=default_generate_topic_sentences_prompt, visible=False)
|
813 |
|
814 |
with gr.Row() as topic_sentences_html:
|
815 |
+
gr.Markdown("# Step 3. 寫主題句")
|
816 |
with gr.Row():
|
817 |
with gr.Column():
|
818 |
gr.Markdown("## 主題句(Topic Sentence)通常位於段落的開頭,幫助讀者迅速理解段落的內容。是段落中最重要的句子,介紹主題並含括段落的所有要點/關鍵字。")
|
|
|
823 |
gr.Markdown("""舉例,情境是 `School & Learning`,段落主題是 `Time Management`,那麼 `Balancing school work and leisure time is a crucial aspect of effective time management` 就是合適的主題句,因為它清楚點出該段落將説明有效運用時間來讓課業及娛樂取得平衡。""")
|
824 |
with gr.Row():
|
825 |
with gr.Column():
|
826 |
+
topic_sentence_input = gr.Textbox(label="寫出主題句")
|
827 |
with gr.Column():
|
828 |
+
generate_topic_sentences_button = gr.Button("✨ JUTOR 產出三個主題句,選出一個最合適的", variant="primary")
|
829 |
+
topic_sentence_output_json = gr.JSON(label="AI 產出主題句", visible=False)
|
830 |
+
topic_sentence_output_radio = gr.Radio(label="AI 產出主題句", interactive=True, visible=False)
|
831 |
+
topic_sentences_suggestions = gr.HTML(visible=False)
|
832 |
+
|
833 |
generate_topic_sentences_button.click(
|
834 |
fn=show_elements,
|
835 |
inputs=[],
|
836 |
+
outputs=[topic_sentence_output_radio]
|
837 |
+
).then(
|
838 |
+
fn=hide_elements,
|
839 |
+
inputs=[],
|
840 |
+
outputs=[topic_sentences_suggestions]
|
841 |
).then(
|
842 |
fn=generate_topic_sentences,
|
843 |
inputs=[
|
|
|
850 |
points_input,
|
851 |
user_generate_topic_sentences_prompt
|
852 |
],
|
853 |
+
outputs=[topic_sentence_output_json, topic_sentence_output_radio]
|
854 |
)
|
855 |
|
856 |
+
topic_sentence_output_radio.select(
|
857 |
+
fn=update_topic_sentence_input,
|
858 |
+
inputs=[topic_sentence_output_json, topic_sentence_output_radio],
|
859 |
+
outputs= [topic_sentence_input, topic_sentences_suggestions]
|
860 |
+
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
861 |
|
862 |
# Step 4.寫出支持句
|
863 |
with gr.Row():
|
|
|
889 |
with gr.Row():
|
890 |
with gr.Column():
|
891 |
with gr.Row():
|
892 |
+
gr.Markdown("## 支持句:以支持句來解釋要點,必要時舉例説明,來支持主題句。這些句子應該按照邏輯順序來組織,例如時間順序、空間順序、重要性順序、因果關係等。並使用轉折詞來引導讀者從一個 idea 到下一個 idea,讓讀者讀起來很順暢,不需反覆閱讀。")
|
|
|
|
|
893 |
with gr.Column():
|
894 |
with gr.Accordion("參考指引:撰寫支持句的方法?", open=False):
|
895 |
gr.Markdown("""
|
|
|
911 |
with gr.Column():
|
912 |
supporting_sentences_input = gr.Textbox(label="根據要點/關鍵字來寫支持句")
|
913 |
with gr.Column():
|
914 |
+
generate_supporting_sentences_button = gr.Button("✨ JUTOR 產出支持句,供參考並自行寫出支持句", variant="primary")
|
915 |
+
supporting_sentences_output = gr.Radio(label="AI 產出支持句", elem_id="supporting_sentences_button", visible=False, interactive=True)
|
916 |
|
917 |
generate_supporting_sentences_button.click(
|
918 |
+
fn=show_elements,
|
919 |
+
inputs=[],
|
920 |
+
outputs=[supporting_sentences_output]
|
921 |
+
).then(
|
922 |
fn=generate_supporting_sentences,
|
923 |
inputs=[
|
924 |
model,
|
|
|
981 |
with gr.Column():
|
982 |
conclusion_sentence_input = gr.Textbox(label="寫出總結段落的結論句")
|
983 |
with gr.Column():
|
984 |
+
generate_conclusion_sentence_button = gr.Button("✨ JUTOR 產出結論句,供參考並自行寫出支持句", variant="primary")
|
985 |
+
conclusion_sentence_output = gr.Radio(label="AI 產出結論句", visible=False, interactive=True)
|
986 |
|
987 |
generate_conclusion_sentence_button.click(
|
988 |
+
fn=show_elements,
|
989 |
+
inputs=[],
|
990 |
+
outputs=[conclusion_sentence_output]
|
991 |
+
).then(
|
992 |
fn=generate_conclusion_sentences,
|
993 |
inputs=[
|
994 |
model,
|
|
|
1017 |
gr.Markdown("# Step 6. 段落確認與修訂")
|
1018 |
with gr.Row():
|
1019 |
with gr.Column():
|
1020 |
+
gr.Markdown("""## 你已經完成段落草稿,可再檢視幾次:
|
1021 |
+
### 1. 找出文法、拼字或標點錯誤
|
1022 |
+
### 2. 需要之處加入合適的轉折詞,例如:first, second, however, moreover, etc.
|
1023 |
+
### 3. 整個段落是否連貫、流暢、容易理解
|
1024 |
""")
|
1025 |
with gr.Column():
|
1026 |
with gr.Accordion("參考指引:什麼是段落的連貫性?", open=False):
|
|
|
1038 |
- 最後,段落應該有一個結論句,總結主要觀點,強化所要傳遞的資訊。
|
1039 |
""")
|
1040 |
with gr.Row():
|
1041 |
+
with gr.Column():
|
1042 |
+
with gr.Row():
|
1043 |
+
generate_paragraph_button = gr.Button("閱讀並修訂草稿", variant="primary")
|
1044 |
+
with gr.Row():
|
1045 |
+
paragraph_output = gr.Textbox(label="完整段落", show_copy_button=True)
|
1046 |
+
|
1047 |
+
generate_paragraph_button.click(
|
1048 |
+
fn=generate_paragraph,
|
1049 |
+
inputs=[
|
1050 |
+
topic_sentence_input,
|
1051 |
+
supporting_sentences_input,
|
1052 |
+
conclusion_sentence_input
|
1053 |
+
],
|
1054 |
+
outputs=paragraph_output
|
1055 |
+
)
|
1056 |
+
with gr.Column():
|
1057 |
+
with gr.Row(visible=False) as paragraph_evaluate_params:
|
1058 |
+
default_user_generate_paragraph_evaluate_prompt = """
|
1059 |
+
Based on the final paragraph provided, evaluate the writing in terms of content, organization, grammar, and vocabulary. Provide feedback in simple and supportive language.
|
1060 |
+
|
1061 |
+
-- 根據上述的文章,以「內容(content)」層面評分。
|
1062 |
+
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:
|
1063 |
+
|
1064 |
+
- Excellent (5-4 points): Look for a clear and pertinent theme or thesis, directly related to the topic, with detailed support.
|
1065 |
+
- Good (3 points): The theme should be present but may lack clarity or emphasis; some narrative development related to the theme should be evident.
|
1066 |
+
- Fair (2-1 points): Identify if the theme is unclear or if the majority of the narrative is undeveloped or irrelevant to the theme.
|
1067 |
+
- 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.
|
1068 |
+
|
1069 |
+
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.
|
1070 |
+
Translate your feedback into Traditional Chinese (zh-tw) as the final result (#中文解釋 zh-TW).
|
1071 |
+
|
1072 |
+
評分結果以 JSON 格式輸出: content: {
|
1073 |
+
"level": "#Excellent(5-4 pts)/Good(3 pts)/Fair(2-1 pts)/Poor(0 pts)",
|
1074 |
+
"explanation": "#中文解釋 zh-TW"
|
1075 |
+
}
|
1076 |
+
|
1077 |
+
-- 根據上述的文章,以「組織(organization)」層面評分。
|
1078 |
+
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:
|
1079 |
+
|
1080 |
+
- 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.
|
1081 |
+
- Good (3 points): The key points should be identifiable but may not be well-arranged; observe any imbalance in development and transitional phrase usage.
|
1082 |
+
- Fair (2-1 points): Identify if the key points are unclear and if the text lacks coherence.
|
1083 |
+
- 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.
|
1084 |
+
|
1085 |
+
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 (#中文解釋).
|
1086 |
+
|
1087 |
+
評分結果以 JSON 格式輸出: organization: {
|
1088 |
+
"level": "#Excellent(5-4 pts)/Good(3 pts)/Fair(2-1 pts)/Poor(0 pts)",
|
1089 |
+
"explanation": "#中文解釋 zh-TW"
|
1090 |
+
}
|
1091 |
+
|
1092 |
+
-- 根據上述的文章,以「文法和用法(Grammar and usage)」層面評分。
|
1093 |
+
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:
|
1094 |
+
|
1095 |
+
- Excellent (5-4 points): Search for text with minimal grammatical errors and a diverse range of sentence structures.
|
1096 |
+
- Good (3 points): There may be some grammatical errors, but they should not affect the overall meaning or flow of the text.
|
1097 |
+
- Fair (2-1 points): Determine if grammatical errors are frequent and if they significantly affect the meaning of the text.
|
1098 |
+
- Poor (0 points): If the essay contains severe grammatical errors throughout, leading to an unclear meaning, it should be marked accordingly.
|
1099 |
+
|
1100 |
+
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 (#中文解釋).
|
1101 |
+
|
1102 |
+
評分結果以 JSON 格式輸出: grammar_and_usage: {
|
1103 |
+
"level": "#Excellent(5-4 pts)/Good(3 pts)/Fair(2-1 pts)/Poor(0 pts)",
|
1104 |
+
"explanation": "#中文解釋 zh-TW"
|
1105 |
+
}
|
1106 |
+
|
1107 |
+
-- 根據上述的文章,以「詞彙(Vocabulary )」層面評分。
|
1108 |
+
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:
|
1109 |
+
|
1110 |
+
- Excellent (5-4 points): The writing should contain accurate and appropriate vocabulary with almost no spelling mistakes.
|
1111 |
+
- 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.
|
1112 |
+
- Fair (2-1 points): Notice if there are many vocabulary errors and spelling mistakes that clearly affect the clarity of the text's meaning.
|
1113 |
+
- Poor (0 points): Writing that only contains scattered words related to the topic or is copied should be scored as such.
|
1114 |
+
|
1115 |
+
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 (#中文解釋).
|
1116 |
+
|
1117 |
+
評分結果以 JSON 格式輸出: vocabulary: {
|
1118 |
+
"level": "#Excellent(5-4 pts)/Good(3 pts)/Fair(2-1 pts)/Poor(0 pts)",
|
1119 |
+
"explanation": "#中文解釋 zh-TW"
|
1120 |
+
}
|
1121 |
+
|
1122 |
+
-- 根據上述的文章,以「連貫性和連接詞(Coherence and Cohesion)」層面評分。
|
1123 |
+
- 評分等級有三級:beginner, intermediate, advanced.
|
1124 |
+
- 以繁體中文 zh-TW 解釋
|
1125 |
+
評分結果以 JSON 格式輸出: coherence_and_cohesion: {
|
1126 |
+
"level": "#beginner/intermediate/advanced",
|
1127 |
+
"explanation": "#中文解釋 zh-TW"
|
1128 |
+
}
|
1129 |
+
|
1130 |
+
Restrictions:
|
1131 |
+
- the _explanation should be in Traditional Chinese (zh-TW), it's very important.
|
1132 |
+
|
1133 |
+
Final Output JSON Format:
|
1134 |
+
{{
|
1135 |
+
“content“: {{content’s dict}},
|
1136 |
+
“organization“: {{organization'dict}},
|
1137 |
+
“grammar_and_usage“: {{grammar_and_usage'dict}},
|
1138 |
+
“vocabulary“: {{vocabulary'dict}},
|
1139 |
+
“coherence_and_cohesion“: {{coherence_and_cohesion'dict}}
|
1140 |
+
}}
|
1141 |
+
"""
|
1142 |
+
user_generate_paragraph_evaluate_prompt = gr.Textbox(label="Paragraph evaluate Prompt", value=default_user_generate_paragraph_evaluate_prompt, visible=False)
|
1143 |
+
with gr.Row():
|
1144 |
+
generate_paragraph_evaluate_button = gr.Button("✨ 段落分析", variant="primary")
|
1145 |
+
with gr.Row():
|
1146 |
+
paragraph_evaluate_output = gr.Dataframe(label="完整段落分析", wrap=True, column_widths=[35, 15, 50], interactive=False)
|
1147 |
|
1148 |
# 修訂文法與拼字錯誤
|
1149 |
with gr.Row():
|
|
|
1190 |
|
1191 |
with gr.Row() as paragraph_correct_grammatical_spelling_errors_html:
|
1192 |
gr.Markdown("# Step 7. 修訂文法與拼字錯誤")
|
1193 |
+
with gr.Accordion("參考指引:AI 的混淆狀況?", open=False):
|
1194 |
+
gr.Markdown("""
|
1195 |
+
- 段落寫作的過程,如果全程採用 JUTOR 的建議例句,則不會有文法與拼字錯誤。JUTOR 有時後仍會挑出一些字詞修訂,並非原本字詞錯誤,而是改換不同說法,你可以參考。
|
1196 |
+
- 若是自行完成段落寫作,則不會發生自我修訂的混淆狀況。
|
1197 |
+
""")
|
|
|
|
|
|
|
|
|
1198 |
with gr.Row():
|
1199 |
with gr.Column():
|
1200 |
paragraph_correct_grammatical_spelling_errors_input = gr.Textbox(label="這是你的原始寫作內容,參考 JUTOR 的改正,你可以選擇是否修改:", show_copy_button=True)
|
1201 |
with gr.Column():
|
1202 |
+
generate_correct_grammatical_spelling_errors_button = gr.Button("✨ 修訂文法與拼字錯誤", variant="primary")
|
1203 |
correct_grammatical_spelling_errors_output_table = gr.Dataframe(label="修訂文法與拼字錯誤", interactive=False)
|
1204 |
revised_paragraph_output = gr.Textbox(label="Revised Paragraph", show_copy_button=True, visible=False)
|
1205 |
+
gr.Markdown("## 修改參考")
|
1206 |
revised_paragraph_diff = gr.HTML()
|
1207 |
|
1208 |
# 段落改善建議
|
|
|
1250 |
with gr.Column():
|
1251 |
paragraph_refine_input = gr.Textbox(label="這是你的原始寫作內容,參考 JUTOR 的建議,你可以選擇是否修改:", show_copy_button=True)
|
1252 |
with gr.Column():
|
1253 |
+
generate_refine_paragraph_button = gr.Button("✨ 段落改善建議", variant="primary")
|
1254 |
refine_output_table = gr.DataFrame(label="Refine Paragraph 段落改善建議", wrap=True, interactive=False)
|
1255 |
refine_output = gr.HTML(label="修改建議", visible=False)
|
1256 |
+
gr.Markdown("## 修改參考")
|
1257 |
refine_output_diff = gr.HTML()
|
1258 |
|
1259 |
+
# 段落分析
|
1260 |
generate_paragraph_evaluate_button.click(
|
1261 |
fn=generate_paragraph_evaluate,
|
1262 |
inputs=[
|
|
|
1272 |
outputs=paragraph_correct_grammatical_spelling_errors_input
|
1273 |
)
|
1274 |
|
1275 |
+
# 修訂文法與拼字錯誤
|
1276 |
generate_correct_grammatical_spelling_errors_button.click(
|
1277 |
fn=generate_correct_grammatical_spelling_errors,
|
1278 |
inputs=[
|
|
|
1296 |
outputs=paragraph_refine_input
|
1297 |
)
|
1298 |
|
1299 |
+
# 段落改善建議
|
1300 |
generate_refine_paragraph_button.click(
|
1301 |
fn=generate_refine_paragraph,
|
1302 |
inputs=[
|
|
|
1602 |
outputs=past_exam_refine_output_diff
|
1603 |
)
|
1604 |
|
1605 |
+
# =====中文作文工具=====
|
1606 |
+
with gr.Tab("中文作文工具"):
|
1607 |
+
# 輸入題目、輸出靈感
|
1608 |
+
with gr.Row():
|
1609 |
+
chinese_write_idea_prompt = """
|
1610 |
+
你是一位國文老師,善於引導學生寫作。請根據以下的題目,幫助學生生成靈感:
|
1611 |
+
"""
|
1612 |
+
chinese_write_idea_prompt_input = gr.Textbox(label="System Prompt", value=chinese_write_idea_prompt, visible=False)
|
1613 |
+
with gr.Column():
|
1614 |
+
with gr.Row():
|
1615 |
+
gr.Markdown("# 中文作文工具")
|
1616 |
+
with gr.Row():
|
1617 |
+
gr.Markdown("## 輸入題目")
|
1618 |
+
with gr.Row():
|
1619 |
+
chinese_essay_title_input = gr.Textbox(label="輸入題目")
|
1620 |
+
with gr.Column():
|
1621 |
+
with gr.Row():
|
1622 |
+
chinese_essay_generate_button = gr.Button("生成靈感", variant="primary")
|
1623 |
+
with gr.Row():
|
1624 |
+
chinese_essay_idea_output = gr.Markdown(label="生成靈感")
|
1625 |
+
|
1626 |
+
chinese_essay_generate_button.click(
|
1627 |
+
fn=generate_chinese_essay_idea,
|
1628 |
+
inputs=[model, chinese_write_idea_prompt_input, chinese_essay_title_input],
|
1629 |
+
outputs=chinese_essay_idea_output
|
1630 |
+
)
|
1631 |
+
|
1632 |
# =====中文全文批改=====
|
1633 |
with gr.Tab("中文全文批改"):
|
1634 |
with gr.Row(visible=False) as chinese_full_paragraph_params:
|