youngtsai commited on
Commit
da6f9f2
·
1 Parent(s): 2f705b4

def generate_submission_html(submission_json):

Browse files
Files changed (1) hide show
  1. assignment_ui.py +104 -10
assignment_ui.py CHANGED
@@ -142,30 +142,124 @@ def create_assignment_ui(user_data, assignment_service, submission_service):
142
  choices.append(choice)
143
  return gr.update(choices=choices)
144
 
145
- def update_submission_data_html(submission_json):
 
 
 
146
  html = f"""
147
  <div style="background-color: #f8f9fa; padding: 30px; border-radius: 15px; font-family: 'Helvetica', sans-serif;">
148
  <h2 style="color: #007bff; font-size: 28px; margin-bottom: 20px;">📝 學生回傳作業</h2>
149
  <div style="background-color: white; border-radius: 10px; padding: 20px; box-shadow: 0 2px 4px rgba(0,0,0,0.05);">
150
  <div style="margin-bottom: 20px;">
151
  <div style="font-weight: bold; color: #6c757d; margin-bottom: 5px;">👤 學生姓名</div>
152
- <div style="background-color: #f8f9fa; padding: 10px 15px; border-radius: 5px;">{submission_json['student_name']}</div>
 
 
153
  </div>
154
  <div style="margin-bottom: 20px;">
155
- <div style="font-weight: bold; color: #6c757d; margin-bottom: 5px;">🆔 學生帳號</div>
156
- <div style="background-color: #f8f9fa; padding: 10px 15px; border-radius: 5px;">{submission_json['student_id']}</div>
 
 
157
  </div>
158
  <div style="margin-bottom: 20px;">
159
- <div style="font-weight: bold; color: #28a745; margin-bottom: 5px;">📄 回傳内容</div>
160
- <div style="background-color: #f8f9fa; padding: 10px 15px; border-radius: 5px; white-space: pre-wrap;">{submission_json['submission_data']['content']}</div>
161
  </div>
162
- <div>
163
- <div style="font-weight: bold; color: #17a2b8; margin-bottom: 5px;">🕒 回傳日期</div>
164
- <div style="background-color: #f8f9fa; padding: 10px 15px; border-radius: 5px;">{submission_json['timestamp']}</div>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
165
  </div>
 
 
 
 
 
 
 
 
 
 
166
  </div>
167
  </div>
168
  """
 
 
 
 
 
 
 
 
169
  return gr.update(value=html)
170
 
171
  get_all_assignments_button.click(
@@ -210,7 +304,7 @@ def create_assignment_ui(user_data, assignment_service, submission_service):
210
  outputs=[submission_data_html]
211
  )
212
 
213
- with gr.Tab("學生|模擬繳交"):
214
  with gr.Row():
215
  with gr.Column():
216
  assignment_id_input_student = gr.Textbox(label="作業 ID")
 
142
  choices.append(choice)
143
  return gr.update(choices=choices)
144
 
