youngtsai commited on
Commit
ce413ef
·
1 Parent(s): 18b603c

fn=get_chinese_paragraph_practice_log_session_content,

Browse files
Files changed (1) hide show
  1. app.py +74 -16
app.py CHANGED
@@ -982,7 +982,8 @@ def generate_chinese_paragraph_practice_history(
982
  "chinese_full_paragraph_refine_input": chinese_full_paragraph_refine_input,
983
  "chinese_full_paragraph_refine_output_text": chinese_full_paragraph_refine_output_text,
984
  "chinese_full_paragraph_refine_output_table": chinese_full_paragraph_refine_output_table.to_dict(orient='records'),
985
- "chinese_full_paragraph_save_output": chinese_full_paragraph_save_output
 
986
  }
987
  GCS_SERVICE.upload_json_string("jutor_logs", file_name, json.dumps(content))
988
 
@@ -1002,6 +1003,14 @@ def generate_chinese_paragraph_practice_history(
1002
  chinese_full_paragraph_refine_output_table, \
1003
  chinese_full_paragraph_save_output
1004
 
 
 
 
 
 
 
 
 
1005
  def get_chinese_paragraph_practice_log_session_content(file_name):
1006
  if file_name:
1007
  content = GCS_SERVICE.download_as_string("jutor_logs", file_name)
@@ -1014,6 +1023,22 @@ def get_chinese_paragraph_practice_log_session_content(file_name):
1014
  chinese_full_paragraph_refine_output_text_history = content_json["chinese_full_paragraph_refine_output_text"]
1015
  chinese_full_paragraph_refine_output_table_history = pd.DataFrame(content_json["chinese_full_paragraph_refine_output_table"])
1016
  chinese_full_paragraph_save_output_history = content_json["chinese_full_paragraph_save_output"]
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1017
  else:
1018
  chinese_full_paragraph_input_history = ""
1019
  chinese_full_paragraph_evaluate_output_text_history = ""
@@ -1023,13 +1048,24 @@ def get_chinese_paragraph_practice_log_session_content(file_name):
1023
  chinese_full_paragraph_refine_output_table_history = pd.DataFrame()
1024
  chinese_full_paragraph_save_output_history = ""
1025
 
 
 
 
 
 
 
1026
  return chinese_full_paragraph_input_history, \
1027
  chinese_full_paragraph_evaluate_output_text_history, \
1028
  chinese_full_paragraph_evaluate_output_table_history, \
1029
  chinese_full_paragraph_refine_input_history, \
1030
  chinese_full_paragraph_refine_output_text_history, \
1031
  chinese_full_paragraph_refine_output_table_history, \
1032
- chinese_full_paragraph_save_output_history
 
 
 
 
 
1033
 
1034
 
1035
  # === OpenAI Assistant ===
@@ -3167,7 +3203,6 @@ with gr.Blocks(theme=THEME, css=CSS) as demo:
3167
  # === 歷程 session 列表
3168
  with gr.Tab("歷程回顧"):
3169
  with gr.Accordion("📚 中文段落練習歷程回顧", open=False) as chinese_grapragh_practice_logs_accordion:
3170
- # 變數名稱就是加上 logs
3171
  with gr.Row():
3172
  with gr.Column(scale=1):
3173
  # 取得中文段落練習 log from GCS
@@ -3175,20 +3210,37 @@ with gr.Blocks(theme=THEME, css=CSS) as demo:
3175
  get_chinese_paragraph_practice_logs_button = gr.Button("👉 取得中文段落寫作練習歷程", variant="primary")
3176
  chinese_paragraph_practice_logs_session_list = gr.Radio(label="歷程時間列表")
3177
  with gr.Column(scale=3, variant="compact"):
3178
- gr.Markdown("<span style='color:#4e80ee'>輸入段落全文</span>")
3179
- chinese_full_paragraph_input_history_log = gr.Markdown()
3180
- gr.Markdown("<span style='color:#4e80ee'>段落全文分析</span>")
3181
- chinese_full_paragraph_evaluate_output_text_history_log = gr.Markdown()
3182
- chinese_full_paragraph_evaluate_output_table_history_log = gr.Dataframe(wrap=True, column_widths=[35, 15, 50], interactive=False)
 
 
 
 
 
 
3183
 
3184
- gr.Markdown("<span style='color:#4e80ee'>段落改善建議 輸入</span>")
3185
- chinese_full_paragraph_refine_input_history_log = gr.Markdown()
3186
- gr.Markdown("<span style='color:#4e80ee'>段落改善建議</span>")
3187
- chinese_full_paragraph_refine_output_text_history_log = gr.Markdown()
3188
- chinese_full_paragraph_refine_output_table_history_log = gr.Dataframe(wrap=True, interactive=False, column_widths=[30, 30, 40])
3189
 
3190
- gr.Markdown("<span style='color:#4e80ee'>修改結果</span>")
3191
- chinese_full_paragraph_save_output_history_log = gr.Markdown()
 
 
 
 
 
 
 
 
 
 
 
 
 
 
3192
 
3193
  get_chinese_paragraph_practice_logs_button.click(
3194
  fn=get_logs_sessions,
@@ -3206,7 +3258,13 @@ with gr.Blocks(theme=THEME, css=CSS) as demo:
3206
  chinese_full_paragraph_refine_input_history_log,
3207
  chinese_full_paragraph_refine_output_text_history_log,
3208
  chinese_full_paragraph_refine_output_table_history_log,
3209
- chinese_full_paragraph_save_output_history_log
 
 
 
 
 
 
3210
  ]
3211
  )
