Spaces:
Sleeping
Sleeping
GCS_SERVICE.upload_json_string("ai_assignment_submission", assignments_file_name, json.dumps(assignments_json))
Browse files
app.py
CHANGED
@@ -960,6 +960,7 @@ def generate_chinese_paragraph_practice_history(
|
|
960 |
user_data,
|
961 |
session_timestamp,
|
962 |
request_origin,
|
|
|
963 |
chinese_full_paragraph_input,
|
964 |
chinese_full_paragraph_evaluate_output_text,
|
965 |
chinese_full_paragraph_evaluate_output_table,
|
@@ -985,6 +986,14 @@ def generate_chinese_paragraph_practice_history(
|
|
985 |
}
|
986 |
GCS_SERVICE.upload_json_string("jutor_logs", file_name, json.dumps(content))
|
987 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
988 |
return chinese_full_paragraph_input, \
|
989 |
chinese_full_paragraph_evaluate_output_text, \
|
990 |
chinese_full_paragraph_evaluate_output_table, \
|
@@ -1262,14 +1271,36 @@ def init_params(request: gr.Request):
|
|
1262 |
english_group = gr.update(visible=False)
|
1263 |
chinese_group = gr.update(visible=True)
|
1264 |
|
1265 |
-
|
|
|
1266 |
if "assignment" in query_params:
|
1267 |
-
|
1268 |
-
|
1269 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1270 |
|
1271 |
|
1272 |
-
return admin_group, session_timestamp, request_origin,
|
|
|
|
|
|
|
1273 |
|
1274 |
CSS = """
|
1275 |
.accordion-prompts {
|
@@ -1349,6 +1380,7 @@ with gr.Blocks(theme=THEME, css=CSS) as demo:
|
|
1349 |
session_timestamp = gr.Textbox(label="Session Timestamp", value="", elem_id="jutor_session_timestamp_input")
|
1350 |
request_origin = gr.Textbox(label="Request Domain", value="")
|
1351 |
assignment_id_input = gr.Textbox(label="Assignment ID", value="", elem_id="jutor_assignment_id_input")
|
|
|
1352 |
|
1353 |
with gr.Row(visible=False) as english_group:
|
1354 |
with gr.Column():
|
@@ -2825,6 +2857,20 @@ with gr.Blocks(theme=THEME, css=CSS) as demo:
|
|
2825 |
with gr.Column():
|
2826 |
with gr.Row() as page_title_chinese:
|
2827 |
gr.Markdown("# 🔮 JUTOR 國文段落寫作練習")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2828 |
|
2829 |
# =====中文作文工具=====
|
2830 |
with gr.Tab("中文作文工具") as chinese_idea_tab:
|
@@ -3072,6 +3118,7 @@ with gr.Blocks(theme=THEME, css=CSS) as demo:
|
|
3072 |
user_data,
|
3073 |
session_timestamp,
|
3074 |
request_origin,
|
|
|
3075 |
chinese_full_paragraph_input,
|
3076 |
chinese_full_paragraph_evaluate_output_text,
|
3077 |
chinese_full_paragraph_evaluate_output_table,
|
@@ -3174,6 +3221,12 @@ with gr.Blocks(theme=THEME, css=CSS) as demo:
|
|
3174 |
session_timestamp,
|
3175 |
request_origin,
|
3176 |
assignment_id_input,
|
|
|
|
|
|
|
|
|
|
|
|
|
3177 |
english_group,
|
3178 |
chinese_group
|
3179 |
]
|
|
|
960 |
user_data,
|
961 |
session_timestamp,
|
962 |
request_origin,
|
963 |
+
assignment_id_input,
|
964 |
chinese_full_paragraph_input,
|
965 |
chinese_full_paragraph_evaluate_output_text,
|
966 |
chinese_full_paragraph_evaluate_output_table,
|
|
|
986 |
}
|
987 |
GCS_SERVICE.upload_json_string("jutor_logs", file_name, json.dumps(content))
|
988 |
|
989 |
+
if assignment_id_input:
|
990 |
+
# GCS "ai_assignment_submission", "assignments.json") 底下有一個 submission_ids 的 list,將 file_name 加入 list
|
991 |
+
assignments_file_name = "assignments.json"
|
992 |
+
assignments_content = GCS_SERVICE.download_as_string("ai_assignment_submission", assignments_file_name)
|
993 |
+
assignments_json = json.loads(assignments_content)
|
994 |
+
assignments_json[assignment_id_input]["submission_ids"].append(file_name)
|
995 |
+
GCS_SERVICE.upload_json_string("ai_assignment_submission", assignments_file_name, json.dumps(assignments_json))
|
996 |
+
|
997 |
return chinese_full_paragraph_input, \
|
998 |
chinese_full_paragraph_evaluate_output_text, \
|
999 |
chinese_full_paragraph_evaluate_output_table, \
|
|
|
1271 |
english_group = gr.update(visible=False)
|
1272 |
chinese_group = gr.update(visible=True)
|
1273 |
|
1274 |
+
assignment_id_value = None
|
1275 |
+
assignment_json_value = None
|
1276 |
if "assignment" in query_params:
|
1277 |
+
assignment_id_value = query_params["assignment"]
|
1278 |
+
assignments_json_text = GCS_SERVICE.download_as_string("ai_assignment_submission", "assignments.json")
|
1279 |
+
assignments_json = json.loads(assignments_json_text)
|
1280 |
+
assignment_json_value = assignments_json.get(assignment_id_value, None)
|
1281 |
+
|
1282 |
+
if assignment_json_value != None and assignment_json_value["assignment_type"] == "中文寫作 AI 批改":
|
1283 |
+
chinese_assignment_row = gr.update(visible=True)
|
1284 |
+
chinese_assignment_grade = gr.update(value=assignment_json_value["grade"])
|
1285 |
+
chinese_assignment_topic = gr.update(value=assignment_json_value["topic"])
|
1286 |
+
chinese_assignment_introduction = gr.update(value=assignment_json_value["introduction"])
|
1287 |
+
chinese_assignment_description = gr.update(value=assignment_json_value["description"])
|
1288 |
+
else:
|
1289 |
+
chinese_assignment_row = gr.update(visible=False)
|
1290 |
+
chinese_assignment_grade = gr.update(value="")
|
1291 |
+
chinese_assignment_topic = gr.update(value="")
|
1292 |
+
chinese_assignment_introduction = gr.update(value="")
|
1293 |
+
chinese_assignment_description = gr.update(value="")
|
1294 |
+
|
1295 |
+
|
1296 |
+
assignment_id_input = gr.update(value=assignment_id_value)
|
1297 |
+
assignment_json = gr.update(value=assignment_json_value)
|
1298 |
|
1299 |
|
1300 |
+
return admin_group, session_timestamp, request_origin, \
|
1301 |
+
assignment_id_input, assignment_json, \
|
1302 |
+
chinese_assignment_row, chinese_assignment_grade, chinese_assignment_topic, chinese_assignment_introduction, chinese_assignment_description, \
|
1303 |
+
english_group, chinese_group
|
1304 |
|
1305 |
CSS = """
|
1306 |
.accordion-prompts {
|
|
|
1380 |
session_timestamp = gr.Textbox(label="Session Timestamp", value="", elem_id="jutor_session_timestamp_input")
|
1381 |
request_origin = gr.Textbox(label="Request Domain", value="")
|
1382 |
assignment_id_input = gr.Textbox(label="Assignment ID", value="", elem_id="jutor_assignment_id_input")
|
1383 |
+
assignment_json = gr.JSON(label="Assignment JSON", elem_id="jutor_assignment_json_input")
|
1384 |
|
1385 |
with gr.Row(visible=False) as english_group:
|
1386 |
with gr.Column():
|
|
|
2857 |
with gr.Column():
|
2858 |
with gr.Row() as page_title_chinese:
|
2859 |
gr.Markdown("# 🔮 JUTOR 國文段落寫作練習")
|
2860 |
+
|
2861 |
+
with gr.Row(visible=False) as chinese_assignment_row:
|
2862 |
+
with gr.Column():
|
2863 |
+
with gr.Row():
|
2864 |
+
gr.Markdown("# 作業模式")
|
2865 |
+
with gr.Row():
|
2866 |
+
chinese_assignment_grade = gr.Textbox(label="年級", interactive=False)
|
2867 |
+
with gr.Row():
|
2868 |
+
chinese_assignment_topic = gr.Textbox(label="主題", interactive=False)
|
2869 |
+
with gr.Row():
|
2870 |
+
chinese_assignment_introduction = gr.Textbox(label="寫作引文", interactive=False)
|
2871 |
+
with gr.Row():
|
2872 |
+
chinese_assignment_description = gr.Textbox(label="作業說明", interactive=False)
|
2873 |
+
|
2874 |
|
2875 |
# =====中文作文工具=====
|
2876 |
with gr.Tab("中文作文工具") as chinese_idea_tab:
|
|
|
3118 |
user_data,
|
3119 |
session_timestamp,
|
3120 |
request_origin,
|
3121 |
+
assignment_id_input,
|
3122 |
chinese_full_paragraph_input,
|
3123 |
chinese_full_paragraph_evaluate_output_text,
|
3124 |
chinese_full_paragraph_evaluate_output_table,
|
|
|
3221 |
session_timestamp,
|
3222 |
request_origin,
|
3223 |
assignment_id_input,
|
3224 |
+
assignment_json,
|
3225 |
+
chinese_assignment_row,
|
3226 |
+
chinese_assignment_grade,
|
3227 |
+
chinese_assignment_topic,
|
3228 |
+
chinese_assignment_introduction,
|
3229 |
+
chinese_assignment_description,
|
3230 |
english_group,
|
3231 |
chinese_group
|
3232 |
]
|