Update app.py
Browse files
app.py
CHANGED
|
@@ -27,11 +27,16 @@ import json
|
|
| 27 |
import csv
|
| 28 |
from datetime import datetime
|
| 29 |
import io
|
|
|
|
|
|
|
| 30 |
|
| 31 |
from dotenv import load_dotenv
|
| 32 |
|
| 33 |
load_dotenv()
|
| 34 |
|
|
|
|
|
|
|
|
|
|
| 35 |
|
| 36 |
#===========================================================================
|
| 37 |
# Clear the /tmp directory on startup
|
|
@@ -138,10 +143,16 @@ tesseract_path = os.getenv("TESSERACT_PATH", r"C:\Program Files\Tesseract-OCR\te
|
|
| 138 |
pytesseract.pytesseract.tesseract_cmd = tesseract_path
|
| 139 |
|
| 140 |
app = Flask(__name__)
|
| 141 |
-
app.config['SECRET_KEY'] = '
|
| 142 |
app.config['UPLOAD_FOLDER'] = 'uploads'
|
| 143 |
app.config['MAX_CONTENT_LENGTH'] = 16 * 1024 * 1024 # 16MB max file size
|
| 144 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 145 |
|
| 146 |
os.makedirs(app.config['UPLOAD_FOLDER'], exist_ok=True)
|
| 147 |
|
|
@@ -699,6 +710,11 @@ def export_csv():
|
|
| 699 |
|
| 700 |
# Option 2: From global variable (if you stored it there)
|
| 701 |
# transformed_data = current_analysis_results
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 702 |
|
| 703 |
if not transformed_data:
|
| 704 |
return jsonify({'error': 'No analysis data available'}), 400
|
|
@@ -793,7 +809,8 @@ def export_csv():
|
|
| 793 |
|
| 794 |
except Exception as e:
|
| 795 |
print(f"Error exporting CSV: {e}")
|
| 796 |
-
|
|
|
|
| 797 |
|
| 798 |
#======================================================================================================================
|
| 799 |
@app.route('/')
|
|
|
|
| 27 |
import csv
|
| 28 |
from datetime import datetime
|
| 29 |
import io
|
| 30 |
+
import secrets
|
| 31 |
+
import traceback
|
| 32 |
|
| 33 |
from dotenv import load_dotenv
|
| 34 |
|
| 35 |
load_dotenv()
|
| 36 |
|
| 37 |
+
current_analysis_data = {}
|
| 38 |
+
|
| 39 |
+
|
| 40 |
|
| 41 |
#===========================================================================
|
| 42 |
# Clear the /tmp directory on startup
|
|
|
|
| 143 |
pytesseract.pytesseract.tesseract_cmd = tesseract_path
|
| 144 |
|
| 145 |
app = Flask(__name__)
|
| 146 |
+
app.config['SECRET_KEY'] = os.getenv('SECRET_KEY', secrets.token_hex(32))
|
| 147 |
app.config['UPLOAD_FOLDER'] = 'uploads'
|
| 148 |
app.config['MAX_CONTENT_LENGTH'] = 16 * 1024 * 1024 # 16MB max file size
|
| 149 |
|
| 150 |
+
# Session configuration for production
|
| 151 |
+
app.config['SESSION_COOKIE_SECURE'] = True # Set to True if using HTTPS
|
| 152 |
+
app.config['SESSION_COOKIE_HTTPONLY'] = True
|
| 153 |
+
app.config['SESSION_COOKIE_SAMESITE'] = 'Lax'
|
| 154 |
+
app.config['PERMANENT_SESSION_LIFETIME'] = 3600 # 1 hour
|
| 155 |
+
|
| 156 |
|
| 157 |
os.makedirs(app.config['UPLOAD_FOLDER'], exist_ok=True)
|
| 158 |
|
|
|
|
| 710 |
|
| 711 |
# Option 2: From global variable (if you stored it there)
|
| 712 |
# transformed_data = current_analysis_results
|
| 713 |
+
|
| 714 |
+
if not transformed_data:
|
| 715 |
+
print("Session data not found, using global variable")
|
| 716 |
+
global current_analysis_data
|
| 717 |
+
transformed_data = current_analysis_data
|
| 718 |
|
| 719 |
if not transformed_data:
|
| 720 |
return jsonify({'error': 'No analysis data available'}), 400
|
|
|
|
| 809 |
|
| 810 |
except Exception as e:
|
| 811 |
print(f"Error exporting CSV: {e}")
|
| 812 |
+
traceback.print_exc()
|
| 813 |
+
return jsonify({'error': f'Export failed: {str(e)}'), 500
|
| 814 |
|
| 815 |
#======================================================================================================================
|
| 816 |
@app.route('/')
|