Commit
·
16edead
1
Parent(s):
10d6457
update_
Browse files- main.py +5 -7
- requirements.txt +1 -0
- templates/index.html +2 -3
main.py
CHANGED
@@ -12,7 +12,8 @@ from dotenv import load_dotenv
|
|
12 |
load_dotenv()
|
13 |
|
14 |
# Create a logs directory in the temp folder
|
15 |
-
|
|
|
16 |
os.makedirs(log_dir, exist_ok=True)
|
17 |
|
18 |
# Create a log file with timestamp
|
@@ -43,7 +44,7 @@ def log_print(message, level="INFO"):
|
|
43 |
logger.warning(message)
|
44 |
|
45 |
# Set up all cache and data directories in /tmp
|
46 |
-
cache_dir =
|
47 |
nltk_data_dir = os.path.join(cache_dir, 'nltk_data')
|
48 |
gensim_data_dir = os.path.join(cache_dir, 'gensim-data')
|
49 |
upload_dir = os.path.join(cache_dir, 'uploads')
|
@@ -383,10 +384,9 @@ def allowed_file(filename, allowed_extensions):
|
|
383 |
filename.rsplit('.', 1)[1].lower() in allowed_extensions
|
384 |
|
385 |
def cleanup_temp_files():
|
386 |
-
"""Clean up temporary files and directories"""
|
387 |
try:
|
388 |
import shutil
|
389 |
-
temp_dirs = [ans_image_dir, upload_dir
|
390 |
for directory in temp_dirs:
|
391 |
if os.path.exists(directory):
|
392 |
shutil.rmtree(directory)
|
@@ -397,9 +397,7 @@ def cleanup_temp_files():
|
|
397 |
|
398 |
if __name__ == '__main__':
|
399 |
try:
|
400 |
-
# Get port from environment variable or use default
|
401 |
port = int(os.environ.get('PORT', 7860))
|
402 |
-
|
403 |
-
app.run(host='0.0.0.0', port=port)
|
404 |
finally:
|
405 |
cleanup_temp_files()
|
|
|
12 |
load_dotenv()
|
13 |
|
14 |
# Create a logs directory in the temp folder
|
15 |
+
BASE_DIR = os.path.dirname(os.path.abspath(__file__))
|
16 |
+
log_dir = os.path.join(BASE_DIR, 'logs')
|
17 |
os.makedirs(log_dir, exist_ok=True)
|
18 |
|
19 |
# Create a log file with timestamp
|
|
|
44 |
logger.warning(message)
|
45 |
|
46 |
# Set up all cache and data directories in /tmp
|
47 |
+
cache_dir = os.path.join(BASE_DIR, 'cache')
|
48 |
nltk_data_dir = os.path.join(cache_dir, 'nltk_data')
|
49 |
gensim_data_dir = os.path.join(cache_dir, 'gensim-data')
|
50 |
upload_dir = os.path.join(cache_dir, 'uploads')
|
|
|
384 |
filename.rsplit('.', 1)[1].lower() in allowed_extensions
|
385 |
|
386 |
def cleanup_temp_files():
|
|
|
387 |
try:
|
388 |
import shutil
|
389 |
+
temp_dirs = [ans_image_dir, upload_dir]
|
390 |
for directory in temp_dirs:
|
391 |
if os.path.exists(directory):
|
392 |
shutil.rmtree(directory)
|
|
|
397 |
|
398 |
if __name__ == '__main__':
|
399 |
try:
|
|
|
400 |
port = int(os.environ.get('PORT', 7860))
|
401 |
+
app.run(host='0.0.0.0', port=port, debug=False)
|
|
|
402 |
finally:
|
403 |
cleanup_temp_files()
|
requirements.txt
CHANGED
@@ -5,6 +5,7 @@ transformers==4.40.1
|
|
5 |
sentence-transformers==2.7.0
|
6 |
opencv-python-headless==4.9.0.80
|
7 |
flask-cors==3.0.10
|
|
|
8 |
|
9 |
# Specific versions for scipy/numpy/gensim compatibility
|
10 |
numpy==1.24.4
|
|
|
5 |
sentence-transformers==2.7.0
|
6 |
opencv-python-headless==4.9.0.80
|
7 |
flask-cors==3.0.10
|
8 |
+
gunicorn==20.1.0
|
9 |
|
10 |
# Specific versions for scipy/numpy/gensim compatibility
|
11 |
numpy==1.24.4
|
templates/index.html
CHANGED
@@ -350,7 +350,6 @@
|
|
350 |
|
351 |
.upload-section.active {
|
352 |
display: block;
|
353 |
-
animation: fadeIn 0.3s ease-out;
|
354 |
}
|
355 |
|
356 |
@keyframes fadeIn {
|
@@ -904,8 +903,8 @@
|
|
904 |
}
|
905 |
|
906 |
// Validate that answers are not empty
|
907 |
-
const
|
908 |
-
if (
|
909 |
alert("Please ensure all answer boxes are filled!");
|
910 |
return;
|
911 |
}
|
|
|
350 |
|
351 |
.upload-section.active {
|
352 |
display: block;
|
|
|
353 |
}
|
354 |
|
355 |
@keyframes fadeIn {
|
|
|
903 |
}
|
904 |
|
905 |
// Validate that answers are not empty
|
906 |
+
const answerValues = Array.from(answerBoxes).map(box => box.value.trim());
|
907 |
+
if (answerValues.some(answer => !answer)) {
|
908 |
alert("Please ensure all answer boxes are filled!");
|
909 |
return;
|
910 |
}
|