Spaces:
Sleeping
Sleeping
File size: 1,541 Bytes
e54d523 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 | import docx
from ocr_processing import OCRProcessor
class GradingSystem:
def __init__(self, ocr_handler):
self.ocr_handler = ocr_handler
def extract_answers(self, student_images):
responses = []
for image_path in student_images:
try:
encoded_img = self.ocr_handler.encode_image(image_path)
prompt = "Extract the visible text from the provided image and organize it as structured responses."
result = self.ocr_handler.extract_text_from_image(encoded_img, prompt)
responses.append(result.content)
except Exception as err:
responses.append(f"[Error extracting {image_path}: {err}]")
return "\n".join(responses)
def extract_marking_criteria(self, docx_file):
try:
doc = docx.Document(docx_file)
criteria = [para.text.strip() for para in doc.paragraphs if para.text.strip()]
return "\n".join(criteria)
except Exception as err:
raise Exception(f"Failed to extract criteria: {err}")
def grade_answers(self, student_text, marking_criteria):
prompt = f"Compare the student's responses with the marking scheme and assign grades accordingly. Marking Scheme:\n{marking_criteria}\n\nStudent Response:\n{student_text}"
try:
result = self.ocr_handler.extract_text_from_image("", prompt)
return result.content
except Exception as err:
raise Exception(f"Grading failed: {err}") |