Spaces:
Sleeping
Sleeping
html update
Browse files- assignment_ui.py +94 -85
assignment_ui.py
CHANGED
@@ -142,59 +142,72 @@ def create_assignment_ui(user_data, assignment_service, submission_service):
|
|
142 |
choices.append(choice)
|
143 |
return gr.update(choices=choices)
|
144 |
|
145 |
-
|
146 |
-
|
147 |
-
|
148 |
-
|
149 |
-
|
150 |
-
html = f"""
|
151 |
<div style="background-color: #f8f9fa; padding: 30px; border-radius: 15px; font-family: 'Helvetica', sans-serif;">
|
152 |
<h2 style="color: #007bff; font-size: 28px; margin-bottom: 20px;">📝 學生回傳作業</h2>
|
153 |
<div style="background-color: white; border-radius: 10px; padding: 20px; box-shadow: 0 2px 4px rgba(0,0,0,0.05);">
|
154 |
-
|
155 |
-
|
156 |
-
|
157 |
-
|
158 |
-
|
159 |
-
|
160 |
-
|
161 |
-
</div>
|
162 |
-
</div>
|
163 |
-
<div style="margin-bottom: 20px;">
|
164 |
-
<div style="font-weight: bold; color: #6c757d; margin-bottom: 5px;">🆔 學生ID</div>
|
165 |
-
<div style="background-color: #f8f9fa; padding: 10px 15px; border-radius: 5px;">
|
166 |
-
{submission_json.get('student_id', '未提供')}
|
167 |
-
</div>
|
168 |
-
</div>
|
169 |
-
<div style="margin-bottom: 20px;">
|
170 |
-
<div style="font-weight: bold; color: #6c757d; margin-bottom: 5px;">🕒 缴交时间</div>
|
171 |
-
<div style="background-color: #f8f9fa; padding: 10px 15px; border-radius: 5px;">{submission_json.get('timestamp', '未提供')}</div>
|
172 |
-
</div>
|
173 |
-
</div>
|
174 |
-
</details>
|
175 |
-
"""
|
176 |
|
177 |
if content_type == 'chinese_full_paragraph_evaluation':
|
178 |
-
|
179 |
elif content_type == 'english_full_paragraph_evaluation':
|
180 |
-
|
181 |
else:
|
182 |
-
|
183 |
-
|
184 |
-
|
|
|
185 |
</div>
|
186 |
</div>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
187 |
"""
|
188 |
-
return html
|
189 |
|
190 |
def generate_chinese_full_paragraph_html(content):
|
191 |
-
|
|
|
|
|
192 |
<details open>
|
193 |
<summary style="cursor: pointer; font-weight: bold; color: #28a745; padding: 10px; background-color: #e9ecef; border-radius: 5px; margin-top: 20px;">原文評估</summary>
|
194 |
<div style="margin-top: 10px;">
|
195 |
-
"""
|
196 |
|
197 |
-
|
198 |
<div style="margin-bottom: 20px;">
|
199 |
<div style="font-weight: bold; color: #28a745; margin-bottom: 5px;">📄 输入段落全文</div>
|
200 |
<div style="background-color: #f8f9fa; padding: 10px 15px; border-radius: 5px; white-space: pre-wrap;">{content.get('chinese_full_paragraph_input', '未提供')}</div>
|
@@ -204,21 +217,21 @@ def create_assignment_ui(user_data, assignment_service, submission_service):
|
|
204 |
<div style="font-weight: bold; color: #17a2b8; margin-bottom: 5px;">📊 段落全文分析</div>
|
205 |
<div style="background-color: #f8f9fa; padding: 10px 15px; border-radius: 5px; white-space: pre-wrap;">{content.get('chinese_full_paragraph_evaluate_output_text', '未提供')}</div>
|
206 |
</div>
|
207 |
-
"""
|
208 |
|
209 |
if 'chinese_full_paragraph_evaluate_output_table' in content:
|
210 |
-
|
211 |
|
212 |
-
|
213 |
</div>
|
214 |
</details>
|
215 |
|
216 |
<details>
|
217 |
<summary style="cursor: pointer; font-weight: bold; color: #6610f2; padding: 10px; background-color: #e9ecef; border-radius: 5px; margin-top: 20px;">第二次修改</summary>
|
218 |
<div style="margin-top: 10px;">
|
219 |
-
"""
|
220 |
|
221 |
-
|
222 |
<div style="margin-bottom: 20px;">
|
223 |
<div style="font-weight: bold; color: #6610f2; margin-bottom: 5px;">🔄 段落改善建议 输入</div>
|
224 |
<div style="background-color: #f8f9fa; padding: 10px 15px; border-radius: 5px; white-space: pre-wrap;">{content.get('chinese_full_paragraph_refine_input', '未提供')}</div>
|
@@ -228,69 +241,71 @@ def create_assignment_ui(user_data, assignment_service, submission_service):
|
|
228 |
<div style="font-weight: bold; color: #fd7e14; margin-bottom: 5px;">🔄 段落改善建议</div>
|
229 |
<div style="background-color: #f8f9fa; padding: 10px 15px; border-radius: 5px; white-space: pre-wrap;">{content.get('chinese_full_paragraph_refine_output_text', '未提供')}</div>
|
230 |
</div>
|
231 |
-
"""
|
232 |
|
233 |
if 'chinese_full_paragraph_refine_output_table' in content:
|
234 |
-
|
235 |
|
236 |
-
|
237 |
<div style="margin-bottom: 20px;">
|
238 |
<div style="font-weight: bold; color: #20c997; margin-bottom: 5px;">📝 修改结果</div>
|
239 |
<div style="background-color: #f8f9fa; padding: 10px 15px; border-radius: 5px; white-space: pre-wrap;">{content.get('chinese_full_paragraph_save_output', '未提供')}</div>
|
240 |
</div>
|
241 |
</div>
|
242 |
</details>
|
243 |
-
"""
|
244 |
|
245 |
-
return
|
246 |
|
247 |
def generate_english_full_paragraph_html(content):
|
248 |
-
|
|
|
|
|
249 |
<details open>
|
250 |
<summary style="cursor: pointer; font-weight: bold; color: #28a745; padding: 10px; background-color: #e9ecef; border-radius: 5px; margin-top: 20px;">原文</summary>
|
251 |
<div style="margin-top: 10px;">
|
252 |
-
"""
|
253 |
|
254 |
-
|
255 |
<div style="margin-bottom: 20px;">
|
256 |
<div style="font-weight: bold; color: #28a745; margin-bottom: 5px;">📄 輸入段落全文</div>
|
257 |
<div style="background-color: #f8f9fa; padding: 10px 15px; border-radius: 5px; white-space: pre-wrap;">{content.get('full_paragraph_input', '未提供')}</div>
|
258 |
</div>
|
259 |
-
"""
|
260 |
|
261 |
if 'full_paragraph_evaluate_output' in content:
|
262 |
-
|
263 |
|
264 |
-
|
265 |
</div>
|
266 |
</details>
|
267 |
|
268 |
<details>
|
269 |
<summary style="cursor: pointer; font-weight: bold; color: #6610f2; padding: 10px; background-color: #e9ecef; border-radius: 5px; margin-top: 20px;">修訂結果</summary>
|
270 |
<div style="margin-top: 10px;">
|
271 |
-
"""
|
272 |
|
273 |
-
|
274 |
<div style="margin-bottom: 20px;">
|
275 |
<div style="font-weight: bold; color: #6610f2; margin-bottom: 5px;">🔄 修訂文法與拼字錯誤 輸入</div>
|
276 |
<div style="background-color: #f8f9fa; padding: 10px 15px; border-radius: 5px; white-space: pre-wrap;">{content.get('full_paragraph_correct_grammatical_spelling_errors_input', '未提供')}</div>
|
277 |
</div>
|
278 |
-
"""
|
279 |
|
280 |
if 'full_paragraph_correct_grammatical_spelling_errors_output_table' in content:
|
281 |
-
|
282 |
|
283 |
-
|
284 |
<div style="margin-bottom: 20px;">
|
285 |
<div style="font-weight: bold; color: #6610f2; margin-bottom: 5px;">🔄 段落改善建議 輸入</div>
|
286 |
<div style="background-color: #f8f9fa; padding: 10px 15px; border-radius: 5px; white-space: pre-wrap;">{content.get('full_paragraph_refine_input', '未提供')}</div>
|
287 |
</div>
|
288 |
-
"""
|
289 |
|
290 |
if 'full_paragraph_refine_output_table' in content:
|
291 |
-
|
292 |
|
293 |
-
|
294 |
<div style="margin-bottom: 20px;">
|
295 |
<div style="font-weight: bold; color: #fd7e14; margin-bottom: 5px;">🔄 修改建議</div>
|
296 |
<div style="background-color: #f8f9fa; padding: 10px 15px; border-radius: 5px; white-space: pre-wrap;">{content.get('full_paragraph_refine_output', '未提供')}</div>
|
@@ -302,55 +317,49 @@ def create_assignment_ui(user_data, assignment_service, submission_service):
|
|
302 |
</div>
|
303 |
</div>
|
304 |
</details>
|
305 |
-
"""
|
306 |
|
307 |
-
return
|
308 |
|
309 |
def generate_table_html(table_data, title, color):
|
310 |
if not table_data or not isinstance(table_data, list):
|
311 |
return ""
|
312 |
|
313 |
-
|
|
|
|
|
314 |
<div style="margin-bottom: 20px;">
|
315 |
<div style="font-weight: bold; color: {color}; margin-bottom: 5px;">{title}</div>
|
316 |
<div style="background-color: #f8f9fa; padding: 10px 15px; border-radius: 5px; overflow-x: auto;">
|
317 |
<table style="width: 100%; border-collapse: collapse; white-space: nowrap;">
|
318 |
<tr style="background-color: #e9ecef;">
|
319 |
-
"""
|
320 |
|
321 |
-
#
|
322 |
headers = table_data[0].keys()
|
323 |
for header in headers:
|
324 |
if header.lower() == '評分' or header.lower() == 'score':
|
325 |
-
|
326 |
else:
|
327 |
-
|
328 |
-
|
329 |
|
330 |
-
#
|
331 |
for item in table_data:
|
332 |
-
|
333 |
for key, value in item.items():
|
334 |
if key.lower() == '評分' or key.lower() == 'score':
|
335 |
-
|
336 |
else:
|
337 |
-
|
338 |
-
|
339 |
|
340 |
-
|
341 |
</table>
|
342 |
</div>
|
343 |
</div>
|
344 |
-
"""
|
345 |
-
return
|
346 |
-
|
347 |
-
def update_submission_data_html(submission_json):
|
348 |
-
html = generate_submission_html(submission_json)
|
349 |
-
return gr.update(value=html)
|
350 |
-
|
351 |
-
def update_submission_data_html(submission_json):
|
352 |
-
html = generate_submission_html(submission_json)
|
353 |
-
return gr.update(value=html)
|
354 |
|
355 |
def update_submission_data_html(submission_json):
|
356 |
html = generate_submission_html(submission_json)
|
|
|
142 |
choices.append(choice)
|
143 |
return gr.update(choices=choices)
|
144 |
|
145 |
+
cdef generate_submission_html(submission_json):
|
146 |
+
html_parts = []
|
147 |
+
|
148 |
+
# 添加外层结构的开始标签
|
149 |
+
html_parts.append("""
|
|
|
150 |
<div style="background-color: #f8f9fa; padding: 30px; border-radius: 15px; font-family: 'Helvetica', sans-serif;">
|
151 |
<h2 style="color: #007bff; font-size: 28px; margin-bottom: 20px;">📝 學生回傳作業</h2>
|
152 |
<div style="background-color: white; border-radius: 10px; padding: 20px; box-shadow: 0 2px 4px rgba(0,0,0,0.05);">
|
153 |
+
""")
|
154 |
+
|
155 |
+
html_parts.append(generate_student_info_html(submission_json))
|
156 |
+
|
157 |
+
submission_data = submission_json.get('submission_data', {})
|
158 |
+
content = submission_data.get('content', {})
|
159 |
+
content_type = content.get('content_type', '')
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
160 |
|
161 |
if content_type == 'chinese_full_paragraph_evaluation':
|
162 |
+
html_parts.append(generate_chinese_full_paragraph_html(content))
|
163 |
elif content_type == 'english_full_paragraph_evaluation':
|
164 |
+
html_parts.append(generate_english_full_paragraph_html(content))
|
165 |
else:
|
166 |
+
html_parts.append("<p>不支持的内容类型</p>")
|
167 |
+
|
168 |
+
# 添加外层结构的结束标签
|
169 |
+
html_parts.append("""
|
170 |
</div>
|
171 |
</div>
|
172 |
+
""")
|
173 |
+
|
174 |
+
return ''.join(html_parts)
|
175 |
+
|
176 |
+
def generate_student_info_html(submission_json):
|
177 |
+
return f"""
|
178 |
+
<details>
|
179 |
+
<summary style="cursor: pointer; font-weight: bold; color: #6c757d; padding: 10px; background-color: #e9ecef; border-radius: 5px;">學生資訊</summary>
|
180 |
+
<div style="margin-top: 10px;">
|
181 |
+
<div style="margin-bottom: 20px;">
|
182 |
+
<div style="font-weight: bold; color: #6c757d; margin-bottom: 5px;">👤 學生姓名</div>
|
183 |
+
<div style="background-color: #f8f9fa; padding: 10px 15px; border-radius: 5px;">
|
184 |
+
{submission_json.get('student_name', '未提供')}
|
185 |
+
</div>
|
186 |
+
</div>
|
187 |
+
<div style="margin-bottom: 20px;">
|
188 |
+
<div style="font-weight: bold; color: #6c757d; margin-bottom: 5px;">🆔 學生ID</div>
|
189 |
+
<div style="background-color: #f8f9fa; padding: 10px 15px; border-radius: 5px;">
|
190 |
+
{submission_json.get('student_id', '未提供')}
|
191 |
+
</div>
|
192 |
+
</div>
|
193 |
+
<div style="margin-bottom: 20px;">
|
194 |
+
<div style="font-weight: bold; color: #6c757d; margin-bottom: 5px;">🕒 繳交時間</div>
|
195 |
+
<div style="background-color: #f8f9fa; padding: 10px 15px; border-radius: 5px;">{submission_json.get('timestamp', '未提供')}</div>
|
196 |
+
</div>
|
197 |
+
</div>
|
198 |
+
</details>
|
199 |
"""
|
|
|
200 |
|
201 |
def generate_chinese_full_paragraph_html(content):
|
202 |
+
html_parts = []
|
203 |
+
|
204 |
+
html_parts.append("""
|
205 |
<details open>
|
206 |
<summary style="cursor: pointer; font-weight: bold; color: #28a745; padding: 10px; background-color: #e9ecef; border-radius: 5px; margin-top: 20px;">原文評估</summary>
|
207 |
<div style="margin-top: 10px;">
|
208 |
+
""")
|
209 |
|
210 |
+
html_parts.append(f"""
|
211 |
<div style="margin-bottom: 20px;">
|
212 |
<div style="font-weight: bold; color: #28a745; margin-bottom: 5px;">📄 输入段落全文</div>
|
213 |
<div style="background-color: #f8f9fa; padding: 10px 15px; border-radius: 5px; white-space: pre-wrap;">{content.get('chinese_full_paragraph_input', '未提供')}</div>
|
|
|
217 |
<div style="font-weight: bold; color: #17a2b8; margin-bottom: 5px;">📊 段落全文分析</div>
|
218 |
<div style="background-color: #f8f9fa; padding: 10px 15px; border-radius: 5px; white-space: pre-wrap;">{content.get('chinese_full_paragraph_evaluate_output_text', '未提供')}</div>
|
219 |
</div>
|
220 |
+
""")
|
221 |
|
222 |
if 'chinese_full_paragraph_evaluate_output_table' in content:
|
223 |
+
html_parts.append(generate_table_html(content['chinese_full_paragraph_evaluate_output_table'], "📊 评分结果", "#dc3545"))
|
224 |
|
225 |
+
html_parts.append("""
|
226 |
</div>
|
227 |
</details>
|
228 |
|
229 |
<details>
|
230 |
<summary style="cursor: pointer; font-weight: bold; color: #6610f2; padding: 10px; background-color: #e9ecef; border-radius: 5px; margin-top: 20px;">第二次修改</summary>
|
231 |
<div style="margin-top: 10px;">
|
232 |
+
""")
|
233 |
|
234 |
+
html_parts.append(f"""
|
235 |
<div style="margin-bottom: 20px;">
|
236 |
<div style="font-weight: bold; color: #6610f2; margin-bottom: 5px;">🔄 段落改善建议 输入</div>
|
237 |
<div style="background-color: #f8f9fa; padding: 10px 15px; border-radius: 5px; white-space: pre-wrap;">{content.get('chinese_full_paragraph_refine_input', '未提供')}</div>
|
|
|
241 |
<div style="font-weight: bold; color: #fd7e14; margin-bottom: 5px;">🔄 段落改善建议</div>
|
242 |
<div style="background-color: #f8f9fa; padding: 10px 15px; border-radius: 5px; white-space: pre-wrap;">{content.get('chinese_full_paragraph_refine_output_text', '未提供')}</div>
|
243 |
</div>
|
244 |
+
""")
|
245 |
|
246 |
if 'chinese_full_paragraph_refine_output_table' in content:
|
247 |
+
html_parts.append(generate_table_html(content['chinese_full_paragraph_refine_output_table'], "📊 修改后评分", "#20c997"))
|
248 |
|
249 |
+
html_parts.append(f"""
|
250 |
<div style="margin-bottom: 20px;">
|
251 |
<div style="font-weight: bold; color: #20c997; margin-bottom: 5px;">📝 修改结果</div>
|
252 |
<div style="background-color: #f8f9fa; padding: 10px 15px; border-radius: 5px; white-space: pre-wrap;">{content.get('chinese_full_paragraph_save_output', '未提供')}</div>
|
253 |
</div>
|
254 |
</div>
|
255 |
</details>
|
256 |
+
""")
|
257 |
|
258 |
+
return ''.join(html_parts)
|
259 |
|
260 |
def generate_english_full_paragraph_html(content):
|
261 |
+
html_parts = []
|
262 |
+
|
263 |
+
html_parts.append("""
|
264 |
<details open>
|
265 |
<summary style="cursor: pointer; font-weight: bold; color: #28a745; padding: 10px; background-color: #e9ecef; border-radius: 5px; margin-top: 20px;">原文</summary>
|
266 |
<div style="margin-top: 10px;">
|
267 |
+
""")
|
268 |
|
269 |
+
html_parts.append(f"""
|
270 |
<div style="margin-bottom: 20px;">
|
271 |
<div style="font-weight: bold; color: #28a745; margin-bottom: 5px;">📄 輸入段落全文</div>
|
272 |
<div style="background-color: #f8f9fa; padding: 10px 15px; border-radius: 5px; white-space: pre-wrap;">{content.get('full_paragraph_input', '未提供')}</div>
|
273 |
</div>
|
274 |
+
""")
|
275 |
|
276 |
if 'full_paragraph_evaluate_output' in content:
|
277 |
+
html_parts.append(generate_table_html(content['full_paragraph_evaluate_output'], "📊 評分結果", "#dc3545"))
|
278 |
|
279 |
+
html_parts.append("""
|
280 |
</div>
|
281 |
</details>
|
282 |
|
283 |
<details>
|
284 |
<summary style="cursor: pointer; font-weight: bold; color: #6610f2; padding: 10px; background-color: #e9ecef; border-radius: 5px; margin-top: 20px;">修訂結果</summary>
|
285 |
<div style="margin-top: 10px;">
|
286 |
+
""")
|
287 |
|
288 |
+
html_parts.append(f"""
|
289 |
<div style="margin-bottom: 20px;">
|
290 |
<div style="font-weight: bold; color: #6610f2; margin-bottom: 5px;">🔄 修訂文法與拼字錯誤 輸入</div>
|
291 |
<div style="background-color: #f8f9fa; padding: 10px 15px; border-radius: 5px; white-space: pre-wrap;">{content.get('full_paragraph_correct_grammatical_spelling_errors_input', '未提供')}</div>
|
292 |
</div>
|
293 |
+
""")
|
294 |
|
295 |
if 'full_paragraph_correct_grammatical_spelling_errors_output_table' in content:
|
296 |
+
html_parts.append(generate_table_html(content['full_paragraph_correct_grammatical_spelling_errors_output_table'], "📊 修訂文法與拼字錯誤", "#20c997"))
|
297 |
|
298 |
+
html_parts.append(f"""
|
299 |
<div style="margin-bottom: 20px;">
|
300 |
<div style="font-weight: bold; color: #6610f2; margin-bottom: 5px;">🔄 段落改善建議 輸入</div>
|
301 |
<div style="background-color: #f8f9fa; padding: 10px 15px; border-radius: 5px; white-space: pre-wrap;">{content.get('full_paragraph_refine_input', '未提供')}</div>
|
302 |
</div>
|
303 |
+
""")
|
304 |
|
305 |
if 'full_paragraph_refine_output_table' in content:
|
306 |
+
html_parts.append(generate_table_html(content['full_paragraph_refine_output_table'], "📊 段落改善建議", "#20c997"))
|
307 |
|
308 |
+
html_parts.append(f"""
|
309 |
<div style="margin-bottom: 20px;">
|
310 |
<div style="font-weight: bold; color: #fd7e14; margin-bottom: 5px;">🔄 修改建議</div>
|
311 |
<div style="background-color: #f8f9fa; padding: 10px 15px; border-radius: 5px; white-space: pre-wrap;">{content.get('full_paragraph_refine_output', '未提供')}</div>
|
|
|
317 |
</div>
|
318 |
</div>
|
319 |
</details>
|
320 |
+
""")
|
321 |
|
322 |
+
return ''.join(html_parts)
|
323 |
|
324 |
def generate_table_html(table_data, title, color):
|
325 |
if not table_data or not isinstance(table_data, list):
|
326 |
return ""
|
327 |
|
328 |
+
html_parts = []
|
329 |
+
|
330 |
+
html_parts.append(f"""
|
331 |
<div style="margin-bottom: 20px;">
|
332 |
<div style="font-weight: bold; color: {color}; margin-bottom: 5px;">{title}</div>
|
333 |
<div style="background-color: #f8f9fa; padding: 10px 15px; border-radius: 5px; overflow-x: auto;">
|
334 |
<table style="width: 100%; border-collapse: collapse; white-space: nowrap;">
|
335 |
<tr style="background-color: #e9ecef;">
|
336 |
+
""")
|
337 |
|
338 |
+
# 动态生成表头
|
339 |
headers = table_data[0].keys()
|
340 |
for header in headers:
|
341 |
if header.lower() == '評分' or header.lower() == 'score':
|
342 |
+
html_parts.append(f'<th style="padding: 10px; border: 1px solid #dee2e6; min-width: 80px;">{header}</th>')
|
343 |
else:
|
344 |
+
html_parts.append(f'<th style="padding: 10px; border: 1px solid #dee2e6;">{header}</th>')
|
345 |
+
html_parts.append('</tr>')
|
346 |
|
347 |
+
# 动态生成表格内容
|
348 |
for item in table_data:
|
349 |
+
html_parts.append('<tr>')
|
350 |
for key, value in item.items():
|
351 |
if key.lower() == '評分' or key.lower() == 'score':
|
352 |
+
html_parts.append(f'<td style="padding: 10px; border: 1px solid #dee2e6; min-width: 80px; text-align: center;">{value}</td>')
|
353 |
else:
|
354 |
+
html_parts.append(f'<td style="padding: 10px; border: 1px solid #dee2e6;">{value}</td>')
|
355 |
+
html_parts.append('</tr>')
|
356 |
|
357 |
+
html_parts.append("""
|
358 |
</table>
|
359 |
</div>
|
360 |
</div>
|
361 |
+
""")
|
362 |
+
return ''.join(html_parts)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
363 |
|
364 |
def update_submission_data_html(submission_json):
|
365 |
html = generate_submission_html(submission_json)
|