3212
 
 
982
  "chinese_full_paragraph_refine_input": chinese_full_paragraph_refine_input,
983
  "chinese_full_paragraph_refine_output_text": chinese_full_paragraph_refine_output_text,
984
  "chinese_full_paragraph_refine_output_table": chinese_full_paragraph_refine_output_table.to_dict(orient='records'),
985
+ "chinese_full_paragraph_save_output": chinese_full_paragraph_save_output,
986
+ "assignment_id": assignment_id_input
987
  }
988
  GCS_SERVICE.upload_json_string("jutor_logs", file_name, json.dumps(content))
989
 
 
1003
  chinese_full_paragraph_refine_output_table, \
1004
  chinese_full_paragraph_save_output
1005
 
1006
+ def get_assignment_content(assignment_id):
1007
+ assignments_file_name = "assignments.json"
1008
+ assignments_content = GCS_SERVICE.download_as_string("ai_assignment_submission", assignments_file_name)
1009
+ assignments_json = json.loads(assignments_content)
1010
+ assignment_json = assignments_json[assignment_id]
1011
+
1012
+ return assignment_json
1013
+
1014
  def get_chinese_paragraph_practice_log_session_content(file_name):
1015
  if file_name:
1016
  content = GCS_SERVICE.download_as_string("jutor_logs", file_name)
 
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:
1029
+ assignment = get_assignment_content(assignment_id)
1030
+ chinese_assignment_content = gr.update(visible=True)
1031
+ chinese_assignment_grade = assignment["grade"]
1032
+ chinese_assignment_topic = assignment["topic"]
1033
+ chinese_assignment_introduction = assignment["introduction"]
1034
+ chinese_assignment_description = assignment["description"]
1035
+ else:
1036
+ chinese_assignment_content = gr.update(visible=False)
1037
+ chinese_assignment_grade = ""
1038
+ chinese_assignment_topic = ""
1039
+ chinese_assignment_introduction = ""
1040
+ chinese_assignment_description = ""
1041
+
1042
  else:
1043
  chinese_full_paragraph_input_history = ""
1044
  chinese_full_paragraph_evaluate_output_text_history = ""
 
1048
  chinese_full_paragraph_refine_output_table_history = pd.DataFrame()
1049
  chinese_full_paragraph_save_output_history = ""
1050
 
1051
+ chinese_assignment_content = gr.update(visible=False)
1052
+ chinese_assignment_grade = ""
1053
+ chinese_assignment_topic = ""
1054
+ chinese_assignment_introduction = ""
1055
+ chinese_assignment_description = ""
1056
+
1057
  return chinese_full_paragraph_input_history, \
1058
  chinese_full_paragraph_evaluate_output_text_history, \
1059
  chinese_full_paragraph_evaluate_output_table_history, \
