Spaces:
Sleeping
Sleeping
fn=get_past_exam_practice_log_session_content,
Browse files
app.py
CHANGED
@@ -758,6 +758,92 @@ def get_full_paragraph_evaluate_log_session_content(file_name):
|
|
758 |
full_paragraph_save_output
|
759 |
|
760 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
761 |
# === Chinese ===
|
762 |
def generate_chinese_evaluation_table(model, sys_content, user_prompt, text):
|
763 |
# 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
|
@@ -2138,7 +2224,88 @@ with gr.Blocks(theme=gr.themes.Soft(primary_hue=gr.themes.colors.blue, secondary
|
|
2138 |
gr.Markdown("## 修改結果")
|
2139 |
with gr.Row():
|
2140 |
past_exam_refine_output_diff = gr.HTML()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2141 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2142 |
past_exam_evaluation_button.click(
|
2143 |
fn=generate_paragraph_evaluate,
|
2144 |
inputs=[model, past_exam_evaluation_sys_content_prompt, past_exam_evaluation_input, past_exam_evaluation_user_prompt],
|
@@ -2279,8 +2446,56 @@ with gr.Blocks(theme=gr.themes.Soft(primary_hue=gr.themes.colors.blue, secondary
|
|
2279 |
log_full_paragraph_save_output_history
|
2280 |
]
|
2281 |
)
|
2282 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2283 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2284 |
english_grapragh_practice_button.click(
|
2285 |
None,
|
2286 |
None,
|
|
|
758 |
full_paragraph_save_output
|
759 |
|
760 |
|
761 |
+
# # 考古題練習歷史紀錄
|
762 |
+
def generate_past_exam_history(
|
763 |
+
user_data,
|
764 |
+
session_timestamp,
|
765 |
+
request_origin,
|
766 |
+
past_exam_title,
|
767 |
+
past_exam_evaluation_input,
|
768 |
+
past_exam_evaluation_output,
|
769 |
+
past_exam_correct_grammatical_spelling_errors_input,
|
770 |
+
past_exam_correct_grammatical_spelling_errors_output_table,
|
771 |
+
past_exam_refine_input,
|
772 |
+
past_exam_refine_output_table,
|
773 |
+
past_exam_refine_output,
|
774 |
+
past_exam_save_output
|
775 |
+
):
|
776 |
+
print("====生成考古題練習歷史紀錄====")
|
777 |
+
print(f"user_data: {user_data}")
|
778 |
+
print(f"session_timestamp: {session_timestamp}")
|
779 |
+
print(f"request_origin: {request_origin}")
|
780 |
+
|
781 |
+
if user_data:
|
782 |
+
encoded_user_id_url = urllib.parse.quote(user_data, safe='')
|
783 |
+
log_type_name = "jutor_write_past_exam"
|
784 |
+
file_name = f"{encoded_user_id_url}/{log_type_name}/{session_timestamp}.json"
|
785 |
+
content = {
|
786 |
+
"session_timestamp": session_timestamp,
|
787 |
+
"request_origin": request_origin,
|
788 |
+
"past_exam_title": past_exam_title,
|
789 |
+
"past_exam_evaluation_input": past_exam_evaluation_input,
|
790 |
+
"past_exam_evaluation_output": past_exam_evaluation_output.to_dict(orient='records'),
|
791 |
+
"past_exam_correct_grammatical_spelling_errors_input": past_exam_correct_grammatical_spelling_errors_input,
|
792 |
+
"past_exam_correct_grammatical_spelling_errors_output_table": past_exam_correct_grammatical_spelling_errors_output_table.to_dict(orient='records'),
|
793 |
+
"past_exam_refine_input": past_exam_refine_input,
|
794 |
+
"past_exam_refine_output_table": past_exam_refine_output_table.to_dict(orient='records'),
|
795 |
+
"past_exam_refine_output": past_exam_refine_output,
|
796 |
+
"past_exam_save_output": past_exam_save_output
|
797 |
+
}
|
798 |
+
print(file_name)
|
799 |
+
print(content)
|
800 |
+
GCS_SERVICE.upload_json_string("jutor_logs", file_name, json.dumps(content))
|
801 |
+
|
802 |
+
return past_exam_title, \
|
803 |
+
past_exam_evaluation_input, \
|
804 |
+
past_exam_evaluation_output, \
|
805 |
+
past_exam_correct_grammatical_spelling_errors_input, \
|
806 |
+
past_exam_correct_grammatical_spelling_errors_output_table, \
|
807 |
+
past_exam_refine_input, \
|
808 |
+
past_exam_refine_output_table, \
|
809 |
+
past_exam_refine_output, \
|
810 |
+
past_exam_save_output
|
811 |
+
|
812 |
+
def get_past_exam_practice_log_session_content(file_name):
|
813 |
+
if file_name:
|
814 |
+
content = GCS_SERVICE.download_as_string("jutor_logs", file_name)
|
815 |
+
print(f"content: {content}")
|
816 |
+
content_json = json.loads(content)
|
817 |
+
past_exam_title = content_json["past_exam_title"]
|
818 |
+
past_exam_evaluation_input = content_json["past_exam_evaluation_input"]
|
819 |
+
past_exam_evaluation_output = pd.DataFrame(content_json["past_exam_evaluation_output"])
|
820 |
+
past_exam_correct_grammatical_spelling_errors_input = content_json["past_exam_correct_grammatical_spelling_errors_input"]
|
821 |
+
past_exam_correct_grammatical_spelling_errors_output_table = pd.DataFrame(content_json["past_exam_correct_grammatical_spelling_errors_output_table"])
|
822 |
+
past_exam_refine_input = content_json["past_exam_refine_input"]
|
823 |
+
past_exam_refine_output_table = pd.DataFrame(content_json["past_exam_refine_output_table"])
|
824 |
+
past_exam_refine_output = content_json["past_exam_refine_output"]
|
825 |
+
past_exam_save_output = content_json["past_exam_save_output"]
|
826 |
+
else:
|
827 |
+
past_exam_title = ""
|
828 |
+
past_exam_evaluation_input = ""
|
829 |
+
past_exam_evaluation_output = pd.DataFrame()
|
830 |
+
past_exam_correct_grammatical_spelling_errors_input = ""
|
831 |
+
past_exam_correct_grammatical_spelling_errors_output_table = pd.DataFrame()
|
832 |
+
past_exam_refine_input = ""
|
833 |
+
past_exam_refine_output_table = pd.DataFrame()
|
834 |
+
past_exam_refine_output = ""
|
835 |
+
past_exam_save_output = ""
|
836 |
+
|
837 |
+
return past_exam_title, \
|
838 |
+
past_exam_evaluation_input, \
|
839 |
+
past_exam_evaluation_output, \
|
840 |
+
past_exam_correct_grammatical_spelling_errors_input, \
|
841 |
+
past_exam_correct_grammatical_spelling_errors_output_table, \
|
842 |
+
past_exam_refine_input, \
|
843 |
+
past_exam_refine_output_table, \
|
844 |
+
past_exam_refine_output, \
|
845 |
+
past_exam_save_output
|
846 |
+
|
847 |
# === Chinese ===
|
848 |
def generate_chinese_evaluation_table(model, sys_content, user_prompt, text):
|
849 |
# 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
|
|
|
2224 |
gr.Markdown("## 修改結果")
|
2225 |
with gr.Row():
|
2226 |
past_exam_refine_output_diff = gr.HTML()
|
2227 |
+
|
2228 |
+
# 最後成果
|
2229 |
+
with gr.Row():
|
2230 |
+
gr.Markdown("# 寫作完成")
|
2231 |
+
with gr.Row():
|
2232 |
+
past_exam_save_button = gr.Button("輸出結果", variant="primary")
|
2233 |
+
with gr.Row():
|
2234 |
+
with gr.Column():
|
2235 |
+
past_exam_save_output = gr.Textbox(label="最後結果")
|
2236 |
+
with gr.Column():
|
2237 |
+
past_exam_audio_output = gr.Audio(label="音檔", type="filepath")
|
2238 |
|
2239 |
+
past_exam_save_button.click(
|
2240 |
+
fn=paragraph_save_and_tts,
|
2241 |
+
inputs=[past_exam_refine_input],
|
2242 |
+
outputs=[past_exam_save_output, past_exam_audio_output]
|
2243 |
+
)
|
2244 |
+
|
2245 |
+
# 建立歷程回顧
|
2246 |
+
with gr.Row():
|
2247 |
+
gr.Markdown("# 建立歷程回顧")
|
2248 |
+
with gr.Row():
|
2249 |
+
past_exam_history_save_button = gr.Button("建立歷程回顧", variant="primary")
|
2250 |
+
with gr.Row():
|
2251 |
+
with gr.Accordion("歷程回顧", open=False) as past_exam_history_accordion:
|
2252 |
+
gr.Markdown("<span style='color:#4e80ee'>考古題</span>")
|
2253 |
+
past_exam_dropdown_history = gr.Markdown()
|
2254 |
+
|
2255 |
+
gr.Markdown("<span style='color:#4e80ee'>段落全文</span>")
|
2256 |
+
past_exam_input_history = gr.Markdown()
|
2257 |
+
gr.Markdown("<span style='color:#4e80ee'>段落全文分析</span>")
|
2258 |
+
past_exam_evaluate_output_history = gr.Dataframe(wrap=True, column_widths=[35, 15, 50], interactive=False)
|
2259 |
+
|
2260 |
+
gr.Markdown("<span style='color:#4e80ee'>文法與拼字錯誤</span>")
|
2261 |
+
past_exam_correct_grammatical_spelling_errors_input_history = gr.Markdown()
|
2262 |
+
gr.Markdown("<span style='color:#4e80ee'>修訂文法與拼字錯誤</span>")
|
2263 |
+
past_exam_correct_grammatical_spelling_errors_output_table_history = gr.Dataframe(interactive=False, wrap=True, column_widths=[30, 30, 40])
|
2264 |
+
|
2265 |
+
gr.Markdown("<span style='color:#4e80ee'>段落改善</span>")
|
2266 |
+
past_exam_refine_input_history = gr.Markdown()
|
2267 |
+
gr.Markdown("<span style='color:#4e80ee'>段落改善建議</span>")
|
2268 |
+
past_exam_refine_output_table_history = gr.Dataframe(wrap=True, interactive=False, column_widths=[30, 30, 40])
|
2269 |
+
|
2270 |
+
gr.Markdown("<span style='color:#4e80ee'>修改建議</span>")
|
2271 |
+
past_exam_refine_output_history = gr.Markdown()
|
2272 |
+
gr.Markdown("<span style='color:#4e80ee'>修改結果</span>")
|
2273 |
+
past_exam_save_output_history = gr.Markdown()
|
2274 |
+
|
2275 |
+
|
2276 |
+
past_exam_history_save_button.click(
|
2277 |
+
fn=generate_past_exam_history,
|
2278 |
+
inputs=[
|
2279 |
+
user_data,
|
2280 |
+
session_timestamp,
|
2281 |
+
request_origin,
|
2282 |
+
past_exam_dropdown,
|
2283 |
+
past_exam_evaluation_input,
|
2284 |
+
past_exam_evaluation_output,
|
2285 |
+
past_exam_correct_grammatical_spelling_errors_input,
|
2286 |
+
past_exam_correct_grammatical_spelling_errors_output_table,
|
2287 |
+
past_exam_refine_input,
|
2288 |
+
past_exam_refine_output_table,
|
2289 |
+
past_exam_refine_output,
|
2290 |
+
past_exam_save_output
|
2291 |
+
],
|
2292 |
+
outputs=[
|
2293 |
+
past_exam_dropdown_history,
|
2294 |
+
past_exam_input_history,
|
2295 |
+
past_exam_evaluate_output_history,
|
2296 |
+
past_exam_correct_grammatical_spelling_errors_input_history,
|
2297 |
+
past_exam_correct_grammatical_spelling_errors_output_table_history,
|
2298 |
+
past_exam_refine_input_history,
|
2299 |
+
past_exam_refine_output_table_history,
|
2300 |
+
past_exam_refine_output_history,
|
2301 |
+
past_exam_save_output_history
|
2302 |
+
]
|
2303 |
+
).then(
|
2304 |
+
fn=update_history_accordion,
|
2305 |
+
inputs=[],
|
2306 |
+
outputs=past_exam_history_accordion
|
2307 |
+
)
|
2308 |
+
|
2309 |
past_exam_evaluation_button.click(
|
2310 |
fn=generate_paragraph_evaluate,
|
2311 |
inputs=[model, past_exam_evaluation_sys_content_prompt, past_exam_evaluation_input, past_exam_evaluation_user_prompt],
|
|
|
2446 |
log_full_paragraph_save_output_history
|
2447 |
]
|
2448 |
)
|
2449 |
+
with gr.Row():
|
2450 |
+
with gr.Accordion("英文考古題寫作練習歷程回顧", open=False) as english_exam_practice_logs_accordion:
|
2451 |
+
with gr.Row():
|
2452 |
+
with gr.Column(scale=1):
|
2453 |
+
# 取得英文段落練習 log from GCS
|
2454 |
+
past_exam_logs_type = gr.State("jutor_write_past_exam")
|
2455 |
+
get_past_exam_logs_button = gr.Button("取得英文考古題寫作練習歷程")
|
2456 |
+
past_exam_logs_session_list = gr.Radio(label="歷程時間列表")
|
2457 |
+
with gr.Column(scale=3, variant="compact"):
|
2458 |
+
gr.Markdown("<span style='color:#4e80ee'>考古題</span>")
|
2459 |
+
past_exam_log_dropdown_history = gr.Markdown()
|
2460 |
+
gr.Markdown("<span style='color:#4e80ee'>段落全文</span>")
|
2461 |
+
past_exam_log_input_history = gr.Markdown()
|
2462 |
+
gr.Markdown("<span style='color:#4e80ee'>段落全文分析</span>")
|
2463 |
+
past_exam_log_evaluate_output_history = gr.Dataframe(wrap=True, column_widths=[35, 15, 50], interactive=False)
|
2464 |
+
|
2465 |
+
gr.Markdown("<span style='color:#4e80ee'>文法與拼字錯誤</span>")
|
2466 |
+
past_exam_log_correct_grammatical_spelling_errors_input_history = gr.Markdown()
|
2467 |
+
gr.Markdown("<span style='color:#4e80ee'>修訂文法與拼字錯誤</span>")
|
2468 |
+
past_exam_log_correct_grammatical_spelling_errors_output_table_history = gr.Dataframe(interactive=False, wrap=True, column_widths=[30, 30, 40])
|
2469 |
+
|
2470 |
+
gr.Markdown("<span style='color:#4e80ee'>段落改善</span>")
|
2471 |
+
past_exam_log_refine_input_history = gr.Markdown()
|
2472 |
+
gr.Markdown("<span style='color:#4e80ee'>段落改善建議</span>")
|
2473 |
+
past_exam_log_refine_output_table_history = gr.Dataframe(wrap=True, interactive=False, column_widths=[30, 30, 40])
|
2474 |
+
|
2475 |
+
gr.Markdown("<span style='color:#4e80ee'>最後結果</span>")
|
2476 |
+
past_exam_log_save_output_history = gr.Markdown()
|
2477 |
|
2478 |
+
get_past_exam_logs_button.click(
|
2479 |
+
fn=get_logs_sessions,
|
2480 |
+
inputs=[user_data, past_exam_logs_type],
|
2481 |
+
outputs=[past_exam_logs_session_list]
|
2482 |
+
)
|
2483 |
+
|
2484 |
+
past_exam_logs_session_list.select(
|
2485 |
+
fn=get_past_exam_practice_log_session_content,
|
2486 |
+
inputs=[past_exam_logs_session_list],
|
2487 |
+
outputs=[
|
2488 |
+
past_exam_log_dropdown_history,
|
2489 |
+
past_exam_log_input_history,
|
2490 |
+
past_exam_log_evaluate_output_history,
|
2491 |
+
past_exam_log_correct_grammatical_spelling_errors_input_history,
|
2492 |
+
past_exam_log_correct_grammatical_spelling_errors_output_table_history,
|
2493 |
+
past_exam_log_refine_input_history,
|
2494 |
+
past_exam_log_refine_output_table_history,
|
2495 |
+
past_exam_log_save_output_history
|
2496 |
+
]
|
2497 |
+
)
|
2498 |
+
|
2499 |
english_grapragh_practice_button.click(
|
2500 |
None,
|
2501 |
None,
|