youngtsai commited on
Commit
ea53a26
·
1 Parent(s): 3f9a8c8

def get_full_paragraph_evaluate_log_session_content(file_name):

Browse files
Files changed (1) hide show
  1. app.py +190 -10
app.py CHANGED
@@ -520,6 +520,7 @@ def generate_refine_paragraph(model, sys_content, eng_level, paragraph, user_ref
520
  def update_paragraph_refine_input(text):
521
  return text
522
 
 
523
  def generate_paragraph_history(
524
  user_data,
525
  session_timestamp,
@@ -675,6 +676,87 @@ def get_paragraph_practice_log_session_content(file_name):
675
  paragraph_log_refine_output_history, \
676
  paragraph_log_paragraph_save_output
677
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
678
 
679
  # === Chinese ===
680
  def generate_chinese_evaluation_table(model, sys_content, user_prompt, text):
@@ -1868,6 +1950,33 @@ with gr.Blocks(theme=gr.themes.Soft(primary_hue=gr.themes.colors.blue, secondary
1868
  full_paragraph_save_output = gr.Textbox(label="最後結果")
1869
  full_audio_output = gr.Audio(label="音檔", type="filepath")
1870
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1871
  full_paragraph_evaluate_button.click(
1872
  fn=generate_paragraph_evaluate,
1873
  inputs=[model, sys_content_input, full_paragraph_input, user_generate_full_paragraph_evaluate_prompt],
@@ -1914,6 +2023,38 @@ with gr.Blocks(theme=gr.themes.Soft(primary_hue=gr.themes.colors.blue, secondary
1914
  outputs=[full_paragraph_save_output, full_audio_output]
1915
  )
1916
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1917
  # ====="英文考古題寫作練習====="
1918
  with gr.Row(visible=False, elem_id="english_exam_practice_row") as english_exam_practice_row:
1919
 
@@ -2089,17 +2230,56 @@ with gr.Blocks(theme=gr.themes.Soft(primary_hue=gr.themes.colors.blue, secondary
2089
  paragraph_log_paragraph_save_output
2090
  ]
2091
  )
2092
- # with gr.Row():
2093
- # with gr.Accordion("英文段落寫作評分歷程回顧", open=False) as english_grapragh_evaluate_logs_accordion:
2094
- # with gr.Row():
2095
- # with gr.Column(scale=1):
2096
- # # 取得英文段落練習 log from GCS
2097
- # paragraph_evaluate_logs_type = gr.State("jutor_evaluate_paragraph")
2098
- # get_paragraph_evaluate_logs_button = gr.Button("取得英文段落寫作評分歷程")
2099
- # paragraph_evaluate_logs_session_list = gr.Radio(label="歷程時間列表")
2100
- # with gr.Column(scale=3, variant="compact"):
2101
- # gr.Markdown("<span style='color:#4e80ee'>輸入</span>")
 
 
 
 
 
 
 
 
 
 
 
 
 
2102
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2103
 
2104
  english_grapragh_practice_button.click(
2105
  None,
 
520
  def update_paragraph_refine_input(text):
521
  return text
522
 
523
+ # 段落練習歷史紀錄
524
  def generate_paragraph_history(
525
  user_data,
526
  session_timestamp,
 
676
  paragraph_log_refine_output_history, \
677
  paragraph_log_paragraph_save_output
678
 
679
+ # 全文批改歷史紀錄
680
+ def generate_paragraph_evaluate_history(
681
+ user_data,
682
+ session_timestamp,
683
+ request_origin,
684
+ full_paragraph_input,
685
+ full_paragraph_evaluate_output,
686
+ full_paragraph_correct_grammatical_spelling_errors_input,
687
+ full_paragraph_correct_grammatical_spelling_errors_output_table,
688
+ full_paragraph_refine_input,
689
+ full_paragraph_refine_output_table,
690
+ full_paragraph_refine_output,
691
+ full_paragraph_save_output
692
+ ):
693
+
694
+ print("====生成全文批改歷史紀錄====")
695
+ print(f"user_data: {user_data}")
696
+ print(f"session_timestamp: {session_timestamp}")
697
+ print(f"request_origin: {request_origin}")
698
+
699
+ if user_data:
700
+ encoded_user_id_url = urllib.parse.quote(user_data, safe='')
701
+ log_type_name = "jutor_write_full_paragraph_evaluation"
702
+ file_name = f"{encoded_user_id_url}/{log_type_name}/{session_timestamp}.json"
703
+ content = {
704
+ "session_timestamp": session_timestamp,
705
+ "request_origin": request_origin,
706
+ "full_paragraph_input": full_paragraph_input,
707
+ "full_paragraph_evaluate_output": full_paragraph_evaluate_output.to_dict(orient='records'),
708
+ "full_paragraph_correct_grammatical_spelling_errors_input": full_paragraph_correct_grammatical_spelling_errors_input,
709
+ "full_paragraph_correct_grammatical_spelling_errors_output_table": full_paragraph_correct_grammatical_spelling_errors_output_table.to_dict(orient='records'),
710
+ "full_paragraph_refine_input": full_paragraph_refine_input,
711
+ "full_paragraph_refine_output_table": full_paragraph_refine_output_table.to_dict(orient='records'),
712
+ "full_paragraph_refine_output": full_paragraph_refine_output,
713
+ "full_paragraph_save_output": full_paragraph_save_output
714
+ }
715
+ print(file_name)
716
+ print(content)
717
+ GCS_SERVICE.upload_json_string("jutor_logs", file_name, json.dumps(content))
718
+
719
+ return full_paragraph_input, \
720
+ full_paragraph_evaluate_output, \
721
+ full_paragraph_correct_grammatical_spelling_errors_input, \
722
+ full_paragraph_correct_grammatical_spelling_errors_output_table, \
723
+ full_paragraph_refine_input, \
724
+ full_paragraph_refine_output_table, \
725
+ full_paragraph_refine_output, \
726
+ full_paragraph_save_output
727
+
728
+ def get_full_paragraph_evaluate_log_session_content(file_name):
729
+ if file_name:
730
+ content = GCS_SERVICE.download_as_string("jutor_logs", file_name)
731
+ print(f"content: {content}")
732
+ content_json = json.loads(content)
733
+ full_paragraph_input = content_json["full_paragraph_input"]
734
+ full_paragraph_evaluate_output = pd.DataFrame(content_json["full_paragraph_evaluate_output"])
735
+ full_paragraph_correct_grammatical_spelling_errors_input = content_json["full_paragraph_correct_grammatical_spelling_errors_input"]
736
+ full_paragraph_correct_grammatical_spelling_errors_output_table = pd.DataFrame(content_json["full_paragraph_correct_grammatical_spelling_errors_output_table"])
737
+ full_paragraph_refine_input = content_json["full_paragraph_refine_input"]
738
+ full_paragraph_refine_output_table = pd.DataFrame(content_json["full_paragraph_refine_output_table"])
739
+ full_paragraph_refine_output = content_json["full_paragraph_refine_output"]
740
+ full_paragraph_save_output = content_json["full_paragraph_save_output"]
741
+ else:
742
+ full_paragraph_input = ""
743
+ full_paragraph_evaluate_output = pd.DataFrame()
744
+ full_paragraph_correct_grammatical_spelling_errors_input = ""
745
+ full_paragraph_correct_grammatical_spelling_errors_output_table = pd.DataFrame()
746
+ full_paragraph_refine_input = ""
747
+ full_paragraph_refine_output_table = pd.DataFrame()
748
+ full_paragraph_refine_output = ""
749
+ full_paragraph_save_output = ""
750
+
751
+ return full_paragraph_input, \
752
+ full_paragraph_evaluate_output, \
753
+ full_paragraph_correct_grammatical_spelling_errors_input, \
754
+ full_paragraph_correct_grammatical_spelling_errors_output_table, \
755
+ full_paragraph_refine_input, \
756
+ full_paragraph_refine_output_table, \
757
+ full_paragraph_refine_output, \
758
+ full_paragraph_save_output
759
+
760
 
761
  # === Chinese ===
762
  def generate_chinese_evaluation_table(model, sys_content, user_prompt, text):
 
1950
  full_paragraph_save_output = gr.Textbox(label="最後結果")
1951
  full_audio_output = gr.Audio(label="音檔", type="filepath")
1952
 
1953
+ # 建立歷程回顧
1954
+ with gr.Row():
1955
+ gr.Markdown("# 歷程回顧")
1956
+ with gr.Row():
1957
+ full_paragraph_history_save_button = gr.Button("建立歷程回顧", variant="primary")
1958
+ with gr.Row():
1959
+ with gr.Accordion("歷程回顧", open=False) as full_paragraph_history_accordion:
1960
+ gr.Markdown("<span style='color:#4e80ee'>輸入段落全文</span>")
1961
+ full_paragraph_input_history = gr.Markdown()
1962
+ gr.Markdown("<span style='color:#4e80ee'>段落全文分析</span>")
1963
+ full_paragraph_evaluate_output_history = gr.Dataframe( wrap=True, column_widths=[35, 15, 50], interactive=False)
1964
+
1965
+ gr.Markdown("<span style='color:#4e80ee'>修訂文法與拼字錯誤 輸入</span>")
1966
+ full_paragraph_correct_grammatical_spelling_errors_input_history = gr.Markdown()
1967
+ gr.Markdown("<span style='color:#4e80ee'>修訂文法與拼字錯誤</span>")
1968
+ full_paragraph_correct_grammatical_spelling_errors_output_table_history = gr.Dataframe(interactive=False, wrap=True, column_widths=[30, 30, 40])
1969
+
1970
+ gr.Markdown("<span style='color:#4e80ee'>段落改善建議 輸入</span>")
1971
+ full_paragraph_refine_input_history = gr.Markdown()
1972
+ gr.Markdown("<span style='color:#4e80ee'>段落改善建議</span>")
1973
+ full_paragraph_refine_output_table_history = gr.Dataframe(wrap=True, interactive=False, column_widths=[30, 30, 40])
1974
+
1975
+ gr.Markdown("<span style='color:#4e80ee'>修改建議</span>")
1976
+ full_paragraph_refine_output_history = gr.Markdown()
1977
+ gr.Markdown("<span style='color:#4e80ee'>修改結果</span>")
1978
+ full_paragraph_save_output_history = gr.Markdown()
1979
+
1980
  full_paragraph_evaluate_button.click(
1981
  fn=generate_paragraph_evaluate,
1982
  inputs=[model, sys_content_input, full_paragraph_input, user_generate_full_paragraph_evaluate_prompt],
 
2023
  outputs=[full_paragraph_save_output, full_audio_output]
2024
  )
2025
 
2026
+ full_paragraph_history_save_button.click(
2027
+ fn=generate_paragraph_evaluate_history,
2028
+ inputs=[
2029
+ user_data,
2030
+ session_timestamp,
2031
+ request_origin,
2032
+ full_paragraph_input,
2033
+ full_paragraph_evaluate_output,
2034
+ full_paragraph_correct_grammatical_spelling_errors_input,
2035
+ full_paragraph_correct_grammatical_spelling_errors_output_table,
2036
+ full_paragraph_refine_input,
2037
+ full_paragraph_refine_output_table,
2038
+ full_paragraph_refine_output,
2039
+ full_paragraph_save_output
2040
+ ],
2041
+ outputs=[
2042
+ full_paragraph_input_history,
2043
+ full_paragraph_evaluate_output_history,
2044
+ full_paragraph_correct_grammatical_spelling_errors_input_history,
2045
+ full_paragraph_correct_grammatical_spelling_errors_output_table_history,
2046
+ full_paragraph_refine_input_history,
2047
+ full_paragraph_refine_output_table_history,
2048
+ full_paragraph_refine_output_history,
2049
+ full_paragraph_save_output_history,
2050
+ ]
2051
+ ).then(
2052
+ fn=update_history_accordion,
2053
+ inputs=[],
2054
+ outputs=full_paragraph_history_accordion
2055
+ )
2056
+
2057
+
2058
  # ====="英文考古題寫作練習====="
2059
  with gr.Row(visible=False, elem_id="english_exam_practice_row") as english_exam_practice_row:
2060
 
 
2230
  paragraph_log_paragraph_save_output
2231
  ]
2232
  )
2233
+ with gr.Row():
2234
+ with gr.Accordion("英文段落寫作評分歷程回顧", open=False) as english_grapragh_evaluate_logs_accordion:
2235
+ with gr.Row():
2236
+ with gr.Column(scale=1):
2237
+ # 取得英文段落練習 log from GCS
2238
+ full_paragraph_evaluate_logs_type = gr.State("jutor_write_full_paragraph_evaluation")
2239
+ get_full_paragraph_evaluate_logs_button = gr.Button("取得英文段落寫作評分歷程")
2240
+ full_paragraph_evaluate_logs_session_list = gr.Radio(label="歷程時間列表")
2241
+ with gr.Column(scale=3, variant="compact"):
2242
+ gr.Markdown("<span style='color:#4e80ee'>輸入段落全文</span>")
2243
+ log_full_paragraph_input_history = gr.Markdown()
2244
+ gr.Markdown("<span style='color:#4e80ee'>段落全文分析</span>")
2245
+ log_full_paragraph_evaluate_output_history = gr.Dataframe( wrap=True, column_widths=[35, 15, 50], interactive=False)
2246
+
2247
+ gr.Markdown("<span style='color:#4e80ee'>修訂文法與拼字錯誤 輸入</span>")
2248
+ log_full_paragraph_correct_grammatical_spelling_errors_input_history = gr.Markdown()
2249
+ gr.Markdown("<span style='color:#4e80ee'>修訂文法與拼字錯誤</span>")
2250
+ log_full_paragraph_correct_grammatical_spelling_errors_output_table_history = gr.Dataframe(interactive=False, wrap=True, column_widths=[30, 30, 40])
2251
+
2252
+ gr.Markdown("<span style='color:#4e80ee'>段落改善建議 輸入</span>")
2253
+ log_full_paragraph_refine_input_history = gr.Markdown()
2254
+ gr.Markdown("<span style='color:#4e80ee'>段落改善建議</span>")
2255
+ log_full_paragraph_refine_output_table_history = gr.Dataframe(wrap=True, interactive=False, column_widths=[30, 30, 40])
2256
 
2257
+ gr.Markdown("<span style='color:#4e80ee'>修改建議</span>")
2258
+ log_full_paragraph_refine_output_history = gr.Markdown()
2259
+ gr.Markdown("<span style='color:#4e80ee'>修改結果</span>")
2260
+ log_full_paragraph_save_output_history = gr.Markdown()
2261
+
2262
+ get_full_paragraph_evaluate_logs_button.click(
2263
+ fn=get_logs_sessions,
2264
+ inputs=[user_data, full_paragraph_evaluate_logs_type],
2265
+ outputs=[full_paragraph_evaluate_logs_session_list]
2266
+ )
2267
+
2268
+ full_paragraph_evaluate_logs_session_list.select(
2269
+ fn=get_full_paragraph_evaluate_log_session_content,
2270
+ inputs=[full_paragraph_evaluate_logs_session_list],
2271
+ outputs=[
2272
+ log_full_paragraph_input_history,
2273
+ log_full_paragraph_evaluate_output_history,
2274
+ log_full_paragraph_correct_grammatical_spelling_errors_input_history,
2275
+ log_full_paragraph_correct_grammatical_spelling_errors_output_table_history,
2276
+ log_full_paragraph_refine_input_history,
2277
+ log_full_paragraph_refine_output_table_history,
2278
+ log_full_paragraph_refine_output_history,
2279
+ log_full_paragraph_save_output_history
2280
+ ]
2281
+ )
2282
+
2283
 
2284
  english_grapragh_practice_button.click(
2285
  None,