1060
  chinese_full_paragraph_refine_input_history, \
1061
  chinese_full_paragraph_refine_output_text_history, \
1062
  chinese_full_paragraph_refine_output_table_history, \
1063
+ chinese_full_paragraph_save_output_history, \
1064
+ chinese_assignment_content, \
1065
+ chinese_assignment_grade, \
1066
+ chinese_assignment_topic, \
1067
+ chinese_assignment_introduction, \
1068
+ chinese_assignment_description
1069
 
1070
 
1071
  # === OpenAI Assistant ===
 
3203
  # === 歷程 session 列表
3204
  with gr.Tab("歷程回顧"):
3205
  with gr.Accordion("📚 中文段落練習歷程回顧", open=False) as chinese_grapragh_practice_logs_accordion:
 
3206
  with gr.Row():
3207
  with gr.Column(scale=1):
3208
  # 取得中文段落練習 log from GCS
 
3210
  get_chinese_paragraph_practice_logs_button = gr.Button("👉 取得中文段落寫作練習歷程", variant="primary")
3211
  chinese_paragraph_practice_logs_session_list = gr.Radio(label="歷程時間列表")
3212
  with gr.Column(scale=3, variant="compact"):
3213
+ with gr.Row(visible=False) as chinese_assignment_content:
3214
+ with gr.Column():
3215
+ gr.Markdown("# 作業模式")
3216
+ gr.Markdown("<span style='color:#4e80ee'>年級</span>")
3217
+ chinese_assignment_grade_history_log = gr.Markdown()
3218
+ gr.Markdown("<span style='color:#4e80ee'>主題</span>")
3219
+ chinese_assignment_topic_history_log = gr.Markdown()
3220
+ gr.Markdown("<span style='color:#4e80ee'>寫作引文</span>")
3221
+ chinese_assignment_introduction_history_log = gr.Markdown()
3222
+ gr.Markdown("<span style='color:#4e80ee'>作業說明</span>")
3223
+ chinese_assignment_description_history_log = gr.Markdown()
3224
 
3225
+ gr.Markdown("---")
3226
+ gr.Markdown("# 回傳作業內容")
 
 
 
3227
 
3228
+ with gr.Row():
3229
+ with gr.Column():
3230
+ gr.Markdown("<span style='color:#4e80ee'>輸入段落全文</span>")
3231
+ chinese_full_paragraph_input_history_log = gr.Markdown()
3232
+ gr.Markdown("<span style='color:#4e80ee'>段落全文分析</span>")
3233
+ chinese_full_paragraph_evaluate_output_text_history_log = gr.Markdown()
3234
+ chinese_full_paragraph_evaluate_output_table_history_log = gr.Dataframe(wrap=True, column_widths=[35, 15, 50], interactive=False)
3235
+
3236
+ gr.Markdown("<span style='color:#4e80ee'>段落改善建議 輸入</span>")
3237
+ chinese_full_paragraph_refine_input_history_log = gr.Markdown()
3238
+ gr.Markdown("<span style='color:#4e80ee'>段落改善建議</span>")
3239
+ chinese_full_paragraph_refine_output_text_history_log = gr.Markdown()
3240
+ chinese_full_paragraph_refine_output_table_history_log = gr.Dataframe(wrap=True, interactive=False, column_widths=[30, 30, 40])
3241
+
3242
+ gr.Markdown("<span style='color:#4e80ee'>修改結果</span>")
3243
+ chinese_full_paragraph_save_output_history_log = gr.Markdown()
3244
 
3245
  get_chinese_paragraph_practice_logs_button.click(
3246
  fn=get_logs_sessions,
 
3258
  chinese_full_paragraph_refine_input_history_log,
3259
  chinese_full_paragraph_refine_output_text_history_log,
3260
  chinese_full_paragraph_refine_output_table_history_log,
3261
+ chinese_full_paragraph_save_output_history_log,
3262
+
3263
+ chinese_assignment_content,
3264
+ chinese_assignment_grade_history_log,
3265
+ chinese_assignment_topic_history_log,
3266
+ chinese_assignment_introduction_history_log,
3267
+ chinese_assignment_description_history_log
3268
  ]
3269
  )
3270