Spaces:
Sleeping
Sleeping
chinese_full_paragraph_input_history = content_json["chinese_full_paragraph_input"]
Browse files
app.py
CHANGED
@@ -1016,13 +1016,13 @@ def get_chinese_paragraph_practice_log_session_content(file_name):
|
|
1016 |
content = GCS_SERVICE.download_as_string("jutor_logs", file_name)
|
1017 |
print(f"content: {content}")
|
1018 |
content_json = json.loads(content)
|
1019 |
-
chinese_full_paragraph_input_history = content_json["chinese_full_paragraph_input"]
|
1020 |
chinese_full_paragraph_evaluate_output_text_history = content_json["chinese_full_paragraph_evaluate_output_text"] if "chinese_full_paragraph_evaluate_output_text" in content_json else ""
|
1021 |
-
chinese_full_paragraph_evaluate_output_table_history = pd.DataFrame(content_json["chinese_full_paragraph_evaluate_output_table"])
|
1022 |
-
chinese_full_paragraph_refine_input_history = content_json["chinese_full_paragraph_refine_input"]
|
1023 |
-
chinese_full_paragraph_refine_output_text_history = content_json["chinese_full_paragraph_refine_output_text"]
|
1024 |
-
chinese_full_paragraph_refine_output_table_history = pd.DataFrame(content_json["chinese_full_paragraph_refine_output_table"])
|
1025 |
-
chinese_full_paragraph_save_output_history = content_json["chinese_full_paragraph_save_output"]
|
1026 |
|
1027 |
assignment_id = content_json["assignment_id"] if "assignment_id" in content_json else ""
|
1028 |
if assignment_id:
|
@@ -1123,8 +1123,17 @@ def assign_grade(subject_content, structure, diction, spelling_punctuation):
|
|
1123 |
# 預設為 🟡
|
1124 |
return "🟡"
|
1125 |
|
1126 |
-
def
|
1127 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1128 |
print(f"====generate_paragraph_evaluate====")
|
1129 |
print(content)
|
1130 |
|
@@ -1158,7 +1167,7 @@ def get_chinese_paragraph_evaluate_content(model, user_content):
|
|
1158 |
return total_content_text, content_table
|
1159 |
|
1160 |
|
1161 |
-
def get_chinese_paragraph_1st_evaluate_content(model, sys_content, paragraph, user_generate_paragraph_evaluate_prompt):
|
1162 |
verify_string_length(paragraph)
|
1163 |
verify_moderation(paragraph)
|
1164 |
|
@@ -1169,25 +1178,22 @@ def get_chinese_paragraph_1st_evaluate_content(model, sys_content, paragraph, us
|
|
1169 |
---
|
1170 |
{user_generate_paragraph_evaluate_prompt}
|
1171 |
"""
|
1172 |
-
total_content_text, content_table = get_chinese_paragraph_evaluate_content(model, user_content)
|
1173 |
|
1174 |
return total_content_text, content_table
|
1175 |
|
1176 |
-
def get_chinese_paragraph_refine_evaluate_content(model, sys_content,
|
1177 |
-
verify_string_length(paragraph_1)
|
1178 |
verify_string_length(paragraph_2)
|
1179 |
-
verify_moderation(
|
1180 |
|
1181 |
user_content = f"""
|
1182 |
sys_content: {sys_content}
|
1183 |
---
|
1184 |
-
original paragraph is: {paragraph_1}
|
1185 |
-
---
|
1186 |
refined paragraph is: {paragraph_2}
|
1187 |
---
|
1188 |
{user_refine_paragraph_prompt}
|
1189 |
"""
|
1190 |
-
total_content_text, content_table = get_chinese_paragraph_evaluate_content(model, user_content)
|
1191 |
|
1192 |
return total_content_text, content_table
|
1193 |
|
@@ -1205,12 +1211,8 @@ def generate_content_by_open_ai_assistant(user_content, thread_id=None, model_na
|
|
1205 |
print(f"instructions: {assistant.instructions}")
|
1206 |
|
1207 |
try:
|
1208 |
-
if not thread_id
|
1209 |
-
|
1210 |
-
thread_id = thread.id
|
1211 |
-
else:
|
1212 |
-
thread = client.beta.threads.retrieve(thread_id)
|
1213 |
-
|
1214 |
print(f"Thread ID: {thread.id}")
|
1215 |
|
1216 |
# if metadata:
|
@@ -2921,12 +2923,15 @@ with gr.Blocks(theme=THEME, css=CSS) as demo:
|
|
2921 |
js=english_logs_tab_button_js
|
2922 |
)
|
2923 |
|
2924 |
-
|
2925 |
with gr.Row(visible=False) as chinese_group:
|
2926 |
with gr.Column():
|
2927 |
with gr.Row() as page_title_chinese:
|
2928 |
gr.Markdown("# 🍄 CUTOR 國文段落寫作練習")
|
2929 |
|
|
|
|
|
|
|
2930 |
with gr.Row(visible=False) as chinese_assignment_row:
|
2931 |
with gr.Column():
|
2932 |
with gr.Row():
|
@@ -3025,55 +3030,33 @@ with gr.Blocks(theme=THEME, css=CSS) as demo:
|
|
3025 |
with gr.Row():
|
3026 |
chinese_full_paragraph_evaluate_output_table = gr.Dataframe(label="段落全文分析表格", wrap=True, column_widths=[20, 15, 65], interactive=False)
|
3027 |
|
3028 |
-
# JUTOR 段落批改與整體建議
|
3029 |
-
# with gr.Row():
|
3030 |
-
# gr.Markdown("# JUTOR 段落批改與整體建議")
|
3031 |
-
# with gr.Row():
|
3032 |
-
# gr.Markdown("## 修訂文法與拼字錯誤")
|
3033 |
-
# with gr.Row():
|
3034 |
-
# with gr.Column():
|
3035 |
-
# chinese_full_paragraph_correct_grammatical_spelling_errors_input = gr.TextArea(label="這是你的原始寫作內容,參考 JUTOR 的建議,你可以選擇是否修改:")
|
3036 |
-
# with gr.Column():
|
3037 |
-
# generate_chinese_full_paragraph_correct_grammatical_spelling_errors_button = gr.Button("修訂文法與拼字錯誤", variant="primary")
|
3038 |
-
# chinese_full_paragraph_correct_grammatical_spelling_errors_output_table = gr.Dataframe(label="修訂文法與拼字錯誤", interactive=False, column_widths=[30, 30, 40])
|
3039 |
-
# revised_chinese_full_paragraph_output = gr.Textbox(label="Revised Paragraph", show_copy_button=True, visible=False)
|
3040 |
-
# gr.Markdown("## 修訂結果")
|
3041 |
-
# revised_chinese_full_paragraph_diff = gr.HTML()
|
3042 |
-
|
3043 |
-
# JUTOR 段落批改與整體建議
|
3044 |
-
# with gr.Row():
|
3045 |
-
# gr.Markdown("## 段落改善建議")
|
3046 |
-
# with gr.Row():
|
3047 |
-
# with gr.Column():
|
3048 |
-
# chinese_full_paragraph_refine_input = gr.TextArea(label="這是你的原始寫作內容,參考 JUTOR 的建議,你可以選擇是否修改:", show_copy_button=True)
|
3049 |
-
# with gr.Column():
|
3050 |
-
# generate_chinese_full_paragraph_refine_button = gr.Button("段落改善建議", variant="primary")
|
3051 |
-
# chinese_full_paragraph_refine_output_table = gr.DataFrame(label="段落改善建議", wrap=True, interactive=False)
|
3052 |
-
# chinese_full_paragraph_refine_output = gr.HTML(label="修改建議", visible=False)
|
3053 |
-
# gr.Markdown("## 修改結果")
|
3054 |
-
# chinese_full_paragraph_refine_output_diff = gr.HTML()
|
3055 |
-
|
3056 |
# 修改文章
|
3057 |
with gr.Row():
|
3058 |
gr.Markdown("# 根據建議修改文章")
|
3059 |
with gr.Row(visible=False) as chinese_full_paragraph_refine_params:
|
3060 |
default_user_generate_chinese_full_paragraph_refine_evaluate_prompt = """
|
3061 |
# 請嚴格根據 instructions
|
3062 |
-
|
3063 |
-
1.
|
|
|
3064 |
2. 請確保作文或段落的內容完整,並且符合中文語法
|
3065 |
3. 如果是一篇亂打的文章請直接給予回饋:「這篇文章內容不完整,無法進行評分。」
|
3066 |
4. 如果無法進行評分 評分標準與回饋的內容跟等級,則為 X
|
3067 |
-
|
3068 |
-
|
3069 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
3070 |
2. 再將評分標準與回饋的內容以JSON格式輸出,並且請使用繁體中文(ZH-TW)來評分段落並輸出,用 ```json ..... ``` 包裹:
|
3071 |
3. please use Chinese language (ZH-TW) to evaluate the paragraph and output use JSON format:
|
|
|
3072 |
|
3073 |
EXAMPLE:
|
3074 |
-
# 整體評分: (🔴?🟡?🟢?)
|
3075 |
-
if 評分與回饋 都是 X,則整體評分給予 🔴。
|
3076 |
-
|
3077 |
# 綜合回饋(前後比較)
|
3078 |
你的文章...............(寫出一段話,比較兩篇作文的差異)
|
3079 |
|
@@ -3192,8 +3175,12 @@ with gr.Blocks(theme=THEME, css=CSS) as demo:
|
|
3192 |
)
|
3193 |
|
3194 |
chinese_full_paragraph_evaluate_button.click(
|
|
|
|
|
|
|
|
|
3195 |
fn=get_chinese_paragraph_1st_evaluate_content,
|
3196 |
-
inputs=[model, chinese_full_paragraph_sys_content_input, chinese_full_paragraph_input, user_generate_chinese_full_paragraph_evaluate_prompt],
|
3197 |
outputs=[chinese_full_paragraph_evaluate_output_text, chinese_full_paragraph_evaluate_output_table]
|
3198 |
).then(
|
3199 |
fn=duplicate_element,
|
@@ -3202,8 +3189,12 @@ with gr.Blocks(theme=THEME, css=CSS) as demo:
|
|
3202 |
)
|
3203 |
|
3204 |
generate_chinese_full_paragraph_refine_button.click(
|
|
|
|
|
|
|
|
|
3205 |
fn=get_chinese_paragraph_refine_evaluate_content,
|
3206 |
-
inputs=[model, chinese_full_paragraph_sys_content_input,
|
3207 |
outputs=[chinese_full_paragraph_refine_output_text, chinese_full_paragraph_refine_output_table]
|
3208 |
)
|
3209 |
|
@@ -3235,8 +3226,8 @@ with gr.Blocks(theme=THEME, css=CSS) as demo:
|
|
3235 |
gr.Markdown("<span style='color:#4e80ee'>作業說明</span>")
|
3236 |
chinese_assignment_description_history_log = gr.Markdown()
|
3237 |
|
3238 |
-
|
3239 |
-
|
3240 |
|
3241 |
with gr.Row():
|
3242 |
with gr.Column():
|
|
|
1016 |
content = GCS_SERVICE.download_as_string("jutor_logs", file_name)
|
1017 |
print(f"content: {content}")
|
1018 |
content_json = json.loads(content)
|
1019 |
+
chinese_full_paragraph_input_history = content_json["chinese_full_paragraph_input"] if "chinese_full_paragraph_input" in content_json else ""
|
1020 |
chinese_full_paragraph_evaluate_output_text_history = content_json["chinese_full_paragraph_evaluate_output_text"] if "chinese_full_paragraph_evaluate_output_text" in content_json else ""
|
1021 |
+
chinese_full_paragraph_evaluate_output_table_history = pd.DataFrame(content_json["chinese_full_paragraph_evaluate_output_table"]) if "chinese_full_paragraph_evaluate_output_table" in content_json else pd.DataFrame()
|
1022 |
+
chinese_full_paragraph_refine_input_history = content_json["chinese_full_paragraph_refine_input"] if "chinese_full_paragraph_refine_input" in content_json else ""
|
1023 |
+
chinese_full_paragraph_refine_output_text_history = content_json["chinese_full_paragraph_refine_output_text"] if "chinese_full_paragraph_refine_output_text" in content_json else ""
|
1024 |
+
chinese_full_paragraph_refine_output_table_history = pd.DataFrame(content_json["chinese_full_paragraph_refine_output_table"]) if "chinese_full_paragraph_refine_output_table" in content_json else pd.DataFrame()
|
1025 |
+
chinese_full_paragraph_save_output_history = content_json["chinese_full_paragraph_save_output"] if "chinese_full_paragraph_save_output" in content_json else ""
|
1026 |
|
1027 |
assignment_id = content_json["assignment_id"] if "assignment_id" in content_json else ""
|
1028 |
if assignment_id:
|
|
|
1123 |
# 預設為 🟡
|
1124 |
return "🟡"
|
1125 |
|
1126 |
+
def get_chinese_conversation_thread_id(thread_id):
|
1127 |
+
if thread_id:
|
1128 |
+
return thread_id
|
1129 |
+
else:
|
1130 |
+
client = CUTOR_OPEN_AI_CLIENT
|
1131 |
+
thread = client.beta.threads.create()
|
1132 |
+
thread_id = thread.id
|
1133 |
+
return thread_id
|
1134 |
+
|
1135 |
+
def get_chinese_paragraph_evaluate_content(thread_id, model, user_content):
|
1136 |
+
content = generate_content_by_open_ai_assistant(user_content, thread_id, model_name=model)
|
1137 |
print(f"====generate_paragraph_evaluate====")
|
1138 |
print(content)
|
1139 |
|
|
|
1167 |
return total_content_text, content_table
|
1168 |
|
1169 |
|
1170 |
+
def get_chinese_paragraph_1st_evaluate_content(thread_id, model, sys_content, paragraph, user_generate_paragraph_evaluate_prompt):
|
1171 |
verify_string_length(paragraph)
|
1172 |
verify_moderation(paragraph)
|
1173 |
|
|
|
1178 |
---
|
1179 |
{user_generate_paragraph_evaluate_prompt}
|
1180 |
"""
|
1181 |
+
total_content_text, content_table = get_chinese_paragraph_evaluate_content(thread_id, model, user_content)
|
1182 |
|
1183 |
return total_content_text, content_table
|
1184 |
|
1185 |
+
def get_chinese_paragraph_refine_evaluate_content(thread_id, model, sys_content, paragraph_2, user_refine_paragraph_prompt):
|
|
|
1186 |
verify_string_length(paragraph_2)
|
1187 |
+
verify_moderation(paragraph_2)
|
1188 |
|
1189 |
user_content = f"""
|
1190 |
sys_content: {sys_content}
|
1191 |
---
|
|
|
|
|
1192 |
refined paragraph is: {paragraph_2}
|
1193 |
---
|
1194 |
{user_refine_paragraph_prompt}
|
1195 |
"""
|
1196 |
+
total_content_text, content_table = get_chinese_paragraph_evaluate_content(thread_id, model, user_content)
|
1197 |
|
1198 |
return total_content_text, content_table
|
1199 |
|
|
|
1211 |
print(f"instructions: {assistant.instructions}")
|
1212 |
|
1213 |
try:
|
1214 |
+
thread_id = get_chinese_conversation_thread_id(thread_id) if not thread_id else thread_id
|
1215 |
+
thread = client.beta.threads.retrieve(thread_id)
|
|
|
|
|
|
|
|
|
1216 |
print(f"Thread ID: {thread.id}")
|
1217 |
|
1218 |
# if metadata:
|
|
|
2923 |
js=english_logs_tab_button_js
|
2924 |
)
|
2925 |
|
2926 |
+
# 中文寫作練習
|
2927 |
with gr.Row(visible=False) as chinese_group:
|
2928 |
with gr.Column():
|
2929 |
with gr.Row() as page_title_chinese:
|
2930 |
gr.Markdown("# 🍄 CUTOR 國文段落寫作練習")
|
2931 |
|
2932 |
+
with gr.Row(visible=True) as chinese_admin:
|
2933 |
+
chinese_thread_id_state = gr.State()
|
2934 |
+
|
2935 |
with gr.Row(visible=False) as chinese_assignment_row:
|
2936 |
with gr.Column():
|
2937 |
with gr.Row():
|
|
|
3030 |
with gr.Row():
|
3031 |
chinese_full_paragraph_evaluate_output_table = gr.Dataframe(label="段落全文分析表格", wrap=True, column_widths=[20, 15, 65], interactive=False)
|
3032 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
3033 |
# 修改文章
|
3034 |
with gr.Row():
|
3035 |
gr.Markdown("# 根據建議修改文章")
|
3036 |
with gr.Row(visible=False) as chinese_full_paragraph_refine_params:
|
3037 |
default_user_generate_chinese_full_paragraph_refine_evaluate_prompt = """
|
3038 |
# 請嚴格根據 instructions
|
3039 |
+
# Rules:
|
3040 |
+
1. 我給你兩篇文章,請進行比較跟批改,並給出建議,如果文章完全一樣,請給出回饋:「這兩篇文章內容完全一樣,無法進行評分。」,後續不用進行評分。給予 level X
|
3041 |
+
2. 先檢查是否是合理的作文或是段落,再進行評分
|
3042 |
2. 請確保作文或段落的內容完整,並且符合中文語法
|
3043 |
3. 如果是一篇亂打的文章請直接給予回饋:「這篇文章內容不完整,無法進行評分。」
|
3044 |
4. 如果無法進行評分 評分標準與回饋的內容跟等級,則為 X
|
3045 |
+
5. 針對修改後的���分標準與回饋根據「A+、A、A- 、B+、 B、 B-」等級來評分,最低為 B-
|
3046 |
+
|
3047 |
+
# Restrictions:
|
3048 |
+
1. 不用給整體評分
|
3049 |
+
2. 不用改標點符號
|
3050 |
+
3. 評分標準的分數等級請使用「A+、A、A- 、B+、 B、 B-」等級,不可使用數字或是其他等級,像是「90分、80分、C、D」等等。
|
3051 |
+
4. 回傳的 output json 不需要有原文的評分,只需要有修改後的評分
|
3052 |
+
|
3053 |
+
# Output format:
|
3054 |
+
1. 先給 綜合回饋、評分標準與回饋、修改範例
|
3055 |
2. 再將評分標準與回饋的內容以JSON格式輸出,並且請使用繁體中文(ZH-TW)來評分段落並輸出,用 ```json ..... ``` 包裹:
|
3056 |
3. please use Chinese language (ZH-TW) to evaluate the paragraph and output use JSON format:
|
3057 |
+
4. if the score is X, please still follow the format and give the key as level and value as 'X'. then give the explanation in Chinese
|
3058 |
|
3059 |
EXAMPLE:
|
|
|
|
|
|
|
3060 |
# 綜合回饋(前後比較)
|
3061 |
你的文章...............(寫出一段話,比較兩篇作文的差異)
|
3062 |
|
|
|
3175 |
)
|
3176 |
|
3177 |
chinese_full_paragraph_evaluate_button.click(
|
3178 |
+
fn=get_chinese_conversation_thread_id,
|
3179 |
+
inputs=[chinese_thread_id_state],
|
3180 |
+
outputs=[chinese_thread_id_state]
|
3181 |
+
).then(
|
3182 |
fn=get_chinese_paragraph_1st_evaluate_content,
|
3183 |
+
inputs=[chinese_thread_id_state, model, chinese_full_paragraph_sys_content_input, chinese_full_paragraph_input, user_generate_chinese_full_paragraph_evaluate_prompt],
|
3184 |
outputs=[chinese_full_paragraph_evaluate_output_text, chinese_full_paragraph_evaluate_output_table]
|
3185 |
).then(
|
3186 |
fn=duplicate_element,
|
|
|
3189 |
)
|
3190 |
|
3191 |
generate_chinese_full_paragraph_refine_button.click(
|
3192 |
+
fn=get_chinese_conversation_thread_id,
|
3193 |
+
inputs=[chinese_thread_id_state],
|
3194 |
+
outputs=[chinese_thread_id_state]
|
3195 |
+
).then(
|
3196 |
fn=get_chinese_paragraph_refine_evaluate_content,
|
3197 |
+
inputs=[chinese_thread_id_state, model, chinese_full_paragraph_sys_content_input, chinese_full_paragraph_refine_input, user_generate_chinese_full_paragraph_refine_evaluate_prompt],
|
3198 |
outputs=[chinese_full_paragraph_refine_output_text, chinese_full_paragraph_refine_output_table]
|
3199 |
)
|
3200 |
|
|
|
3226 |
gr.Markdown("<span style='color:#4e80ee'>作業說明</span>")
|
3227 |
chinese_assignment_description_history_log = gr.Markdown()
|
3228 |
|
3229 |
+
gr.Markdown("---")
|
3230 |
+
gr.Markdown("# 回傳作業內容")
|
3231 |
|
3232 |
with gr.Row():
|
3233 |
with gr.Column():
|