Spaces:
Sleeping
Sleeping
full_paragraph_input = gr.Textbox(label="輸入段落全文")
Browse files
app.py
CHANGED
@@ -422,8 +422,51 @@ def update_history_accordion():
|
|
422 |
history_accordion_gr_update = gr.update(open=True)
|
423 |
return history_accordion_gr_update
|
424 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
425 |
with gr.Blocks(theme=gr.themes.Soft(primary_hue=gr.themes.colors.blue, secondary_hue=gr.themes.colors.orange)) as demo:
|
426 |
-
with gr.Tab(label="
|
427 |
# basic inputs 主題與情境
|
428 |
with gr.Row():
|
429 |
with gr.Column():
|
@@ -1149,7 +1192,7 @@ with gr.Blocks(theme=gr.themes.Soft(primary_hue=gr.themes.colors.blue, secondary
|
|
1149 |
outputs=history_accordion
|
1150 |
)
|
1151 |
|
1152 |
-
with gr.Tab("
|
1153 |
with gr.Row(visible=False) as full_paragraph_params:
|
1154 |
full_paragraph_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.")
|
1155 |
default_user_generate_full_paragraph_evaluate_prompt = default_user_generate_paragraph_evaluate_prompt
|
@@ -1159,17 +1202,19 @@ with gr.Blocks(theme=gr.themes.Soft(primary_hue=gr.themes.colors.blue, secondary
|
|
1159 |
with gr.Row():
|
1160 |
gr.Markdown("# 輸入段落全文")
|
1161 |
with gr.Row():
|
1162 |
-
|
1163 |
-
|
1164 |
-
|
1165 |
-
|
1166 |
-
|
|
|
|
|
1167 |
|
1168 |
-
|
1169 |
-
|
1170 |
-
|
1171 |
-
|
1172 |
-
|
1173 |
|
1174 |
# JUTOR 段落批改與整體建議
|
1175 |
with gr.Row():
|
@@ -1244,4 +1289,149 @@ with gr.Blocks(theme=gr.themes.Soft(primary_hue=gr.themes.colors.blue, secondary
|
|
1244 |
outputs=[full_paragraph_save_output, full_audio_output]
|
1245 |
)
|
1246 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1247 |
demo.launch()
|
|
|
422 |
history_accordion_gr_update = gr.update(open=True)
|
423 |
return history_accordion_gr_update
|
424 |
|
425 |
+
|
426 |
+
def generate_chinese_evaluation_table(sys_content, user_prompt, text):
|
427 |
+
# 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
|
428 |
+
|
429 |
+
user_content = f"""
|
430 |
+
本篇作文:{text}
|
431 |
+
---
|
432 |
+
{user_prompt}
|
433 |
+
"""
|
434 |
+
messages = [
|
435 |
+
{"role": "system", "content": sys_content},
|
436 |
+
{"role": "user", "content": user_content}
|
437 |
+
]
|
438 |
+
|
439 |
+
response_format = { "type": "json_object" }
|
440 |
+
|
441 |
+
request_payload = {
|
442 |
+
"model": "gpt-4-turbo",
|
443 |
+
"messages": messages,
|
444 |
+
"max_tokens": 2000,
|
445 |
+
"response_format": response_format
|
446 |
+
}
|
447 |
+
|
448 |
+
response = OPEN_AI_CLIENT.chat.completions.create(**request_payload)
|
449 |
+
content = response.choices[0].message.content
|
450 |
+
|
451 |
+
print(f"====generate_chinese_evaluation_table====")
|
452 |
+
print(content)
|
453 |
+
|
454 |
+
data = json.loads(content)["results"]
|
455 |
+
headers = ["架構", "評分", "解釋"]
|
456 |
+
table_data = [
|
457 |
+
["題旨發揮", data['題旨發揮']['level'], data['題旨發揮']['explanation']],
|
458 |
+
["資料掌握", data['資料掌握']['level'], data['資料掌握']['explanation']],
|
459 |
+
["結構安排", data['結構安排']['level'], data['結構安排']['explanation']],
|
460 |
+
["字句運用", data['字句運用']['level'], data['字句運用']['explanation']]
|
461 |
+
]
|
462 |
+
|
463 |
+
gr_update = gr.update(value=table_data, headers=headers)
|
464 |
+
|
465 |
+
return gr_update
|
466 |
+
|
467 |
+
|
468 |
with gr.Blocks(theme=gr.themes.Soft(primary_hue=gr.themes.colors.blue, secondary_hue=gr.themes.colors.orange)) as demo:
|
469 |
+
with gr.Tab(label="英文段落寫作練習"):
|
470 |
# basic inputs 主題與情境
|
471 |
with gr.Row():
|
472 |
with gr.Column():
|
|
|
1192 |
outputs=history_accordion
|
1193 |
)
|
1194 |
|
1195 |
+
with gr.Tab("英文全文批改"):
|
1196 |
with gr.Row(visible=False) as full_paragraph_params:
|
1197 |
full_paragraph_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.")
|
1198 |
default_user_generate_full_paragraph_evaluate_prompt = default_user_generate_paragraph_evaluate_prompt
|
|
|
1202 |
with gr.Row():
|
1203 |
gr.Markdown("# 輸入段落全文")
|
1204 |
with gr.Row():
|
1205 |
+
with gr.Column():
|
1206 |
+
full_paragraph_input = gr.Textbox(label="輸入段落全文")
|
1207 |
+
with gr.Column():
|
1208 |
+
with gr.Row():
|
1209 |
+
full_paragraph_evaluate_button = gr.Button("段落全文分析", variant="primary")
|
1210 |
+
with gr.Row():
|
1211 |
+
full_paragraph_evaluate_output = gr.Dataframe(label="段落全文分析", wrap=True, column_widths=[35, 15, 50], interactive=False)
|
1212 |
|
1213 |
+
full_paragraph_evaluate_button.click(
|
1214 |
+
fn=generate_paragraph_evaluate,
|
1215 |
+
inputs=[sys_content_input, full_paragraph_input, user_generate_full_paragraph_evaluate_prompt],
|
1216 |
+
outputs=full_paragraph_evaluate_output
|
1217 |
+
)
|
1218 |
|
1219 |
# JUTOR 段落批改與整體建議
|
1220 |
with gr.Row():
|
|
|
1289 |
outputs=[full_paragraph_save_output, full_audio_output]
|
1290 |
)
|
1291 |
|
1292 |
+
with gr.Tab("中文全文批改"):
|
1293 |
+
with gr.Row(visible=False) as chinese_full_paragraph_params:
|
1294 |
+
chinese_full_paragraph_sys_content_input = gr.Textbox(label="System Prompt", value="You are an Chinese teacher who is practicing with me to improve my Chinese writing skill.")
|
1295 |
+
default_user_generate_chinese_full_paragraph_evaluate_prompt = """
|
1296 |
+
你是一位國文老師,負責評分學生的作文。請根據以下的評分標準,對這篇作文進行詳細評價:
|
1297 |
+
請根據「國文作文評分標準」,對這篇作文進行詳細評價:
|
1298 |
+
|
1299 |
+
評分標準:
|
1300 |
+
題旨發揮 (40%):
|
1301 |
+
A 等 - 能掌握題幹要求,緊扣題旨發揮;內容充實,思路清晰;感發得宜,想像豐富;情感真摯,表達適當,體悟深刻;論述周延,富有創意。
|
1302 |
+
B 等 - 尚能掌握題幹要求,依照題旨發揮;內容平實,思路尚稱清晰;感發尚稱得宜,想像平淡;情感表達尚稱適當,體悟稍欠深刻;論述尚稱周延,略有創意。
|
1303 |
+
C 等 - 未能掌握題幹要求,題旨不明或偏離題旨;內容浮泛,思路不清;感發未能得宜,想像不足;情感表達不當,體悟膚淺或全無體悟;論述不周延,缺乏創意。
|
1304 |
+
|
1305 |
+
資料掌握 (20%):
|
1306 |
+
A 等 - 能融會貫通題幹資料;能深刻回應引導內容;能善用成語及典故;舉證詳實貼切;材料運用恰當。
|
1307 |
+
B 等 - 僅側重部分題幹資料;僅大致回應引導內容;尚能運用成語及典故;舉證平淡疏略;材料運用尚稱恰當。
|
1308 |
+
C 等 - 誤解題幹資料;大部分抄襲引導內容;錯誤運用成語及典故;舉證鬆散模糊;材料運用不當。
|
1309 |
+
|
1310 |
+
結構安排 (20%):
|
1311 |
+
A 等 - 結構嚴謹;前後通貫;脈絡清楚;條理分明;照應緊密。
|
1312 |
+
B 等 - 結構大致完整;前後尚能通貫;脈絡大致清楚;條理尚稱分明;略有照應。
|
1313 |
+
C 等 - 結構鬆散;前後矛盾;脈絡不清;條理紛雜;全無照應。
|
1314 |
+
|
1315 |
+
字句運用 (20%):
|
1316 |
+
A 等 - 字句妥切,邏輯清晰;用詞精確,造句工穩;描寫細膩,論述精彩;文筆流暢,修辭優美;標點符號使用正確。
|
1317 |
+
B 等 - 字句尚稱適當,邏輯尚稱清晰;用詞通順,造句平淡;描寫平淡,論述平實;文筆平順,修辭尚可;標點符號使用大致正確。
|
1318 |
+
C 等 - 字句欠當,邏輯不通;用詞粗率,造句冗贅;描寫粗陋,論述空洞;文筆蕪蔓,修辭粗俗;標點符號使用多有錯誤。
|
1319 |
+
|
1320 |
+
請根據這些標準,對這篇作文進行評級,並詳細解釋每個維度的得分理由。
|
1321 |
+
|
1322 |
+
等級可以細分為 A+、A、A-、B+、B、B-、C+、C、C- 九個等級。
|
1323 |
+
|
1324 |
+
please use Chinese language (ZH-TW) to evaluate the paragraph and output use JSON format:
|
1325 |
+
EXAMPLE:
|
1326 |
+
"results": {{
|
1327 |
+
"題旨發揮": {{
|
1328 |
+
"level": "A+",
|
1329 |
+
"explanation": "#中文解釋 ZH-TW"
|
1330 |
+
}},
|
1331 |
+
"資料掌握": {{
|
1332 |
+
"level": "B+",
|
1333 |
+
"explanation": "#中文解釋 ZH-TW"
|
1334 |
+
}},
|
1335 |
+
"結構安排": {{
|
1336 |
+
"level": "C",
|
1337 |
+
"explanation": "#中文解釋 ZH-TW"
|
1338 |
+
}},
|
1339 |
+
"字句運用": {{
|
1340 |
+
"level": "C-",
|
1341 |
+
"explanation": "#中文解釋 ZH-TW"
|
1342 |
+
}}
|
1343 |
+
}}
|
1344 |
+
|
1345 |
+
Restrictions:
|
1346 |
+
- ALL the content should be in Traditional Chinese (zh-TW), it's very important.
|
1347 |
+
"""
|
1348 |
+
user_generate_chinese_full_paragraph_evaluate_prompt = gr.Textbox(label="Paragraph evaluate Prompt", value=default_user_generate_chinese_full_paragraph_evaluate_prompt)
|
1349 |
+
with gr.Row():
|
1350 |
+
gr.Markdown("# 輸入段落全文")
|
1351 |
+
with gr.Row():
|
1352 |
+
with gr.Column():
|
1353 |
+
chinese_full_paragraph_input = gr.Textbox(label="輸入段落全文", lines=5)
|
1354 |
+
with gr.Column():
|
1355 |
+
with gr.Row():
|
1356 |
+
chinese_full_paragraph_evaluate_button = gr.Button("段落全文分析", variant="primary")
|
1357 |
+
with gr.Row():
|
1358 |
+
chinese_full_paragraph_evaluate_output = gr.Dataframe(label="段落全文分析", wrap=True, column_widths=[20, 15, 65], interactive=False)
|
1359 |
+
|
1360 |
+
chinese_full_paragraph_evaluate_button.click(
|
1361 |
+
fn=generate_chinese_evaluation_table,
|
1362 |
+
inputs=[chinese_full_paragraph_sys_content_input, user_generate_chinese_full_paragraph_evaluate_prompt, chinese_full_paragraph_input],
|
1363 |
+
outputs=chinese_full_paragraph_evaluate_output
|
1364 |
+
)
|
1365 |
+
|
1366 |
+
# JUTOR 段落批改與整體建議
|
1367 |
+
with gr.Row():
|
1368 |
+
gr.Markdown("# JUTOR 段落批改與整體建議")
|
1369 |
+
with gr.Row():
|
1370 |
+
gr.Markdown("## 修訂文法與拼字錯誤")
|
1371 |
+
with gr.Row():
|
1372 |
+
with gr.Column():
|
1373 |
+
chinese_full_paragraph_correct_grammatical_spelling_errors_input = gr.Textbox(label="這是你的原始寫作內容,參考 JUTOR 的建議,你可以選擇是否修改:")
|
1374 |
+
with gr.Column():
|
1375 |
+
generate_chinese_full_paragraph_correct_grammatical_spelling_errors_button = gr.Button("JUTOR 修訂", variant="primary")
|
1376 |
+
chinese_full_paragraph_correct_grammatical_spelling_errors_output_table = gr.Dataframe(label="修訂文法與拼字錯誤", interactive=False, column_widths=[30, 30, 40])
|
1377 |
+
revised_chinese_full_paragraph_output = gr.Textbox(label="Revised Paragraph", show_copy_button=True, visible=False)
|
1378 |
+
gr.Markdown("## 修訂結果")
|
1379 |
+
revised_chinese_full_paragraph_diff = gr.HTML()
|
1380 |
+
|
1381 |
+
generate_chinese_full_paragraph_correct_grammatical_spelling_errors_button.click(
|
1382 |
+
fn=generate_correct_grammatical_spelling_errors,
|
1383 |
+
inputs=[chinese_full_paragraph_sys_content_input, eng_level_input, chinese_full_paragraph_input, user_correct_grammatical_spelling_errors_prompt],
|
1384 |
+
outputs=[chinese_full_paragraph_correct_grammatical_spelling_errors_output_table, revised_chinese_full_paragraph_output]
|
1385 |
+
).then(
|
1386 |
+
fn=highlight_diff_texts,
|
1387 |
+
inputs=[chinese_full_paragraph_correct_grammatical_spelling_errors_output_table, revised_chinese_full_paragraph_output],
|
1388 |
+
outputs=revised_chinese_full_paragraph_diff
|
1389 |
+
).then(
|
1390 |
+
fn=update_paragraph_correct_grammatical_spelling_errors_input,
|
1391 |
+
inputs=[chinese_full_paragraph_input],
|
1392 |
+
outputs=chinese_full_paragraph_correct_grammatical_spelling_errors_input
|
1393 |
+
)
|
1394 |
+
|
1395 |
+
# JUTOR 段落批改與整體建議
|
1396 |
+
with gr.Row():
|
1397 |
+
gr.Markdown("## 段落改善建議")
|
1398 |
+
with gr.Row():
|
1399 |
+
with gr.Column():
|
1400 |
+
chinese_full_paragraph_refine_input = gr.Textbox(label="這是你的原始寫作內容,參考 JUTOR 的建議,你可以選擇是否修改:", show_copy_button=True)
|
1401 |
+
with gr.Column():
|
1402 |
+
generate_chinese_full_paragraph_refine_button = gr.Button("段落改善建議", variant="primary")
|
1403 |
+
chinese_full_paragraph_refine_output_table = gr.DataFrame(label="Refine Paragraph 段落改善建議", wrap=True, interactive=False)
|
1404 |
+
chinese_full_paragraph_refine_output = gr.HTML(label="修改建議", visible=False)
|
1405 |
+
gr.Markdown("## 修改結果")
|
1406 |
+
chinese_full_paragraph_refine_output_diff = gr.HTML()
|
1407 |
+
|
1408 |
+
generate_chinese_full_paragraph_refine_button.click(
|
1409 |
+
fn=generate_refine_paragraph,
|
1410 |
+
inputs=[chinese_full_paragraph_sys_content_input, eng_level_input, chinese_full_paragraph_correct_grammatical_spelling_errors_input, user_refine_paragraph_prompt],
|
1411 |
+
outputs=[chinese_full_paragraph_refine_output_table, chinese_full_paragraph_refine_output]
|
1412 |
+
).then(
|
1413 |
+
fn=highlight_diff_texts,
|
1414 |
+
inputs=[chinese_full_paragraph_refine_output_table, chinese_full_paragraph_refine_output],
|
1415 |
+
outputs=chinese_full_paragraph_refine_output_diff
|
1416 |
+
).then(
|
1417 |
+
fn=update_paragraph_refine_input,
|
1418 |
+
inputs=[chinese_full_paragraph_correct_grammatical_spelling_errors_input],
|
1419 |
+
outputs=chinese_full_paragraph_refine_input
|
1420 |
+
)
|
1421 |
+
|
1422 |
+
# 寫作完成
|
1423 |
+
with gr.Row():
|
1424 |
+
gr.Markdown("# 寫作完成")
|
1425 |
+
with gr.Row():
|
1426 |
+
chinese_full_paragraph_save_button = gr.Button("輸出結果", variant="primary")
|
1427 |
+
with gr.Row():
|
1428 |
+
chinese_full_paragraph_save_output = gr.Textbox(label="最後結果")
|
1429 |
+
chinese_full_audio_output = gr.Audio(label="音檔", type="filepath")
|
1430 |
+
|
1431 |
+
chinese_full_paragraph_save_button.click(
|
1432 |
+
fn=paragraph_save_and_tts,
|
1433 |
+
inputs=[chinese_full_paragraph_refine_input],
|
1434 |
+
outputs=[chinese_full_paragraph_save_output, chinese_full_audio_output]
|
1435 |
+
)
|
1436 |
+
|
1437 |
demo.launch()
|