Spaces:
Build error
Build error
sanjaymalladi
commited on
Commit
·
77014ce
1
Parent(s):
0526384
fixed few errors
Browse files- app.py +7 -17
- requirements.txt +1 -2
app.py
CHANGED
@@ -15,7 +15,6 @@ import numpy as np
|
|
15 |
import joblib
|
16 |
import base64
|
17 |
from werkzeug.utils import secure_filename
|
18 |
-
from flask_sqlalchemy import SQLAlchemy
|
19 |
|
20 |
# HTML template with embedded JavaScript
|
21 |
HTML_TEMPLATE = """
|
@@ -320,7 +319,6 @@ class EnhancedDocProcessor:
|
|
320 |
return results
|
321 |
|
322 |
app = Flask(__name__)
|
323 |
-
db = SQLAlchemy(app)
|
324 |
processor = EnhancedDocProcessor()
|
325 |
|
326 |
@app.route('/')
|
@@ -336,21 +334,14 @@ def batch_process():
|
|
336 |
user_id = request.form.get('user_id')
|
337 |
|
338 |
file_paths = []
|
339 |
-
|
340 |
-
|
341 |
-
|
|
|
|
|
|
|
342 |
try:
|
343 |
-
for file in files:
|
344 |
-
if file.filename.endswith('.pdf'):
|
345 |
-
filename = secure_filename(file.filename)
|
346 |
-
temp_path = os.path.join(temp_dir, filename)
|
347 |
-
file.save(temp_path)
|
348 |
-
file_paths.append(temp_path)
|
349 |
-
|
350 |
-
processor = EnhancedDocProcessor(db, app.config['UPLOAD_FOLDER'], app.config['TEMP_FOLDER'])
|
351 |
results = processor.process_batch(file_paths, user_id)
|
352 |
-
except PermissionError:
|
353 |
-
return jsonify({'error': 'Permission denied. Please check your permissions.'}), 403
|
354 |
except Exception as e:
|
355 |
return jsonify({'error': str(e)}), 500
|
356 |
finally:
|
@@ -360,8 +351,7 @@ def batch_process():
|
|
360 |
os.remove(path)
|
361 |
except:
|
362 |
pass
|
363 |
-
|
364 |
-
|
365 |
return jsonify(results)
|
366 |
|
367 |
if __name__ == '__main__':
|
|
|
15 |
import joblib
|
16 |
import base64
|
17 |
from werkzeug.utils import secure_filename
|
|
|
18 |
|
19 |
# HTML template with embedded JavaScript
|
20 |
HTML_TEMPLATE = """
|
|
|
319 |
return results
|
320 |
|
321 |
app = Flask(__name__)
|
|
|
322 |
processor = EnhancedDocProcessor()
|
323 |
|
324 |
@app.route('/')
|
|
|
334 |
user_id = request.form.get('user_id')
|
335 |
|
336 |
file_paths = []
|
337 |
+
for file in files:
|
338 |
+
if file.filename.endswith('.pdf'):
|
339 |
+
temp_path = f"temp_{file.filename}"
|
340 |
+
file.save(temp_path)
|
341 |
+
file_paths.append(temp_path)
|
342 |
+
|
343 |
try:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
344 |
results = processor.process_batch(file_paths, user_id)
|
|
|
|
|
345 |
except Exception as e:
|
346 |
return jsonify({'error': str(e)}), 500
|
347 |
finally:
|
|
|
351 |
os.remove(path)
|
352 |
except:
|
353 |
pass
|
354 |
+
|
|
|
355 |
return jsonify(results)
|
356 |
|
357 |
if __name__ == '__main__':
|
requirements.txt
CHANGED
@@ -4,5 +4,4 @@ scikit-learn==1.0.2
|
|
4 |
numpy==1.21.2
|
5 |
joblib==1.1.0
|
6 |
gunicorn==20.1.0
|
7 |
-
werkzeug==2.0.1
|
8 |
-
flask-sqlalchemy
|
|
|
4 |
numpy==1.21.2
|
5 |
joblib==1.1.0
|
6 |
gunicorn==20.1.0
|
7 |
+
werkzeug==2.0.1
|
|