Spaces:
Running
Running
Commit ·
9d060d5
1
Parent(s): f59cfc7
5th
Browse files
app.py
CHANGED
|
@@ -283,6 +283,9 @@ def get_evaluated_document_count():
|
|
| 283 |
def index():
|
| 284 |
"""Landing page with file upload and evaluator name."""
|
| 285 |
if request.method == 'POST':
|
|
|
|
|
|
|
|
|
|
| 286 |
# Check if the post request has the file part
|
| 287 |
if 'file' not in request.files:
|
| 288 |
error_msg = 'No file part in the request. Please try again.'
|
|
@@ -312,16 +315,19 @@ def index():
|
|
| 312 |
|
| 313 |
if file:
|
| 314 |
try:
|
| 315 |
-
#
|
| 316 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 317 |
|
| 318 |
-
#
|
| 319 |
-
|
| 320 |
-
|
| 321 |
-
flash('File successfully uploaded.')
|
| 322 |
|
| 323 |
# Check file size and contents
|
| 324 |
-
file_size = os.path.getsize(
|
| 325 |
log_error(f"File size: {file_size} bytes")
|
| 326 |
|
| 327 |
if file_size == 0:
|
|
@@ -332,7 +338,7 @@ def index():
|
|
| 332 |
|
| 333 |
# Preview the file contents
|
| 334 |
try:
|
| 335 |
-
with open(
|
| 336 |
first_lines = [next(f) for _ in range(5) if f]
|
| 337 |
log_error(f"File preview: {first_lines}")
|
| 338 |
except Exception as e:
|
|
@@ -541,11 +547,9 @@ def reset():
|
|
| 541 |
return redirect(url_for('index'))
|
| 542 |
|
| 543 |
if __name__ == '__main__':
|
| 544 |
-
#
|
| 545 |
-
|
| 546 |
-
|
| 547 |
-
# Set debug mode for troubleshooting
|
| 548 |
-
app.config['DEBUG'] = True
|
| 549 |
|
| 550 |
-
#
|
| 551 |
app.run(host='0.0.0.0', port=int(os.environ.get('PORT', 7860)))
|
|
|
|
| 283 |
def index():
|
| 284 |
"""Landing page with file upload and evaluator name."""
|
| 285 |
if request.method == 'POST':
|
| 286 |
+
# Ensure data directory exists
|
| 287 |
+
ensure_data_directory()
|
| 288 |
+
|
| 289 |
# Check if the post request has the file part
|
| 290 |
if 'file' not in request.files:
|
| 291 |
error_msg = 'No file part in the request. Please try again.'
|
|
|
|
| 315 |
|
| 316 |
if file:
|
| 317 |
try:
|
| 318 |
+
# Instead of overwriting documents.csv directly, save to a temp file first
|
| 319 |
+
temp_path = os.path.join(DATA_DIR, 'temp_upload.csv')
|
| 320 |
+
file.save(temp_path)
|
| 321 |
+
|
| 322 |
+
# Then try to read it using pandas to validate
|
| 323 |
+
df = load_and_validate_csv(temp_path)
|
| 324 |
|
| 325 |
+
# If successful, move the temp file to documents.csv
|
| 326 |
+
documents_path = os.path.join(DATA_DIR, 'documents.csv')
|
| 327 |
+
shutil.move(temp_path, documents_path)
|
|
|
|
| 328 |
|
| 329 |
# Check file size and contents
|
| 330 |
+
file_size = os.path.getsize(documents_path)
|
| 331 |
log_error(f"File size: {file_size} bytes")
|
| 332 |
|
| 333 |
if file_size == 0:
|
|
|
|
| 338 |
|
| 339 |
# Preview the file contents
|
| 340 |
try:
|
| 341 |
+
with open(documents_path, 'r', encoding='utf-8') as f:
|
| 342 |
first_lines = [next(f) for _ in range(5) if f]
|
| 343 |
log_error(f"File preview: {first_lines}")
|
| 344 |
except Exception as e:
|
|
|
|
| 547 |
return redirect(url_for('index'))
|
| 548 |
|
| 549 |
if __name__ == '__main__':
|
| 550 |
+
# Set up the data directory and initial files
|
| 551 |
+
ensure_data_directory()
|
| 552 |
+
copy_template_if_needed()
|
|
|
|
|
|
|
| 553 |
|
| 554 |
+
# Run the app
|
| 555 |
app.run(host='0.0.0.0', port=int(os.environ.get('PORT', 7860)))
|