Spaces:
Sleeping
Sleeping
File size: 5,024 Bytes
37b9a66 03c245b 37b9a66 03c245b 20d4a20 03c245b 20d4a20 03c245b 37b9a66 20d4a20 37b9a66 20d4a20 6e9921b 03c245b 6e9921b 20d4a20 6e9921b 03c245b ace78a3 37b9a66 03c245b 20d4a20 03c245b 20d4a20 b035c24 20d4a20 37b9a66 4ffb1cb ace78a3 37b9a66 03c245b 37b9a66 1cd4967 f77abbc e7d1bf7 f77abbc 37b9a66 03c245b 37b9a66 03c245b 37b9a66 d521cdd 03c245b 20d4a20 03c245b 20d4a20 03c245b |
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 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 |
import streamlit as st
from src.main import process_essays
from PIL import Image
import os
from openpyxl import load_workbook, Workbook
from io import BytesIO
import openai
import base64
from src.utils import save_workbook_to_bytes, serve_excel_for_download, image_to_base64, download_image
openai_api_key = os.getenv("OPENAI_API_KEY")
# Set the OpenAI API key
openai.api_key = openai_api_key
st.title("AutoAssess: Student Essay Transcription and Assessment")
st.subheader("Upload Student Essays")
# Upload folder of images
uploaded_files = st.file_uploader("Upload a folder of student essays (images). Please make sure that the images are in order i.e. first image is the first page of the first student, the second image is the second page of the first student (if it exists) untill all images of the first student are uploaded which should be followed by the ordererd pages of the second student, etc.", type=['jpg', 'jpeg', 'png'], accept_multiple_files=True)
# Path to your example images (you need to place them in your project directory or provide a URL)
# image_1_path = "example_essay_1.png" # Example file path
# image_2_path = "example_essay_2.png" # Example file path
# # Example images section
# st.text("If you don't have any images to upload, you can download (and reupload) the example images below.")
# # Download buttons for the two example essays (images)
# download_image(image_1_path, "example_essay_1.png")
# download_image(image_2_path, "example_essay_2.png")
# replace uploaded files with files loading from directory
# image_dir = "data/images"
# uploaded_files = []
# for file in os.listdir(image_dir):
# with open(image_dir + '/' + file, "rb") as image_file:
# uploaded_files.append(image_file.read())
# Text inputs for question and criteria
# essay_question = st.text_input("Enter the essay question:")
# grading_criteria = st.text_area("Enter grading criteria or relevant marking information:")
st.subheader("Specify Essay Question")
st.text("For example: What is beauty?")
essay_question = st.text_input("Enter the essay question:")
st.subheader("Specify Grading Criteria")
st.text("For example: Please follow the german grading system where 1 is the best grade and 6 is the worst grade. An essay with a grade of 1 should be well structured, have a clear introduction, body and conclusion, be free of grammatical errors, spelling mistakes and punctuation errors, be original and creative.")
grading_criteria = st.text_area("Enter grading criteria or relevant marking information:")
# essay_question = "What is beauty?"
# grading_criteria = "1. Introduction\n2. Body\n3. Conclusion\n4. Grammar\n5. Spelling\n6. Punctuation\n7. Originality\n8. Creativity"
# Path to the example Excel file in the repository
st.subheader("Specify student IDs and page count")
example_file_path ="example.xlsx"
serve_excel_for_download(example_file_path)
st.text("Please download the example Excel file to see the expected format. You will need to adjust the student IDs and page counts. Note that if you provide a grade and reason for a student, the system will not reassess that student's essay. Further, this will help te system make better assessments by calibrating it to your style of grading. Note that grade and reason must both be specified.")
# Upload Excel file with student IDs and page count
excel_file = st.file_uploader("Upload Excel file with student IDs and page count", type=["xlsx"])
# excel_file = "data/essays.xlsx"
if st.button("Process Essays"):
if not uploaded_files or not essay_question or not grading_criteria or not excel_file:
st.warning("Please upload all required files and enter necessary information.")
else:
st.text("Processing essays...This may take a few seconds.")
st.text("A download button will appear underneath once the process is complete.")
# assert that no duplicate files are uploaded
uploaded_files_names = [file.name for file in uploaded_files]
assert len(uploaded_files_names) == len(set(uploaded_files_names)), "Duplicate images uploaded. Please ensure that each image is only uploaded once."
uploaded_files = sorted(uploaded_files, key=lambda x: x.name)
print(uploaded_files)
# Process student info file
workbook = load_workbook(excel_file)
new_workbook = process_essays(uploaded_files,essay_question,grading_criteria,workbook)
# Optional: Save results to the output folder
# output_file = "output/results.xlsx"
# new_workbook.save(output_file)
# st.success(f"All essays processed. Results saved to {output_file}")
# Convert the workbook to bytes
excel_file = save_workbook_to_bytes(new_workbook)
# Display the download button
st.download_button(
label="Download the assessed Excel file",
data=excel_file,
file_name="assessments.xlsx",
mime="application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"
) |