File size: 2,646 Bytes
37b9a66
03c245b
37b9a66
03c245b
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
37b9a66
 
 
03c245b
 
 
37b9a66
ace78a3
03c245b
 
ace78a3
 
 
 
 
37b9a66
 
03c245b
 
 
 
 
37b9a66
 
ace78a3
 
37b9a66
 
03c245b
37b9a66
 
 
03c245b
 
37b9a66
03c245b
37b9a66
 
 
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
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

def save_workbook_to_bytes(wb):
    # Save the workbook into a BytesIO object (in memory, not on disk)
    byte_io = BytesIO()
    wb.save(byte_io)
    byte_io.seek(0)  # Go to the beginning of the BytesIO buffer
    return byte_io.getvalue()


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.title("AutoAssess")
st.write("If you see this, the basic app is loading correctly!")

# Upload folder of images
uploaded_files = sorted(st.file_uploader("Upload a folder of student essays (images)", type=['jpg', 'jpeg', 'png'], accept_multiple_files=True))

# 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:")

essay_question = "What is beauty?"
grading_criteria = "1. Introduction\n2. Body\n3. Conclusion\n4. Grammar\n5. Spelling\n6. Punctuation\n7. Originality\n8. Creativity"

# Upload Excel file with student IDs and page count
student_info_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:
        # 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 Excel file",
            data=excel_file,
            file_name="results.xlsx",
            mime="application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"
)