Rajarshi255 commited on
Commit
3eb4e47
·
verified ·
1 Parent(s): 54fa237

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +17 -1
app.py CHANGED
@@ -328,6 +328,19 @@ def grade_summary(student_name: str, student_class: str, title: str, student_sum
328
  except Exception as e:
329
  return f"### ❌ Error\n{e}", "", "Not saved."
330
 
 
 
 
 
 
 
 
 
 
 
 
 
 
331
  with gr.Blocks(title="Summary Grader") as demo:
332
  gr.Markdown("## Summary Grader")
333
  with gr.Row():
@@ -335,9 +348,12 @@ with gr.Blocks(title="Summary Grader") as demo:
335
  class_in = gr.Textbox(label="Class")
336
  gr.Button("Marking Scheme").click(fn=intro_message, inputs=[name_in, class_in], outputs=gr.Markdown())
337
  title_in = gr.Textbox(label="Title")
338
- summary_in = gr.Textbox(label="Summary", lines=10)
 
 
339
  btn = gr.Button("Grade & Save", variant="primary")
340
  btn.click(fn=grade_summary, inputs=[name_in, class_in, title_in, summary_in], outputs=[gr.Markdown(), gr.Textbox(), gr.Markdown()])
 
341
 
342
  if __name__ == "__main__":
343
  demo.launch()
 
328
  except Exception as e:
329
  return f"### ❌ Error\n{e}", "", "Not saved."
330
 
331
+ # JavaScript to block pasting on the specific 'summary-input' component
332
+ block_paste_js = """
333
+ function() {
334
+ const target = document.querySelector("#summary-input textarea");
335
+ if (target) {
336
+ target.addEventListener('paste', function(e) {
337
+ e.preventDefault();
338
+ alert("⚠️ Please type your summary manually. Copy-pasting is disabled!");
339
+ });
340
+ }
341
+ }
342
+ """
343
+
344
  with gr.Blocks(title="Summary Grader") as demo:
345
  gr.Markdown("## Summary Grader")
346
  with gr.Row():
 
348
  class_in = gr.Textbox(label="Class")
349
  gr.Button("Marking Scheme").click(fn=intro_message, inputs=[name_in, class_in], outputs=gr.Markdown())
350
  title_in = gr.Textbox(label="Title")
351
+ #summary_in = gr.Textbox(label="Summary", lines=10)
352
+ # Add elem_id="summary-input" so the JavaScript can find this specific box
353
+ summary_in = gr.Textbox(label="Summary", lines=10, elem_id="summary-input")
354
  btn = gr.Button("Grade & Save", variant="primary")
355
  btn.click(fn=grade_summary, inputs=[name_in, class_in, title_in, summary_in], outputs=[gr.Markdown(), gr.Textbox(), gr.Markdown()])
356
+ demo.load(None, None, None, js=block_paste_js)
357
 
358
  if __name__ == "__main__":
359
  demo.launch()