WebashalarForML commited on
Commit
8b83b0a
·
verified ·
1 Parent(s): 35c08cc

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +19 -5
app.py CHANGED
@@ -19,6 +19,7 @@ app.config['UPLOAD_FOLDER'] = 'uploads/'
19
  app.config['JSON_FOLDER'] = 'JSON/'
20
  app.config['DATA_FOLDER'] = 'data/'
21
  app.config['MODELS_FOLDER'] = 'Models/'
 
22
 
23
  # Creating Folders if not exists
24
  os.makedirs(app.config['UPLOAD_FOLDER'], exist_ok=True)
@@ -375,11 +376,24 @@ def download_latest_model():
375
  return redirect(request.referrer)
376
 
377
  # Route to serve uploaded files
378
- '''
379
- @app.route('/uploads/<filename>')
380
- def uploaded_file(filename):
381
- return send_from_directory(app.config['UPLOAD_FOLDER'], filename)
382
- '''
 
 
 
 
 
 
 
 
 
 
 
 
 
383
 
384
  if __name__ == '__main__':
385
  app.run(debug=True)
 
19
  app.config['JSON_FOLDER'] = 'JSON/'
20
  app.config['DATA_FOLDER'] = 'data/'
21
  app.config['MODELS_FOLDER'] = 'Models/'
22
+ app.config['MAIN_FOLDER'] = os.getcwd()
23
 
24
  # Creating Folders if not exists
25
  os.makedirs(app.config['UPLOAD_FOLDER'], exist_ok=True)
 
376
  return redirect(request.referrer)
377
 
378
  # Route to serve uploaded files
379
+ @app.route('/<foldername>/zip', methods=['GET'])
380
+ def zip_folder(foldername):
381
+ # Construct the folder path
382
+ folder_path = os.path.join(app.config['MAIN_FOLDER'], foldername)
383
+
384
+ # Check if the folder exists
385
+ if not os.path.exists(folder_path) or not os.path.isdir(folder_path):
386
+ abort(404, description="Folder not found")
387
+
388
+ # Define the zip file name and path
389
+ zip_filename = f"{foldername}.zip"
390
+ zip_path = os.path.join(app.config['MAIN_FOLDER'], zip_filename)
391
+
392
+ # Create a zip file of the folder
393
+ shutil.make_archive(zip_path[:-4], 'zip', folder_path)
394
+
395
+ # Send the zipped file to the client
396
+ return send_from_directory(app.config['MAIN_FOLDER'], zip_filename, as_attachment=True)
397
 
398
  if __name__ == '__main__':
399
  app.run(debug=True)