yamanavijayavardhan commited on
Commit
9ea114e
·
1 Parent(s): bea66a9
Files changed (1) hide show
  1. main.py +40 -3
main.py CHANGED
@@ -124,34 +124,44 @@ def compute_marks():
124
  if not a:
125
  return jsonify({"error": "No answers provided"}), 400
126
 
 
127
  print("Received answers:", a)
128
  a = json.loads(a)
129
  answers = []
130
  for i in a:
131
  ans = i.split('\n\n')
132
  answers.append(ans)
133
- print("Processed answers:", answers)
134
 
135
  # Process files and create data structure
136
  data = {}
137
  parent_folder = os.path.join(cache_dir, 'student_answers')
138
  os.makedirs(parent_folder, exist_ok=True)
139
 
 
140
  # First, save uploaded files
141
  files = request.files.getlist('files[]')
142
  if not files:
143
  return jsonify({"error": "No files uploaded"}), 400
144
 
 
 
145
  # Save files to temporary directory with proper naming
146
  for file in files:
147
  if file.filename.endswith(('.jpg', '.jpeg', '.png')):
148
  relative_path = file.filename.replace('\\', '/')
149
  path_parts = relative_path.split('/')
150
 
 
 
 
151
  if len(path_parts) >= 2:
152
  student_folder = path_parts[1]
153
  file_name = path_parts[-1]
154
 
 
 
 
155
  # Create student folder
156
  student_dir = os.path.join(parent_folder, student_folder)
157
  os.makedirs(student_dir, exist_ok=True)
@@ -159,6 +169,7 @@ def compute_marks():
159
  # Save file with original name to maintain order
160
  save_path = os.path.join(student_dir, file_name)
161
  file.save(save_path)
 
162
 
163
  # Store in data structure
164
  if student_folder not in data:
@@ -167,8 +178,34 @@ def compute_marks():
167
  'path': save_path,
168
  'name': os.path.splitext(file_name)[0]
169
  })
170
-
171
- print("Initial data structure:", data)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
172
 
173
  # Create vectors for reference answers
174
  sen_vec_answers = []
 
124
  if not a:
125
  return jsonify({"error": "No answers provided"}), 400
126
 
127
+ print("\n=== Processing Answers ===")
128
  print("Received answers:", a)
129
  a = json.loads(a)
130
  answers = []
131
  for i in a:
132
  ans = i.split('\n\n')
133
  answers.append(ans)
134
+ print("Number of reference answers:", len(answers))
135
 
136
  # Process files and create data structure
137
  data = {}
138
  parent_folder = os.path.join(cache_dir, 'student_answers')
139
  os.makedirs(parent_folder, exist_ok=True)
140
 
141
+ print("\n=== Processing Uploaded Files ===")
142
  # First, save uploaded files
143
  files = request.files.getlist('files[]')
144
  if not files:
145
  return jsonify({"error": "No files uploaded"}), 400
146
 
147
+ print(f"Number of files received: {len(files)}")
148
+
149
  # Save files to temporary directory with proper naming
150
  for file in files:
151
  if file.filename.endswith(('.jpg', '.jpeg', '.png')):
152
  relative_path = file.filename.replace('\\', '/')
153
  path_parts = relative_path.split('/')
154
 
155
+ print(f"\nProcessing file: {file.filename}")
156
+ print(f"Path parts: {path_parts}")
157
+
158
  if len(path_parts) >= 2:
159
  student_folder = path_parts[1]
160
  file_name = path_parts[-1]
161
 
162
+ print(f"Student folder: {student_folder}")
163
+ print(f"File name: {file_name}")
164
+
165
  # Create student folder
166
  student_dir = os.path.join(parent_folder, student_folder)
167
  os.makedirs(student_dir, exist_ok=True)
 
169
  # Save file with original name to maintain order
170
  save_path = os.path.join(student_dir, file_name)
171
  file.save(save_path)
172
+ print(f"Saved to: {save_path}")
173
 
174
  # Store in data structure
175
  if student_folder not in data:
 
178
  'path': save_path,
179
  'name': os.path.splitext(file_name)[0]
180
  })
181
+ else:
182
+ print(f"Warning: File {file.filename} doesn't have the expected folder structure")
183
+
184
+ print("\n=== Final Data Structure ===")
185
+ for student, images in data.items():
186
+ print(f"\nStudent: {student}")
187
+ print("Images:")
188
+ for img in sorted(images, key=lambda x: x['name']):
189
+ print(f" - {img['name']} ({img['path']})")
190
+
191
+ # Verify mapping before processing
192
+ print("\n=== Verifying File Mapping ===")
193
+ for student_folder, images in data.items():
194
+ print(f"\nChecking student folder: {student_folder}")
195
+ actual_files = os.listdir(os.path.join(parent_folder, student_folder))
196
+ mapped_files = [os.path.basename(img['path']) for img in images]
197
+
198
+ print(f"Files in directory: {actual_files}")
199
+ print(f"Files in data structure: {mapped_files}")
200
+
201
+ # Check for mismatches
202
+ missing_files = set(actual_files) - set(mapped_files)
203
+ extra_files = set(mapped_files) - set(actual_files)
204
+
205
+ if missing_files:
206
+ print(f"Warning: Files in directory but not mapped: {missing_files}")
207
+ if extra_files:
208
+ print(f"Warning: Files mapped but not in directory: {extra_files}")
209
 
210
  # Create vectors for reference answers
211
  sen_vec_answers = []