atz21 commited on
Commit
f4d049d
·
verified ·
1 Parent(s): 7a68726

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +35 -1
app.py CHANGED
@@ -562,6 +562,32 @@ def align_and_grade_pipeline(qp_path, ms_path, ans_path, imprint=False):
562
  })
563
  print("🔗 Graph bundles for grading:", graph_bundles)
564
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
565
  # Step 4: Grading - send both transcripts to grading model, inject graph bundle info
566
  print("2) Preparing grading input and sending to Gemini for grading...")
567
  grading_input = (
@@ -581,7 +607,15 @@ def align_and_grade_pipeline(qp_path, ms_path, ans_path, imprint=False):
581
  grading_input += graph_note
582
 
583
  grading_prompt_system = PROMPTS["GRADING_PROMPT"]["content"]
584
- grading_text = gemini_generate_content(model, grading_prompt_system + "\n\nPlease grade the following transcripts:\n" + grading_input)
 
 
 
 
 
 
 
 
585
  print("🧾 Grading output received. Saving debug file: debug_grading.md")
586
  with open("debug_grading.md", "w", encoding="utf-8") as f:
587
  f.write(grading_text)
 
562
  })
563
  print("🔗 Graph bundles for grading:", graph_bundles)
564
 
565
+ # --- NEW: Separate and save graph pages as images ---
566
+ ms_images = convert_from_path(ms_path, dpi=200)
567
+ ans_images = convert_from_path(ans_path, dpi=200)
568
+ graph_image_paths = [] # To collect for grading prompt if needed
569
+ for bundle in graph_bundles:
570
+ q = bundle['question']
571
+ ms_page = bundle['ms_page']
572
+ as_page = bundle['as_page']
573
+ # Markscheme graph page
574
+ ms_img_path = f"ms_graph_Q{q}.png"
575
+ try:
576
+ ms_images[ms_page-1].save(ms_img_path)
577
+ print(f"🖼️ Separated Markscheme graph page for Q{q}: source=MS, page={ms_page}, output={ms_img_path}")
578
+ graph_image_paths.append((f"ms_graph_Q{q}", ms_img_path))
579
+ except Exception as e:
580
+ print(f"❌ Failed to save Markscheme graph page for Q{q}: {e}")
581
+ # Answer Sheet graph page
582
+ as_img_path = f"as_graph_Q{q}.png"
583
+ try:
584
+ ans_images[as_page-1].save(as_img_path)
585
+ print(f"🖼️ Separated Answer Sheet graph page for Q{q}: source=AS, page={as_page}, output={as_img_path}")
586
+ graph_image_paths.append((f"as_graph_Q{q}", as_img_path))
587
+ except Exception as e:
588
+ print(f"❌ Failed to save Answer Sheet graph page for Q{q}: {e}")
589
+ # --- END NEW ---
590
+
591
  # Step 4: Grading - send both transcripts to grading model, inject graph bundle info
592
  print("2) Preparing grading input and sending to Gemini for grading...")
593
  grading_input = (
 
607
  grading_input += graph_note
608
 
609
  grading_prompt_system = PROMPTS["GRADING_PROMPT"]["content"]
610
+ # --- NEW: Attach graph images to grading prompt if graph bundles exist ---
611
+ if graph_bundles and graph_image_paths:
612
+ print(f"📎 Attaching {len(graph_image_paths)} graph images to grading prompt for visual grading.")
613
+ # If gemini_generate_content supports image_obj list, pass it here. Otherwise, just print for now.
614
+ # grading_text = gemini_generate_content(model, grading_prompt_system + "\n\nPlease grade the following transcripts:\n" + grading_input, image_obj=[p[1] for p in graph_image_paths])
615
+ grading_text = gemini_generate_content(model, grading_prompt_system + "\n\nPlease grade the following transcripts:\n" + grading_input)
616
+ else:
617
+ grading_text = gemini_generate_content(model, grading_prompt_system + "\n\nPlease grade the following transcripts:\n" + grading_input)
618
+ # --- END NEW ---
619
  print("🧾 Grading output received. Saving debug file: debug_grading.md")
620
  with open("debug_grading.md", "w", encoding="utf-8") as f:
621
  f.write(grading_text)