Spaces:
Sleeping
Sleeping
| from transcriber import transcribe_pdf | |
| from evaluator import eval_flow | |
| import json | |
| import os | |
| def flow(student_pdf_path: str, | |
| standard_pdf_path:str, | |
| save_dict: bool, | |
| student_dict_path: str, | |
| standard_dict_path: str, | |
| output_pdf_path: str): | |
| # create new interim_files folder if multiple instances of the flow are run | |
| # Transcribe the student's PDF response | |
| print("Transcribing the student's response") | |
| student_resp = transcribe_pdf(student_pdf_path, "interim_files_student", save_dict, student_dict_path) | |
| print("--------------------------------------------") | |
| # Transcribe the standard answer key PDF | |
| print("Transcribing the standard answer key") | |
| standard_key = transcribe_pdf(standard_pdf_path, "interim_files_standard", save_dict, standard_dict_path) | |
| print("--------------------------------------------") | |
| # # comment if running full flow | |
| # # when testing the evaluator only | |
| # student_resp = json.load(open(student_dict_path, "r")) | |
| # standard_key = json.load(open(standard_dict_path, "r")) | |
| # Evaluate the student's response and generate a report | |
| print("Evaluating the student's response") | |
| eval_flow(student_resp, standard_key, output_pdf_path) | |
| print("Flow completed successfully!") | |
| print("--------------------------------------------") | |
| # remove the files in the interim_files folder | |
| print("Clearing interim files folder") | |
| for file in os.listdir("interim_files_student"): | |
| file_path = os.path.join("interim_files_student", file) | |
| os.remove(file_path) | |
| for file in os.listdir("interim_files_standard"): | |
| file_path = os.path.join("interim_files_standard", file) | |
| os.remove(file_path) | |
| return output_pdf_path | |
| if __name__ == "__main__": | |
| # student_pdf_path = "examples/Chapter 1 - Indian Regulatory Framework Student Answer Key (1).pdf" | |
| # standard_pdf_path = "examples/Chapter 1 Indian Regulatory Frame Work Standard Question And Answer Key (2).pdf" | |
| student_pdf_path = "examples/ca inter chapter - amalgamation student answer.pdf" | |
| standard_pdf_path = "examples/ca inter chapter - amalgamation.pdf" | |
| save_dict = True | |
| student_dict_path = "student_response.json" | |
| standard_dict_path = "standard_key.json" | |
| output_pdf_path = "output_report.pdf" | |
| flow(student_pdf_path, standard_pdf_path, save_dict, student_dict_path, standard_dict_path, output_pdf_path) | |