AutoAssess / app.py
TensorFlo's picture
fixed iterate till first empty row
b035c24
raw
history blame
4.54 kB
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:
uploaded_files = sorted(uploaded_files, key=lambda x: x.name)
# 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"
)