145
+ def generate_submission_html(submission_json):
146
+ submission_data = submission_json.get('submission_data', {})
147
+ content = submission_data.get('content', {})
148
+
149
  html = f"""
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
  <div style="margin-bottom: 20px;">
154
  <div style="font-weight: bold; color: #6c757d; margin-bottom: 5px;">👤 學生姓名</div>
155
+ <div style="background-color: #f8f9fa; padding: 10px 15px; border-radius: 5px;">
156
+ {submission_json.get('student_name', '未提供')}
157
+ </div>
158
  </div>
159
  <div style="margin-bottom: 20px;">
160
+ <div style="font-weight: bold; color: #6c757d; margin-bottom: 5px;">🆔 學生ID</div>
161
+ <div style="background-color: #f8f9fa; padding: 10px 15px; border-radius: 5px;">
162
+ {submission_json.get('student_id', '未提供')}
163
+ </div>
164
  </div>
165
  <div style="margin-bottom: 20px;">
166
+ <div style="font-weight: bold; color: #6c757d; margin-bottom: 5px;">🕒 繳交時間</div>
167
+ <div style="background-color: #f8f9fa; padding: 10px 15px; border-radius: 5px;">{submission_json.get('timestamp', '未提供')}</div>
168
  </div>
169
+ <div style="margin-bottom: 20px;">
170
+ <div style="font-weight: bold; color: #28a745; margin-bottom: 5px;">📄 輸入段落全文</div>
171
+ <div style="background-color: #f8f9fa; padding: 10px 15px; border-radius: 5px; white-space: pre-wrap;">{content.get('chinese_full_paragraph_input', '未提供')}</div>
172
+ </div>
173
+
174
+ <div style="margin-bottom: 20px;">
175
+ <div style="font-weight: bold; color: #17a2b8; margin-bottom: 5px;">📊 段落全文分析</div>
176
+ <div style="background-color: #f8f9fa; padding: 10px 15px; border-radius: 5px; white-space: pre-wrap;">{content.get('chinese_full_paragraph_evaluate_output_text', '未提供')}</div>
177
+ </div>
178
+ """
179
+
180
+ if 'chinese_full_paragraph_evaluate_output_table' in content:
181
+ html += """
182
+ <div style="margin-bottom: 20px;">
183
+ <div style="font-weight: bold; color: #dc3545; margin-bottom: 5px;">📊 評分結果</div>
184
+ <div style="background-color: #f8f9fa; padding: 10px 15px; border-radius: 5px;">
185
+ <table style="width: 100%; border-collapse: collapse;">
186
+ <tr style="background-color: #e9ecef;">
187
+ <th style="padding: 10px; border: 1px solid #dee2e6;">評分項目</th>
188
+ <th style="padding: 10px; border: 1px solid #dee2e6;">分數</th>
189
+ <th style="padding: 10px; border: 1px solid #dee2e6;">評語</th>
190
+ </tr>
191
+ """
192
+ for item in content['chinese_full_paragraph_evaluate_output_table']:
193
+ html += f"""
194
+ <tr>
195
+ <td style='padding: 10px; border: 1px solid #dee2e6;'>{item.get('架構', '')}</td>
196
+ <td style='padding: 10px; border: 1px solid #dee2e6;'>{item.get('評分', '')}</td>
197
+ <td style='padding: 10px; border: 1px solid #dee2e6;'>{item.get('解釋', '')}</td>
198
+ </tr>
199
+ """
200
+ html += """
201
+ </table>
202
+ </div>
203
+ </div>
204
+ """
205
+
206
+ html += f"""
207
+ <div style="margin-bottom: 20px;">
208
+ <div style="font-weight: bold; color: #6610f2; margin-bottom: 5px;">🔄 段落改善建議 輸入</div>
209
+ <div style="background-color: #f8f9fa; padding: 10px 15px; border-radius: 5px; white-space: pre-wrap;">{content.get('chinese_full_paragraph_refine_input', '未提供')}</div>
210
+ </div>
211
+
212
+ <div style="margin-bottom: 20px;">
213
+ <div style="font-weight: bold; color: #fd7e14; margin-bottom: 5px;">🔄 段落改善建議</div>
214
+ <div style="background-color: #f8f9fa; padding: 10px 15px; border-radius: 5px; white-space: pre-wrap;">{content.get('chinese_full_paragraph_refine_output_text', '未提供')}</div>
215
+ </div>
216
+ """
217
+
218
+ if 'chinese_full_paragraph_refine_output_table' in content:
219
+ html += """
220
+ <div style="margin-bottom: 20px;">
221
+ <div style="font-weight: bold; color: #20c997; margin-bottom: 5px;">📊 修改後評分</div>
222
+ <div style="background-color: #f8f9fa; padding: 10px 15px; border-radius: 5px;">
223
+ <table style="width: 100%; border-collapse: collapse;">
224
+ <tr style="background-color: #e9ecef;">
225
+ <th style="padding: 10px; border: 1px solid #dee2e6;">評分項目</th>
226
+ <th style="padding: 10px; border: 1px solid #dee2e6;">分數</th>
227
+ <th style="padding: 10px; border: 1px solid #dee2e6;">評語</th>
228
+ </tr>
229
+ """
230
+ for item in content['chinese_full_paragraph_refine_output_table']:
231
+ html += f"""
232
+ <tr>
233
+ <td style='padding: 10px; border: 1px solid #dee2e6;'>{item.get('架構', '')}</td>
234
+ <td style='padding: 10px; border: 1px solid #dee2e6;'>{item.get('評分', '')}</td>
235
+ <td style='padding: 10px; border: 1px solid #dee2e6;'>{item.get('解釋', '')}</td>
236
+ </tr>
237
+ """
238
+ html += """
239
+ </table>
240
+ </div>
241
  </div>
242
+ """
243
+
244
+ html += f"""
245
+ <div style="margin-bottom: 20px;">
246
+ <div style="font-weight: bold; color: #20c997; margin-bottom: 5px;">📝 修改結果</div>
247
+ <div style="background-color: #f8f9fa; padding: 10px 15px; border-radius: 5px; white-space: pre-wrap;">{content.get('chinese_full_paragraph_save_output', '未提供')}</div>
248
+ </div>
249
+ """
250
+
251
+ html += """
252
  </div>
253
  </div>
254
  """
255
+ return html
256
+
257
+ def update_submission_data_html(submission_json):
258
+ html = generate_submission_html(submission_json)
259
+ return gr.update(value=html)
260
+
261
+ def update_submission_data_html(submission_json):
262
+ html = generate_submission_html(submission_json)
263
  return gr.update(value=html)
264
 
265
  get_all_assignments_button.click(
 
304
  outputs=[submission_data_html]
305
  )
306
 
307
+ with gr.Tab("生|模擬繳交"):
308
  with gr.Row():
309
  with gr.Column():
310
  assignment_id_input_student = gr.Textbox(label="作業 ID")