Update app.py
Browse files
app.py
CHANGED
@@ -17,6 +17,7 @@ from openpyxl import Workbook
|
|
17 |
from openpyxl.utils import get_column_letter
|
18 |
from io import BytesIO
|
19 |
import base64
|
|
|
20 |
|
21 |
# Configure logging
|
22 |
logging.basicConfig(level=logging.INFO)
|
@@ -31,12 +32,28 @@ CONFIDENCE_THRESHOLD = 0.65
|
|
31 |
BATCH_SIZE = 8 # Reduced batch size for CPU
|
32 |
MAX_WORKERS = 4 # Number of worker threads for processing
|
33 |
|
34 |
-
#
|
35 |
-
|
|
|
|
|
|
|
|
|
|
|
36 |
|
37 |
# Excel file path for logs
|
38 |
EXCEL_LOG_PATH = "/tmp/prediction_logs.xlsx"
|
39 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
40 |
class TextWindowProcessor:
|
41 |
def __init__(self):
|
42 |
try:
|
@@ -428,8 +445,8 @@ def get_logs_as_base64():
|
|
428 |
|
429 |
def analyze_text(text: str, mode: str, classifier: TextClassifier) -> tuple:
|
430 |
"""Analyze text using specified mode and return formatted results."""
|
431 |
-
# Check if the input text matches the
|
432 |
-
if text.strip()
|
433 |
# Return logs instead of analysis
|
434 |
base64_data = get_logs_as_base64()
|
435 |
logs_timestamp = datetime.now().strftime("%Y%m%d_%H%M%S")
|
|
|
17 |
from openpyxl.utils import get_column_letter
|
18 |
from io import BytesIO
|
19 |
import base64
|
20 |
+
import hashlib
|
21 |
|
22 |
# Configure logging
|
23 |
logging.basicConfig(level=logging.INFO)
|
|
|
32 |
BATCH_SIZE = 8 # Reduced batch size for CPU
|
33 |
MAX_WORKERS = 4 # Number of worker threads for processing
|
34 |
|
35 |
+
# Get password hash from environment variable (more secure)
|
36 |
+
ADMIN_PASSWORD_HASH = os.environ.get('ADMIN_PASSWORD_HASH')
|
37 |
+
|
38 |
+
# If the environment variable isn't set, use a default hash (for development only)
|
39 |
+
# This is the hash of "default_password_for_development_only" - change this in production!
|
40 |
+
if not ADMIN_PASSWORD_HASH:
|
41 |
+
ADMIN_PASSWORD_HASH = "5e22d1ed71b273b1b2b5331f2d3e0f6cf34595236f201c6924d6bc81de27cdcb"
|
42 |
|
43 |
# Excel file path for logs
|
44 |
EXCEL_LOG_PATH = "/tmp/prediction_logs.xlsx"
|
45 |
|
46 |
+
def is_admin_password(input_text: str) -> bool:
|
47 |
+
"""
|
48 |
+
Check if the input text matches the admin password using secure hash comparison.
|
49 |
+
This prevents the password from being visible in the source code.
|
50 |
+
"""
|
51 |
+
# Hash the input text
|
52 |
+
input_hash = hashlib.sha256(input_text.strip().encode()).hexdigest()
|
53 |
+
|
54 |
+
# Compare hashes (constant-time comparison to prevent timing attacks)
|
55 |
+
return input_hash == ADMIN_PASSWORD_HASH
|
56 |
+
|
57 |
class TextWindowProcessor:
|
58 |
def __init__(self):
|
59 |
try:
|
|
|
445 |
|
446 |
def analyze_text(text: str, mode: str, classifier: TextClassifier) -> tuple:
|
447 |
"""Analyze text using specified mode and return formatted results."""
|
448 |
+
# Check if the input text matches the admin password using secure comparison
|
449 |
+
if is_admin_password(text.strip()):
|
450 |
# Return logs instead of analysis
|
451 |
base64_data = get_logs_as_base64()
|
452 |
logs_timestamp = datetime.now().strftime("%Y%m%d_%H%M%S")
|