update folder creation
Browse files
app.py
CHANGED
|
@@ -9,19 +9,24 @@ from flask import send_file
|
|
| 9 |
|
| 10 |
logger = logging.getLogger(__name__)
|
| 11 |
logging.basicConfig(level=logging.INFO)
|
|
|
|
|
|
|
|
|
|
|
|
|
| 12 |
app = Flask(__name__)
|
| 13 |
app.config['SEND_FILE_MAX_AGE_DEFAULT'] = 0
|
| 14 |
app.config["SECRET_KEY"] = '#thaistartsfirst!'
|
| 15 |
-
app.config["IMAGES"] =
|
| 16 |
-
app.config["OUT"] =
|
| 17 |
app.config["LABELS"] = []
|
| 18 |
app.config["HEAD"] = 0
|
| 19 |
app.config["SESSION_PERMANENT"] = False
|
| 20 |
-
|
| 21 |
-
#
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
|
|
|
| 25 |
|
| 26 |
|
| 27 |
@app.route('/', methods=['GET', 'POST'])
|
|
@@ -31,19 +36,19 @@ def index():
|
|
| 31 |
user_id = uuid.uuid4()
|
| 32 |
session['_id'] = user_id
|
| 33 |
logger.info(user_id)
|
| 34 |
-
|
|
|
|
| 35 |
f.write("image,id,name,xMin,xMax,yMin,yMax\n")
|
| 36 |
|
| 37 |
if request.method == 'POST':
|
| 38 |
if 'file' not in request.files:
|
| 39 |
flash('No files selected')
|
| 40 |
return redirect('/')
|
| 41 |
-
img_folder = f'{
|
| 42 |
try:
|
| 43 |
-
os.
|
| 44 |
-
except:
|
| 45 |
logger.info('user already has an active session')
|
| 46 |
-
logger.info(user_id)
|
| 47 |
files = request.files.getlist("file")
|
| 48 |
filenames = []
|
| 49 |
for f in files:
|
|
|
|
| 9 |
|
| 10 |
logger = logging.getLogger(__name__)
|
| 11 |
logging.basicConfig(level=logging.INFO)
|
| 12 |
+
|
| 13 |
+
UPLOAD_FOLDER = '/app/images'
|
| 14 |
+
OUT_FOLDER = '/app/anno'
|
| 15 |
+
|
| 16 |
app = Flask(__name__)
|
| 17 |
app.config['SEND_FILE_MAX_AGE_DEFAULT'] = 0
|
| 18 |
app.config["SECRET_KEY"] = '#thaistartsfirst!'
|
| 19 |
+
app.config["IMAGES"] = UPLOAD_FOLDER
|
| 20 |
+
app.config["OUT"] = OUT_FOLDER
|
| 21 |
app.config["LABELS"] = []
|
| 22 |
app.config["HEAD"] = 0
|
| 23 |
app.config["SESSION_PERMANENT"] = False
|
| 24 |
+
|
| 25 |
+
# Ensure the upload directory exists
|
| 26 |
+
if not os.path.exists(UPLOAD_FOLDER):
|
| 27 |
+
os.makedirs(UPLOAD_FOLDER)
|
| 28 |
+
if not os.path.exists(OUT_FOLDER):
|
| 29 |
+
os.makedirs(OUT_FOLDER)
|
| 30 |
|
| 31 |
|
| 32 |
@app.route('/', methods=['GET', 'POST'])
|
|
|
|
| 36 |
user_id = uuid.uuid4()
|
| 37 |
session['_id'] = user_id
|
| 38 |
logger.info(user_id)
|
| 39 |
+
file_path = os.path.join(OUT_FOLDER, f'{user_id}.csv')
|
| 40 |
+
with open(file_path, 'w') as f:
|
| 41 |
f.write("image,id,name,xMin,xMax,yMin,yMax\n")
|
| 42 |
|
| 43 |
if request.method == 'POST':
|
| 44 |
if 'file' not in request.files:
|
| 45 |
flash('No files selected')
|
| 46 |
return redirect('/')
|
| 47 |
+
img_folder = os.path.join(UPLOAD_FOLDER, f'{user_id}')
|
| 48 |
try:
|
| 49 |
+
os.makedirs(img_folder)
|
| 50 |
+
except FileExistsError:
|
| 51 |
logger.info('user already has an active session')
|
|
|
|
| 52 |
files = request.files.getlist("file")
|
| 53 |
filenames = []
|
| 54 |
for f in files:
|