Commit
·
10d6457
1
Parent(s):
666fb5d
update_
Browse files- main.py +0 -9
- requirements.txt +1 -0
- templates/index.html +25 -5
main.py
CHANGED
@@ -5,8 +5,6 @@ import logging
|
|
5 |
import sys
|
6 |
import builtins
|
7 |
from datetime import datetime
|
8 |
-
from flask_limiter import Limiter
|
9 |
-
from flask_limiter.util import get_remote_address
|
10 |
from flask_cors import CORS
|
11 |
from dotenv import load_dotenv
|
12 |
|
@@ -101,13 +99,6 @@ CORS(app, resources={
|
|
101 |
}
|
102 |
})
|
103 |
|
104 |
-
# Initialize rate limiter
|
105 |
-
limiter = Limiter(
|
106 |
-
app=app,
|
107 |
-
key_func=get_remote_address,
|
108 |
-
default_limits=["200 per day", "50 per hour"]
|
109 |
-
)
|
110 |
-
|
111 |
@app.route('/')
|
112 |
def index():
|
113 |
return render_template('index.html')
|
|
|
5 |
import sys
|
6 |
import builtins
|
7 |
from datetime import datetime
|
|
|
|
|
8 |
from flask_cors import CORS
|
9 |
from dotenv import load_dotenv
|
10 |
|
|
|
99 |
}
|
100 |
})
|
101 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
102 |
@app.route('/')
|
103 |
def index():
|
104 |
return render_template('index.html')
|
requirements.txt
CHANGED
@@ -4,6 +4,7 @@ torch==2.2.2
|
|
4 |
transformers==4.40.1
|
5 |
sentence-transformers==2.7.0
|
6 |
opencv-python-headless==4.9.0.80
|
|
|
7 |
|
8 |
# Specific versions for scipy/numpy/gensim compatibility
|
9 |
numpy==1.24.4
|
|
|
4 |
transformers==4.40.1
|
5 |
sentence-transformers==2.7.0
|
6 |
opencv-python-headless==4.9.0.80
|
7 |
+
flask-cors==3.0.10
|
8 |
|
9 |
# Specific versions for scipy/numpy/gensim compatibility
|
10 |
numpy==1.24.4
|
templates/index.html
CHANGED
@@ -903,6 +903,13 @@
|
|
903 |
return;
|
904 |
}
|
905 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
906 |
if (selectedFiles.size === 0) {
|
907 |
alert("Please upload student answer files!");
|
908 |
return;
|
@@ -920,18 +927,27 @@
|
|
920 |
const formData = new FormData();
|
921 |
formData.append('answers', JSON.stringify(answers));
|
922 |
|
923 |
-
// Add files with their paths
|
|
|
924 |
selectedFiles.forEach((fileInfo, path) => {
|
925 |
-
|
|
|
|
|
|
|
926 |
});
|
927 |
|
|
|
|
|
|
|
|
|
928 |
const response = await fetch('/compute_marks', {
|
929 |
method: 'POST',
|
930 |
body: formData
|
931 |
});
|
932 |
|
933 |
if (!response.ok) {
|
934 |
-
|
|
|
935 |
}
|
936 |
|
937 |
const result = await response.json();
|
@@ -941,6 +957,10 @@
|
|
941 |
throw new Error(result.error);
|
942 |
}
|
943 |
|
|
|
|
|
|
|
|
|
944 |
displayMarks(result.message);
|
945 |
|
946 |
// Reset button
|
@@ -961,8 +981,8 @@
|
|
961 |
const container = document.getElementById('marks-table-container');
|
962 |
container.innerHTML = '';
|
963 |
|
964 |
-
if (!results || results.length === 0) {
|
965 |
-
container.innerHTML = '<p>No marks
|
966 |
return;
|
967 |
}
|
968 |
|
|
|
903 |
return;
|
904 |
}
|
905 |
|
906 |
+
// Validate that answers are not empty
|
907 |
+
const answers = Array.from(answerBoxes).map(box => box.value.trim());
|
908 |
+
if (answers.some(answer => !answer)) {
|
909 |
+
alert("Please ensure all answer boxes are filled!");
|
910 |
+
return;
|
911 |
+
}
|
912 |
+
|
913 |
if (selectedFiles.size === 0) {
|
914 |
alert("Please upload student answer files!");
|
915 |
return;
|
|
|
927 |
const formData = new FormData();
|
928 |
formData.append('answers', JSON.stringify(answers));
|
929 |
|
930 |
+
// Add files with their paths and validate file types
|
931 |
+
let validFiles = 0;
|
932 |
selectedFiles.forEach((fileInfo, path) => {
|
933 |
+
if (fileInfo.file.type.startsWith('image/')) {
|
934 |
+
formData.append('files[]', fileInfo.file, path);
|
935 |
+
validFiles++;
|
936 |
+
}
|
937 |
});
|
938 |
|
939 |
+
if (validFiles === 0) {
|
940 |
+
throw new Error("No valid image files found in the uploaded folder");
|
941 |
+
}
|
942 |
+
|
943 |
const response = await fetch('/compute_marks', {
|
944 |
method: 'POST',
|
945 |
body: formData
|
946 |
});
|
947 |
|
948 |
if (!response.ok) {
|
949 |
+
const errorData = await response.json();
|
950 |
+
throw new Error(errorData.error || 'Server returned an error response');
|
951 |
}
|
952 |
|
953 |
const result = await response.json();
|
|
|
957 |
throw new Error(result.error);
|
958 |
}
|
959 |
|
960 |
+
if (!result.message || Object.keys(result.message).length === 0) {
|
961 |
+
throw new Error("No marks were computed. Please check your input files and answers.");
|
962 |
+
}
|
963 |
+
|
964 |
displayMarks(result.message);
|
965 |
|
966 |
// Reset button
|
|
|
981 |
const container = document.getElementById('marks-table-container');
|
982 |
container.innerHTML = '';
|
983 |
|
984 |
+
if (!results || Object.keys(results).length === 0) {
|
985 |
+
container.innerHTML = '<p class="error-message">No marks were computed. Please check your input files and answers.</p>';
|
986 |
return;
|
987 |
}
|
988 |
|