Spaces:
Build error
Build error
sanjaymalladi commited on
Commit ·
0ae087f
1
Parent(s): 77014ce
changes made
Browse files
app.py
CHANGED
|
@@ -15,7 +15,7 @@ import numpy as np
|
|
| 15 |
import joblib
|
| 16 |
import base64
|
| 17 |
from werkzeug.utils import secure_filename
|
| 18 |
-
|
| 19 |
# HTML template with embedded JavaScript
|
| 20 |
HTML_TEMPLATE = """
|
| 21 |
<!DOCTYPE html>
|
|
@@ -333,26 +333,25 @@ def batch_process():
|
|
| 333 |
files = request.files.getlist('files[]')
|
| 334 |
user_id = request.form.get('user_id')
|
| 335 |
|
| 336 |
-
|
| 337 |
-
|
| 338 |
-
|
| 339 |
-
|
| 340 |
-
file.
|
| 341 |
-
|
| 342 |
-
|
| 343 |
-
|
| 344 |
-
|
| 345 |
-
|
| 346 |
-
|
| 347 |
-
|
| 348 |
-
|
| 349 |
-
|
| 350 |
-
|
| 351 |
-
|
| 352 |
-
|
| 353 |
-
pass
|
| 354 |
|
| 355 |
-
|
| 356 |
|
| 357 |
if __name__ == '__main__':
|
| 358 |
app.run(host='0.0.0.0', port=7860, debug=True)
|
|
|
|
| 15 |
import joblib
|
| 16 |
import base64
|
| 17 |
from werkzeug.utils import secure_filename
|
| 18 |
+
import tempfile
|
| 19 |
# HTML template with embedded JavaScript
|
| 20 |
HTML_TEMPLATE = """
|
| 21 |
<!DOCTYPE html>
|
|
|
|
| 333 |
files = request.files.getlist('files[]')
|
| 334 |
user_id = request.form.get('user_id')
|
| 335 |
|
| 336 |
+
# Create a temporary directory
|
| 337 |
+
with tempfile.TemporaryDirectory() as temp_dir:
|
| 338 |
+
file_paths = []
|
| 339 |
+
for file in files:
|
| 340 |
+
if file.filename.endswith('.pdf'):
|
| 341 |
+
# Create a secure filename
|
| 342 |
+
secure_name = secure_filename(file.filename)
|
| 343 |
+
# Create full path in temporary directory
|
| 344 |
+
temp_path = os.path.join(temp_dir, secure_name)
|
| 345 |
+
file.save(temp_path)
|
| 346 |
+
file_paths.append(temp_path)
|
| 347 |
+
|
| 348 |
+
try:
|
| 349 |
+
results = processor.process_batch(file_paths, user_id)
|
| 350 |
+
except Exception as e:
|
| 351 |
+
return jsonify({'error': str(e)}), 500
|
| 352 |
+
# No need to manually clean up - TemporaryDirectory does it automatically
|
|
|
|
| 353 |
|
| 354 |
+
return jsonify(results)
|
| 355 |
|
| 356 |
if __name__ == '__main__':
|
| 357 |
app.run(host='0.0.0.0', port=7860, debug=True)
|