Spaces:
Sleeping
Sleeping
Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,65 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import streamlit as st
|
| 2 |
+
from ocr_processing import OCRProcessor
|
| 3 |
+
from grading_logic import GradingSystem
|
| 4 |
+
import os
|
| 5 |
+
|
| 6 |
+
# Initialize components
|
| 7 |
+
ocr_handler = OCRProcessor()
|
| 8 |
+
grading_handler = GradingSystem(ocr_handler)
|
| 9 |
+
|
| 10 |
+
|
| 11 |
+
def main():
|
| 12 |
+
st.set_page_config(page_title="Grading Assistant", page_icon=":pencil:", layout="wide")
|
| 13 |
+
|
| 14 |
+
st.sidebar.title("Upload Student Files")
|
| 15 |
+
st.sidebar.info("Upload student answer sheets and marking schemes.")
|
| 16 |
+
|
| 17 |
+
student_files = st.sidebar.file_uploader("Upload Answer Sheets", type=["pdf", "jpeg", "jpg", "png"], accept_multiple_files=True)
|
| 18 |
+
marking_scheme_file = st.sidebar.file_uploader("Upload Marking Scheme (DOCX)", type=["docx"])
|
| 19 |
+
|
| 20 |
+
st.title("📖 Automated Grading Assistant")
|
| 21 |
+
st.subheader("An AI-powered tool for grading student responses.")
|
| 22 |
+
|
| 23 |
+
if st.button("Start Grading"):
|
| 24 |
+
if not student_files or not marking_scheme_file:
|
| 25 |
+
st.error("Both student answers and a marking scheme are required!")
|
| 26 |
+
return
|
| 27 |
+
|
| 28 |
+
student_image_paths = []
|
| 29 |
+
for student_file in student_files:
|
| 30 |
+
file_path = f"./uploads/{student_file.name}"
|
| 31 |
+
with open(file_path, "wb") as f:
|
| 32 |
+
f.write(student_file.getvalue())
|
| 33 |
+
|
| 34 |
+
if student_file.name.lower().endswith(".pdf"):
|
| 35 |
+
try:
|
| 36 |
+
extracted_images = ocr_handler.convert_pdf_to_images(file_path)
|
| 37 |
+
student_image_paths.extend(extracted_images)
|
| 38 |
+
except Exception as err:
|
| 39 |
+
st.error(f"Error processing {student_file.name}: {err}")
|
| 40 |
+
else:
|
| 41 |
+
student_image_paths.append(file_path)
|
| 42 |
+
|
| 43 |
+
# Save marking scheme
|
| 44 |
+
marking_scheme_path = f"./uploads/{marking_scheme_file.name}"
|
| 45 |
+
with open(marking_scheme_path, "wb") as f:
|
| 46 |
+
f.write(marking_scheme_file.getvalue())
|
| 47 |
+
|
| 48 |
+
st.info("Extracting student responses...")
|
| 49 |
+
extracted_answers = grading_handler.extract_answers(student_image_paths)
|
| 50 |
+
st.success("Responses extracted successfully.")
|
| 51 |
+
st.text_area("Extracted Responses", extracted_answers, height=200)
|
| 52 |
+
|
| 53 |
+
st.info("Extracting marking scheme...")
|
| 54 |
+
marking_criteria = grading_handler.extract_marking_criteria(marking_scheme_path)
|
| 55 |
+
st.success("Marking scheme extracted.")
|
| 56 |
+
st.text_area("Marking Scheme", marking_criteria, height=200)
|
| 57 |
+
|
| 58 |
+
st.info("Evaluating responses...")
|
| 59 |
+
assessment_results = grading_handler.grade_answers(extracted_answers, marking_criteria)
|
| 60 |
+
st.success("Assessment complete.")
|
| 61 |
+
st.text_area("Assessment Results", assessment_results, height=200)
|
| 62 |
+
|
| 63 |
+
|
| 64 |
+
if __name__ == "__main__":
|
| 65 |
+
main()
|